ENH: When source file is in subdirectory put object file in subdirectory. Fixes Bug #290 - Source files in subdirectories should produce object files in subdirectories
This commit is contained in:
parent
62fec96d99
commit
d6090a2395
|
@ -580,7 +580,9 @@ IF(BUILD_TESTING)
|
||||||
--build-generator ${CMAKE_GENERATOR}
|
--build-generator ${CMAKE_GENERATOR}
|
||||||
--build-makeprogram ${MAKEPROGRAM}
|
--build-makeprogram ${MAKEPROGRAM}
|
||||||
--build-project SUBDIR
|
--build-project SUBDIR
|
||||||
--test-command test "${CMake_BINARY_DIR}/Tests/SubDir/ShouldBeHere"
|
--test-command test
|
||||||
|
"${CMake_BINARY_DIR}/Tests/SubDir/ShouldBeHere"
|
||||||
|
"${CMake_BINARY_DIR}/Tests/SubDir/testfromsubdir.o"
|
||||||
)
|
)
|
||||||
|
|
||||||
IF (APPLE)
|
IF (APPLE)
|
||||||
|
|
|
@ -27,9 +27,16 @@ void cmSourceFile::SetName(const char* name, const char* dir,
|
||||||
const std::vector<std::string>& sourceExts,
|
const std::vector<std::string>& sourceExts,
|
||||||
const std::vector<std::string>& headerExts)
|
const std::vector<std::string>& headerExts)
|
||||||
{
|
{
|
||||||
|
|
||||||
this->SetProperty("HEADER_FILE_ONLY","1");
|
this->SetProperty("HEADER_FILE_ONLY","1");
|
||||||
|
|
||||||
m_SourceName = name;
|
m_SourceName = cmSystemTools::GetFilenamePath(name);
|
||||||
|
if ( m_SourceName.size() > 0 )
|
||||||
|
{
|
||||||
|
m_SourceName += "/";
|
||||||
|
}
|
||||||
|
m_SourceName += cmSystemTools::GetFilenameWithoutLastExtension(name);
|
||||||
|
|
||||||
std::string pathname = dir;
|
std::string pathname = dir;
|
||||||
|
|
||||||
// the name might include the full path already, so
|
// the name might include the full path already, so
|
||||||
|
@ -47,7 +54,7 @@ void cmSourceFile::SetName(const char* name, const char* dir,
|
||||||
|
|
||||||
// First try and see whether the listed file can be found
|
// First try and see whether the listed file can be found
|
||||||
// as is without extensions added on.
|
// as is without extensions added on.
|
||||||
pathname += m_SourceName;
|
pathname += name;
|
||||||
std::string hname = pathname;
|
std::string hname = pathname;
|
||||||
if(cmSystemTools::FileExists(hname.c_str()))
|
if(cmSystemTools::FileExists(hname.c_str()))
|
||||||
{
|
{
|
||||||
|
@ -55,14 +62,13 @@ void cmSourceFile::SetName(const char* name, const char* dir,
|
||||||
if(pos != std::string::npos)
|
if(pos != std::string::npos)
|
||||||
{
|
{
|
||||||
m_SourceExtension = hname.substr(pos+1, hname.size()-pos);
|
m_SourceExtension = hname.substr(pos+1, hname.size()-pos);
|
||||||
|
if ( cmSystemTools::FileIsFullPath(name) )
|
||||||
|
{
|
||||||
std::string::size_type pos2 = hname.rfind('/');
|
std::string::size_type pos2 = hname.rfind('/');
|
||||||
if(pos2 != std::string::npos)
|
if(pos2 != std::string::npos)
|
||||||
{
|
{
|
||||||
m_SourceName = hname.substr(pos2+1, pos - pos2-1);
|
m_SourceName = hname.substr(pos2+1, pos - pos2-1);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
m_SourceName = hname.substr(0, pos);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
PROJECT(SUBDIR)
|
PROJECT(SUBDIR)
|
||||||
SUBDIRS(Executable EXCLUDE_FROM_ALL Examples)
|
SUBDIRS(Executable EXCLUDE_FROM_ALL Examples)
|
||||||
WRITE_FILE(${SUBDIR_BINARY_DIR}/ShouldBeHere "This file should exist.")
|
WRITE_FILE(${SUBDIR_BINARY_DIR}/ShouldBeHere "This file should exist.")
|
||||||
|
|
||||||
|
ADD_EXECUTABLE(TestFromSubdir AnotherSubdir/testfromsubdir.c AnotherSubdir/secondone)
|
||||||
|
|
|
@ -28,11 +28,22 @@ int FileExists(const char* filename)
|
||||||
|
|
||||||
int main(int ac, char** av)
|
int main(int ac, char** av)
|
||||||
{
|
{
|
||||||
|
if(ac <= 1)
|
||||||
|
{
|
||||||
|
printf("Usage: %s <file>\n", av[0]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
if(!FileExists(av[1]))
|
if(!FileExists(av[1]))
|
||||||
{
|
{
|
||||||
printf("Missing file %s\n", av[1]);
|
printf("Missing file %s\n", av[1]);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
printf("%s is there!", av[1]);
|
if(FileExists(av[2]))
|
||||||
|
{
|
||||||
|
printf("File %s should be in subdirectory\n", av[2]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
printf("%s is not there! Good.", av[2]);
|
||||||
|
printf("%s is there! Good.", av[1]);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue