diff options
-rw-r--r-- | Source/cmLocalUnixMakefileGenerator2.cxx | 84 | ||||
-rw-r--r-- | Source/cmLocalUnixMakefileGenerator2.h | 2 | ||||
-rw-r--r-- | Tests/MakeClean/CMakeLists.txt | 1 | ||||
-rw-r--r-- | Tests/MakeClean/ToClean/CMakeLists.txt | 23 | ||||
-rw-r--r-- | Tests/Wrapping/CMakeLists.txt | 4 |
5 files changed, 79 insertions, 35 deletions
diff --git a/Source/cmLocalUnixMakefileGenerator2.cxx b/Source/cmLocalUnixMakefileGenerator2.cxx index fda2e0a..1c7e973 100644 --- a/Source/cmLocalUnixMakefileGenerator2.cxx +++ b/Source/cmLocalUnixMakefileGenerator2.cxx @@ -46,10 +46,6 @@ // TODO: Add "help" target. // TODO: Identify remaining relative path violations. // TODO: Need test for separate executable/library output path. -// TODO: Add registered files for cleaning: -// $(GENERATED_QT_FILES) $(GENERATED_FLTK_FILES) -// What about cleaning custom command outputs? - //---------------------------------------------------------------------------- cmLocalUnixMakefileGenerator2::cmLocalUnixMakefileGenerator2() @@ -706,6 +702,35 @@ cmLocalUnixMakefileGenerator2 preEcho += "..."; this->WriteMakeRule(ruleFileStream, comment, preEcho.c_str(), cc.GetOutput().c_str(), depends, commands); + + // Write the clean rule for this custom command. + std::string cleanTarget = customName; + cleanTarget += ".clean"; + commands.clear(); + depends.clear(); + std::vector<std::string> cleanFiles; + cleanFiles.push_back(cc.GetOutput().c_str()); + this->AppendCleanCommand(commands, cleanFiles); + this->WriteMakeRule(ruleFileStream, + "Clean the output of this custom command.", 0, + cleanTarget.c_str(), depends, commands); + + // Check whether to attach the clean rule. + bool attach = true; + if(const char* clean_no_custom = + m_Makefile->GetProperty("CLEAN_NO_CUSTOM")) + { + if(!cmSystemTools::IsOff(clean_no_custom)) + { + attach = false; + } + } + + // Attach the clean rule to the directory-level clean rule. + if(attach) + { + this->WriteLocalRule(ruleFileStream, "clean", cleanTarget.c_str()); + } } //---------------------------------------------------------------------------- @@ -1797,23 +1822,17 @@ cmLocalUnixMakefileGenerator2 // Add a command to remove any existing files for this library. std::vector<std::string> cleanFiles; - std::string remove = "$(CMAKE_COMMAND) -E remove -f "; - remove += targetOutPathReal; - cleanFiles.push_back(targetOutPathReal); + cleanFiles.push_back(targetFullPathReal); if(targetOutPathSO != targetOutPathReal) { - remove += " "; - remove += targetOutPathSO; - cleanFiles.push_back(targetOutPathSO); + cleanFiles.push_back(targetFullPathSO); } if(targetOutPath != targetOutPathSO && targetOutPath != targetOutPathReal) { - remove += " "; - remove += targetOutPath; - cleanFiles.push_back(targetOutPath); + cleanFiles.push_back(targetFullPath); } - commands.push_back(remove); + this->AppendCleanCommand(commands, cleanFiles); // TODO: Pre-build and pre-link rules. @@ -2008,14 +2027,7 @@ cmLocalUnixMakefileGenerator2 cleanTarget += ".clean"; // Construct the clean command. - std::string remove = "$(CMAKE_COMMAND) -E remove -f"; - for(std::vector<std::string>::const_iterator f = files.begin(); - f != files.end(); ++f) - { - remove += " "; - remove += *f; - } - commands.push_back(remove); + this->AppendCleanCommand(commands, files); // Write the rule. this->WriteMakeRule(ruleFileStream, 0, 0, cleanTarget.c_str(), @@ -2110,16 +2122,9 @@ cmLocalUnixMakefileGenerator2 else { // Have extra files to clean. Write the action to remove them. - std::string remove = "$(CMAKE_COMMAND) -E remove -f"; - for(std::vector<std::string>::iterator i = files.begin(); - i != files.end(); ++i) - { - remove += " "; - remove += this->ConvertToRelativeOutputPath(i->c_str()); - } std::vector<std::string> no_depends; std::vector<std::string> commands; - commands.push_back(remove); + this->AppendCleanCommand(commands, files); this->WriteMakeRule(makefileStream, "Clean extra files in this directory.", 0, "clean.local", no_depends, commands); @@ -2720,6 +2725,25 @@ cmLocalUnixMakefileGenerator2 } //---------------------------------------------------------------------------- +void +cmLocalUnixMakefileGenerator2 +::AppendCleanCommand(std::vector<std::string>& commands, + const std::vector<std::string>& files) +{ + if(!files.empty()) + { + std::string remove = "$(CMAKE_COMMAND) -E remove -f"; + for(std::vector<std::string>::const_iterator f = files.begin(); + f != files.end(); ++f) + { + remove += " "; + remove += this->ConvertToRelativeOutputPath(f->c_str()); + } + commands.push_back(remove); + } +} + +//---------------------------------------------------------------------------- std::string cmLocalUnixMakefileGenerator2 ::GetRecursiveMakeCall(const char* tgt) diff --git a/Source/cmLocalUnixMakefileGenerator2.h b/Source/cmLocalUnixMakefileGenerator2.h index 7cf9a16..0da8998 100644 --- a/Source/cmLocalUnixMakefileGenerator2.h +++ b/Source/cmLocalUnixMakefileGenerator2.h @@ -180,6 +180,8 @@ protected: const std::vector<cmCustomCommand>& ccs); void AppendCustomCommand(std::vector<std::string>& commands, const cmCustomCommand& cc); + void AppendCleanCommand(std::vector<std::string>& commands, + const std::vector<std::string>& files); std::string GetRecursiveMakeCall(const char* tgt); void WriteJumpAndBuildRules(std::ostream& makefileStream); diff --git a/Tests/MakeClean/CMakeLists.txt b/Tests/MakeClean/CMakeLists.txt index a1a292c..6852a6e 100644 --- a/Tests/MakeClean/CMakeLists.txt +++ b/Tests/MakeClean/CMakeLists.txt @@ -5,7 +5,6 @@ TRY_COMPILE(TOCLEAN_BUILT ${MakeClean_BINARY_DIR}/ToClean ${MakeClean_SOURCE_DIR}/ToClean ToClean - toclean OUTPUT_VARIABLE OUTPUT ) IF(TOCLEAN_BUILT) diff --git a/Tests/MakeClean/ToClean/CMakeLists.txt b/Tests/MakeClean/ToClean/CMakeLists.txt index 49507f4..673bbc4 100644 --- a/Tests/MakeClean/ToClean/CMakeLists.txt +++ b/Tests/MakeClean/ToClean/CMakeLists.txt @@ -5,10 +5,13 @@ ADD_EXECUTABLE(toclean toclean.cxx) # List some build-time-generated files. GET_TARGET_PROPERTY(TOCLEAN_FILES toclean LOCATION) -SET(TOCLEAN_FILES ${TOCLEAN_FILES} - "${ToClean_BINARY_DIR}/toclean${CMAKE_CXX_OUTPUT_EXTENSION}") -#SET(TOCLEAN_FILES ${TOCLEAN_FILES} -# "${ToClean_BINARY_DIR}/toclean.dir/toclean${CMAKE_CXX_OUTPUT_EXTENSION}") +IF(CMAKE_GENERATOR_NEW) + SET(TOCLEAN_FILES ${TOCLEAN_FILES} + "${ToClean_BINARY_DIR}/toclean.dir/toclean${CMAKE_CXX_OUTPUT_EXTENSION}") +ELSE(CMAKE_GENERATOR_NEW) + SET(TOCLEAN_FILES ${TOCLEAN_FILES} + "${ToClean_BINARY_DIR}/toclean${CMAKE_CXX_OUTPUT_EXTENSION}") +ENDIF(CMAKE_GENERATOR_NEW) # Create a file that must be registered for cleaning. FILE(WRITE "${ToClean_BINARY_DIR}/Registered.txt" @@ -17,6 +20,18 @@ SET_DIRECTORY_PROPERTIES(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${ToClean_BINARY_DIR}/Registered.txt") SET(TOCLEAN_FILES ${TOCLEAN_FILES} "${ToClean_BINARY_DIR}/Registered.txt") +# Create a custom command whose output should be cleaned. +IF(CMAKE_GENERATOR_NEW) + ADD_CUSTOM_COMMAND(OUTPUT ${ToClean_BINARY_DIR}/generated.txt + DEPENDS ${ToClean_SOURCE_DIR}/toclean.cxx + COMMAND ${CMAKE_COMMAND} + ARGS -E copy ${ToClean_SOURCE_DIR}/toclean.cxx + ${ToClean_BINARY_DIR}/generated.txt + ) + ADD_CUSTOM_TARGET(generate ALL DEPENDS ${ToClean_BINARY_DIR}/generated.txt) + SET(TOCLEAN_FILES ${TOCLEAN_FILES} "${ToClean_BINARY_DIR}/generated.txt") +ENDIF(CMAKE_GENERATOR_NEW) + # Configure a file listing these build-time-generated files. CONFIGURE_FILE(${ToClean_SOURCE_DIR}/ToCleanFiles.cmake.in ${ToClean_BINARY_DIR}/ToCleanFiles.cmake @ONLY IMMEDIATE) diff --git a/Tests/Wrapping/CMakeLists.txt b/Tests/Wrapping/CMakeLists.txt index 8aeec0d..cbf23c0 100644 --- a/Tests/Wrapping/CMakeLists.txt +++ b/Tests/Wrapping/CMakeLists.txt @@ -3,6 +3,10 @@ # PROJECT (Wrapping) +# Disable cleaning of custom command outputs to preserve the hacks +# used to generate the files using CONFIGURE_FILE. +SET_DIRECTORY_PROPERTIES(PROPERTIES CLEAN_NO_CUSTOM 1) + # # Lib and exe path # |