diff options
author | Andy Cedilnik <andy.cedilnik@kitware.com> | 2004-04-26 21:32:56 (GMT) |
---|---|---|
committer | Andy Cedilnik <andy.cedilnik@kitware.com> | 2004-04-26 21:32:56 (GMT) |
commit | d6090a2395a2e8e0c506e62a95e0e9dd197c6572 (patch) | |
tree | 3030c69e7dcc93a84fe308a73db6b45044661d4b | |
parent | 62fec96d993975775410ebc2dceaa65b03a12ae2 (diff) | |
download | CMake-d6090a2395a2e8e0c506e62a95e0e9dd197c6572.zip CMake-d6090a2395a2e8e0c506e62a95e0e9dd197c6572.tar.gz CMake-d6090a2395a2e8e0c506e62a95e0e9dd197c6572.tar.bz2 |
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
-rw-r--r-- | Source/CMakeLists.txt | 4 | ||||
-rw-r--r-- | Source/cmSourceFile.cxx | 22 | ||||
-rw-r--r-- | Tests/SubDir/CMakeLists.txt | 2 | ||||
-rw-r--r-- | Tests/SubDir/Executable/test.cxx | 13 |
4 files changed, 31 insertions, 10 deletions
diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt index 13b2416..d38c37f 100644 --- a/Source/CMakeLists.txt +++ b/Source/CMakeLists.txt @@ -580,7 +580,9 @@ IF(BUILD_TESTING) --build-generator ${CMAKE_GENERATOR} --build-makeprogram ${MAKEPROGRAM} --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) diff --git a/Source/cmSourceFile.cxx b/Source/cmSourceFile.cxx index 138d5d2..b8a547a 100644 --- a/Source/cmSourceFile.cxx +++ b/Source/cmSourceFile.cxx @@ -27,9 +27,16 @@ void cmSourceFile::SetName(const char* name, const char* dir, const std::vector<std::string>& sourceExts, const std::vector<std::string>& headerExts) { + 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; // 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 // as is without extensions added on. - pathname += m_SourceName; + pathname += name; std::string hname = pathname; if(cmSystemTools::FileExists(hname.c_str())) { @@ -55,14 +62,13 @@ void cmSourceFile::SetName(const char* name, const char* dir, if(pos != std::string::npos) { m_SourceExtension = hname.substr(pos+1, hname.size()-pos); - std::string::size_type pos2 = hname.rfind('/'); - if(pos2 != std::string::npos) + if ( cmSystemTools::FileIsFullPath(name) ) { + std::string::size_type pos2 = hname.rfind('/'); + if(pos2 != std::string::npos) + { m_SourceName = hname.substr(pos2+1, pos - pos2-1); - } - else - { - m_SourceName = hname.substr(0, pos); + } } } diff --git a/Tests/SubDir/CMakeLists.txt b/Tests/SubDir/CMakeLists.txt index b70b312..a1da9b6 100644 --- a/Tests/SubDir/CMakeLists.txt +++ b/Tests/SubDir/CMakeLists.txt @@ -1,3 +1,5 @@ PROJECT(SUBDIR) SUBDIRS(Executable EXCLUDE_FROM_ALL Examples) WRITE_FILE(${SUBDIR_BINARY_DIR}/ShouldBeHere "This file should exist.") + +ADD_EXECUTABLE(TestFromSubdir AnotherSubdir/testfromsubdir.c AnotherSubdir/secondone) diff --git a/Tests/SubDir/Executable/test.cxx b/Tests/SubDir/Executable/test.cxx index f351521..c528fb1 100644 --- a/Tests/SubDir/Executable/test.cxx +++ b/Tests/SubDir/Executable/test.cxx @@ -28,11 +28,22 @@ int FileExists(const char* filename) int main(int ac, char** av) { + if(ac <= 1) + { + printf("Usage: %s <file>\n", av[0]); + return 1; + } if(!FileExists(av[1])) { printf("Missing file %s\n", av[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; } |