From 0d41b45cc931530d5dbc51674699f4da2290a6d3 Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Fri, 17 May 2019 10:56:50 +0200 Subject: Makefiles: Inline range loop range arguments --- Source/cmGlobalUnixMakefileGenerator3.cxx | 44 ++++++++++--------------------- Source/cmLocalUnixMakefileGenerator3.cxx | 9 +++---- 2 files changed, 17 insertions(+), 36 deletions(-) diff --git a/Source/cmGlobalUnixMakefileGenerator3.cxx b/Source/cmGlobalUnixMakefileGenerator3.cxx index 1ea3673..5486ac0 100644 --- a/Source/cmGlobalUnixMakefileGenerator3.cxx +++ b/Source/cmGlobalUnixMakefileGenerator3.cxx @@ -354,9 +354,7 @@ void cmGlobalUnixMakefileGenerator3::WriteMainCMakefile() { cmakefileStream << "# Byproducts of CMake generate step:\n" << "set(CMAKE_MAKEFILE_PRODUCTS\n"; - const std::vector& outfiles = - lg->GetMakefile()->GetOutputFiles(); - for (std::string const& outfile : outfiles) { + for (std::string const& outfile : lg->GetMakefile()->GetOutputFiles()) { cmakefileStream << " \"" << lg->MaybeConvertToRelativePath(binDir, outfile) << "\"\n"; @@ -392,8 +390,7 @@ void cmGlobalUnixMakefileGenerator3::WriteMainCMakefileLanguageRules( for (cmLocalGenerator* lGenerator : lGenerators) { lg = static_cast(lGenerator); // for all of out targets - const std::vector& tgts = lg->GetGeneratorTargets(); - for (cmGeneratorTarget* tgt : tgts) { + for (cmGeneratorTarget* tgt : lg->GetGeneratorTargets()) { if ((tgt->GetType() == cmStateEnums::EXECUTABLE) || (tgt->GetType() == cmStateEnums::STATIC_LIBRARY) || (tgt->GetType() == cmStateEnums::SHARED_LIBRARY) || @@ -423,8 +420,7 @@ void cmGlobalUnixMakefileGenerator3::WriteDirectoryRule2( // The directory-level rule should depend on the target-level rules // for all targets in the directory. std::vector depends; - const std::vector& targets = lg->GetGeneratorTargets(); - for (cmGeneratorTarget* gtarget : targets) { + for (cmGeneratorTarget* gtarget : lg->GetGeneratorTargets()) { int type = gtarget->GetType(); if ((type == cmStateEnums::EXECUTABLE) || (type == cmStateEnums::STATIC_LIBRARY) || @@ -446,8 +442,7 @@ void cmGlobalUnixMakefileGenerator3::WriteDirectoryRule2( // The directory-level rule should depend on the directory-level // rules of the subdirectories. - std::vector children = lg->GetStateSnapshot().GetChildren(); - for (cmStateSnapshot const& c : children) { + for (cmStateSnapshot const& c : lg->GetStateSnapshot().GetChildren()) { std::string subdir = c.GetDirectory().GetCurrentBinary(); subdir += "/"; subdir += pass; @@ -567,8 +562,7 @@ void cmGlobalUnixMakefileGenerator3::WriteConvenienceRules( cmLocalUnixMakefileGenerator3* lg = static_cast(localGen); // for each target Generate the rule files for each target. - const std::vector& targets = lg->GetGeneratorTargets(); - for (cmGeneratorTarget* gtarget : targets) { + for (cmGeneratorTarget* gtarget : lg->GetGeneratorTargets()) { // Don't emit the same rule twice (e.g. two targets with the same // simple name) int type = gtarget->GetType(); @@ -652,8 +646,7 @@ void cmGlobalUnixMakefileGenerator3::WriteConvenienceRules2( } // for each target Generate the rule files for each target. - const std::vector& targets = lg->GetGeneratorTargets(); - for (cmGeneratorTarget* gtarget : targets) { + for (cmGeneratorTarget* gtarget : lg->GetGeneratorTargets()) { int type = gtarget->GetType(); std::string name = gtarget->GetName(); if (!name.empty() && @@ -693,9 +686,7 @@ void cmGlobalUnixMakefileGenerator3::WriteConvenienceRules2( { std::ostringstream progressArg; const char* sep = ""; - std::vector const& progFiles = - this->ProgressMap[gtarget].Marks; - for (unsigned long progFile : progFiles) { + for (unsigned long progFile : this->ProgressMap[gtarget].Marks) { progressArg << sep << progFile; sep = ","; } @@ -817,8 +808,7 @@ void cmGlobalUnixMakefileGenerator3::InitializeProgressMarks() this->DirectoryTargetsMap.clear(); // Loop over all targets in all local generators. for (cmLocalGenerator* lg : this->LocalGenerators) { - const std::vector& targets = lg->GetGeneratorTargets(); - for (cmGeneratorTarget* gt : targets) { + for (cmGeneratorTarget* gt : lg->GetGeneratorTargets()) { cmLocalGenerator* tlg = gt->GetLocalGenerator(); if (gt->GetType() == cmStateEnums::INTERFACE_LIBRARY || @@ -841,8 +831,7 @@ void cmGlobalUnixMakefileGenerator3::InitializeProgressMarks() // Add dependencies of the included target. An excluded // target may still be included if it is a dependency of a // non-excluded target. - TargetDependSet const& tgtdeps = this->GetTargetDirectDepends(gt); - for (cmTargetDepend const& tgtdep : tgtdeps) { + for (cmTargetDepend const& tgtdep : this->GetTargetDirectDepends(gt)) { targetSet.insert(tgtdep); } } @@ -856,8 +845,7 @@ size_t cmGlobalUnixMakefileGenerator3::CountProgressMarksInTarget( size_t count = 0; if (emitted.insert(target).second) { count = this->ProgressMap[target].Marks.size(); - TargetDependSet const& depends = this->GetTargetDirectDepends(target); - for (cmTargetDepend const& depend : depends) { + for (cmTargetDepend const& depend : this->GetTargetDirectDepends(target)) { if (depend->GetType() == cmStateEnums::INTERFACE_LIBRARY) { continue; } @@ -872,9 +860,8 @@ size_t cmGlobalUnixMakefileGenerator3::CountProgressMarksInAll( { size_t count = 0; std::set emitted; - std::set const& targets = - this->DirectoryTargetsMap[lg->GetStateSnapshot()]; - for (cmGeneratorTarget const* target : targets) { + for (cmGeneratorTarget const* target : + this->DirectoryTargetsMap[lg->GetStateSnapshot()]) { count += this->CountProgressMarksInTarget(target, emitted); } return count; @@ -913,8 +900,7 @@ void cmGlobalUnixMakefileGenerator3::TargetProgress::WriteProgressVariables( void cmGlobalUnixMakefileGenerator3::AppendGlobalTargetDepends( std::vector& depends, cmGeneratorTarget* target) { - TargetDependSet const& depends_set = this->GetTargetDirectDepends(target); - for (cmTargetDepend const& i : depends_set) { + for (cmTargetDepend const& i : this->GetTargetDirectDepends(target)) { // Create the target-level dependency. cmGeneratorTarget const* dep = i; if (dep->GetType() == cmStateEnums::INTERFACE_LIBRARY) { @@ -956,9 +942,7 @@ void cmGlobalUnixMakefileGenerator3::WriteHelpRule( // the targets if (lg2 == lg || lg->IsRootMakefile()) { // for each target Generate the rule files for each target. - const std::vector& targets = - lg2->GetGeneratorTargets(); - for (cmGeneratorTarget* target : targets) { + for (cmGeneratorTarget* target : lg2->GetGeneratorTargets()) { cmStateEnums::TargetType type = target->GetType(); if ((type == cmStateEnums::EXECUTABLE) || (type == cmStateEnums::STATIC_LIBRARY) || diff --git a/Source/cmLocalUnixMakefileGenerator3.cxx b/Source/cmLocalUnixMakefileGenerator3.cxx index 88966c8..857440c 100644 --- a/Source/cmLocalUnixMakefileGenerator3.cxx +++ b/Source/cmLocalUnixMakefileGenerator3.cxx @@ -115,10 +115,9 @@ void cmLocalUnixMakefileGenerator3::Generate() this->Makefile->IsOn("CMAKE_SKIP_ASSEMBLY_SOURCE_RULES"); // Generate the rule files for each target. - const std::vector& targets = this->GetGeneratorTargets(); cmGlobalUnixMakefileGenerator3* gg = static_cast(this->GlobalGenerator); - for (cmGeneratorTarget* target : targets) { + for (cmGeneratorTarget* target : this->GetGeneratorTargets()) { if (target->GetType() == cmStateEnums::INTERFACE_LIBRARY) { continue; } @@ -154,8 +153,7 @@ void cmLocalUnixMakefileGenerator3::ComputeHomeRelativeOutputPath() void cmLocalUnixMakefileGenerator3::GetLocalObjectFiles( std::map& localObjectFiles) { - const std::vector& targets = this->GetGeneratorTargets(); - for (cmGeneratorTarget* gt : targets) { + for (cmGeneratorTarget* gt : this->GetGeneratorTargets()) { if (gt->GetType() == cmStateEnums::INTERFACE_LIBRARY) { continue; } @@ -353,9 +351,8 @@ void cmLocalUnixMakefileGenerator3::WriteLocalMakefileTargets( // for each target we just provide a rule to cd up to the top and do a make // on the target - const std::vector& targets = this->GetGeneratorTargets(); std::string localName; - for (cmGeneratorTarget* target : targets) { + for (cmGeneratorTarget* target : this->GetGeneratorTargets()) { if ((target->GetType() == cmStateEnums::EXECUTABLE) || (target->GetType() == cmStateEnums::STATIC_LIBRARY) || (target->GetType() == cmStateEnums::SHARED_LIBRARY) || -- cgit v0.12 From adc3459707c4c942b547eb57d02a82b8d5085962 Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Fri, 17 May 2019 12:30:08 +0200 Subject: Makefiles: Avoid pointer repurposing --- Source/cmGlobalUnixMakefileGenerator3.cxx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Source/cmGlobalUnixMakefileGenerator3.cxx b/Source/cmGlobalUnixMakefileGenerator3.cxx index 5486ac0..2f3bc76 100644 --- a/Source/cmGlobalUnixMakefileGenerator3.cxx +++ b/Source/cmGlobalUnixMakefileGenerator3.cxx @@ -247,13 +247,13 @@ void cmGlobalUnixMakefileGenerator3::WriteMainMakefile2() // Write out the "special" stuff lg->WriteSpecialTargetsTop(makefileStream); - // write the target convenience rules + // Write the target convenience rules for (cmLocalGenerator* localGen : this->LocalGenerators) { - lg = static_cast(localGen); - this->WriteConvenienceRules2(makefileStream, lg); + this->WriteConvenienceRules2( + makefileStream, static_cast(localGen)); } - lg = static_cast(this->LocalGenerators[0]); + // Write special bottom targets lg->WriteSpecialTargetsBottom(makefileStream); } -- cgit v0.12 From 827da1119ef2d0978dd6dbc58aeee803e43b2455 Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Fri, 17 May 2019 17:02:53 +0200 Subject: Makefiles: Make build root targets "all", "clean" and "preinstall" recursive In the "Unix Makefiles" generator, the subdirectory targets "all", "clean" and "preinstall" in Makefile2 are recursive. In the build root directory, these targets aren't. Instead they're are added separately and additional dependencies are added on a per target basis. This is inconsistent and it complicates per directory commands, like a per directory clean command. This patch makes the "all", "clean" and "preinstall" targets in Makefile2 in the build root directory recursive, using the same algorithm that is already used for subdirectories. Some side effects are: - Makefile2 gets smaller and simpler - The main "all", "clean" and "preinstall" targets have recursive dependencies, instead of flat (depth of 1) ones. --- Source/cmGlobalUnixMakefileGenerator3.cxx | 63 ++++++++++++------------------- 1 file changed, 24 insertions(+), 39 deletions(-) diff --git a/Source/cmGlobalUnixMakefileGenerator3.cxx b/Source/cmGlobalUnixMakefileGenerator3.cxx index 2f3bc76..f640d52 100644 --- a/Source/cmGlobalUnixMakefileGenerator3.cxx +++ b/Source/cmGlobalUnixMakefileGenerator3.cxx @@ -232,18 +232,6 @@ void cmGlobalUnixMakefileGenerator3::WriteMainMakefile2() depends.push_back(this->EmptyRuleHackDepends); } - // Write and empty all: - lg->WriteMakeRule(makefileStream, "The main recursive all target", "all", - depends, no_commands, true); - - // Write an empty preinstall: - lg->WriteMakeRule(makefileStream, "The main recursive preinstall target", - "preinstall", depends, no_commands, true); - - // Write an empty clean: - lg->WriteMakeRule(makefileStream, "The main recursive clean target", "clean", - depends, no_commands, true); - // Write out the "special" stuff lg->WriteSpecialTargetsTop(makefileStream); @@ -414,7 +402,7 @@ void cmGlobalUnixMakefileGenerator3::WriteDirectoryRule2( { // Get the relative path to the subdirectory from the top. std::string makeTarget = lg->GetCurrentBinaryDirectory(); - makeTarget += "/"; + makeTarget += '/'; makeTarget += pass; // The directory-level rule should depend on the target-level rules @@ -444,7 +432,7 @@ void cmGlobalUnixMakefileGenerator3::WriteDirectoryRule2( // rules of the subdirectories. for (cmStateSnapshot const& c : lg->GetStateSnapshot().GetChildren()) { std::string subdir = c.GetDirectory().GetCurrentBinary(); - subdir += "/"; + subdir += '/'; subdir += pass; depends.push_back(std::move(subdir)); } @@ -456,9 +444,16 @@ void cmGlobalUnixMakefileGenerator3::WriteDirectoryRule2( } // Write the rule. - std::string doc = "Convenience name for \""; - doc += pass; - doc += "\" pass in the directory."; + std::string doc; + if (lg->IsRootMakefile()) { + doc = "The main recursive \""; + doc += pass; + doc += "\" target."; + } else { + doc = "Recursive \""; + doc += pass; + doc += "\" directory target."; + } std::vector no_commands; lg->WriteMakeRule(ruleFileStream, doc.c_str(), makeTarget, depends, no_commands, true); @@ -467,17 +462,19 @@ void cmGlobalUnixMakefileGenerator3::WriteDirectoryRule2( void cmGlobalUnixMakefileGenerator3::WriteDirectoryRules2( std::ostream& ruleFileStream, cmLocalUnixMakefileGenerator3* lg) { - // Only subdirectories need these rules. - if (lg->IsRootMakefile()) { - return; - } - // Begin the directory-level rules section. - std::string dir = - cmSystemTools::ConvertToOutputPath(lg->MaybeConvertToRelativePath( - lg->GetBinaryDirectory(), lg->GetCurrentBinaryDirectory())); - lg->WriteDivider(ruleFileStream); - ruleFileStream << "# Directory level rules for directory " << dir << "\n\n"; + { + std::string dir = + cmSystemTools::ConvertToOutputPath(lg->MaybeConvertToRelativePath( + lg->GetBinaryDirectory(), lg->GetCurrentBinaryDirectory())); + lg->WriteDivider(ruleFileStream); + if (lg->IsRootMakefile()) { + ruleFileStream << "# Directory level rules for the build root directory"; + } else { + ruleFileStream << "# Directory level rules for directory " << dir; + } + ruleFileStream << "\n\n"; + } // Write directory-level rules for "all". this->WriteDirectoryRule2(ruleFileStream, lg, "all", true, false); @@ -709,15 +706,6 @@ void cmGlobalUnixMakefileGenerator3::WriteConvenienceRules2( lg->WriteMakeRule(ruleFileStream, "All Build rule for target.", localName, depends, commands, true); - // add the all/all dependency - if (!this->IsExcluded(gtarget)) { - depends.clear(); - depends.push_back(localName); - commands.clear(); - lg->WriteMakeRule(ruleFileStream, "Include target in all.", "all", - depends, commands, true); - } - // Write the rule. commands.clear(); @@ -794,9 +782,6 @@ void cmGlobalUnixMakefileGenerator3::WriteConvenienceRules2( lg->WriteMakeRule(ruleFileStream, "clean rule for target.", makeTargetName, depends, commands, true); commands.clear(); - depends.push_back(makeTargetName); - lg->WriteMakeRule(ruleFileStream, "clean rule for target.", "clean", - depends, commands, true); } } } -- cgit v0.12 From 1ded3599d698c1bfa0243d58ece8b619d2900a17 Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Fri, 17 May 2019 17:15:50 +0200 Subject: Makefiles: Process ADDTIONAL_CLEAN_FILES dir prop at directory level In the "Unix Makefiles" generator, the `ADDTIONAL_CLEAN_FILES` directory property was evaluated on a per target basis. This had two drawbacks: - per directory clean files were repeated in every target clean script - per directory clean files weren't removed in directories without targets (issue #8164) This patch moves the `ADDTIONAL_CLEAN_FILES` directory property processing from the target to the directory level clean target. Fixes: #8164 "ADDITIONAL_CLEAN_FILES directory property not respected if no target present in directory" --- Source/cmGlobalUnixMakefileGenerator3.cxx | 14 ++++++--- Source/cmGlobalUnixMakefileGenerator3.h | 3 +- Source/cmLocalUnixMakefileGenerator3.cxx | 51 +++++++++++++++++++++++++++++++ Source/cmLocalUnixMakefileGenerator3.h | 1 + Source/cmMakefileTargetGenerator.cxx | 12 -------- 5 files changed, 63 insertions(+), 18 deletions(-) diff --git a/Source/cmGlobalUnixMakefileGenerator3.cxx b/Source/cmGlobalUnixMakefileGenerator3.cxx index f640d52..8053f61 100644 --- a/Source/cmGlobalUnixMakefileGenerator3.cxx +++ b/Source/cmGlobalUnixMakefileGenerator3.cxx @@ -398,7 +398,8 @@ void cmGlobalUnixMakefileGenerator3::WriteMainCMakefileLanguageRules( void cmGlobalUnixMakefileGenerator3::WriteDirectoryRule2( std::ostream& ruleFileStream, cmLocalUnixMakefileGenerator3* lg, - const char* pass, bool check_all, bool check_relink) + const char* pass, bool check_all, bool check_relink, + std::vector const& commands) { // Get the relative path to the subdirectory from the top. std::string makeTarget = lg->GetCurrentBinaryDirectory(); @@ -454,9 +455,8 @@ void cmGlobalUnixMakefileGenerator3::WriteDirectoryRule2( doc += pass; doc += "\" directory target."; } - std::vector no_commands; - lg->WriteMakeRule(ruleFileStream, doc.c_str(), makeTarget, depends, - no_commands, true); + lg->WriteMakeRule(ruleFileStream, doc.c_str(), makeTarget, depends, commands, + true); } void cmGlobalUnixMakefileGenerator3::WriteDirectoryRules2( @@ -480,7 +480,11 @@ void cmGlobalUnixMakefileGenerator3::WriteDirectoryRules2( this->WriteDirectoryRule2(ruleFileStream, lg, "all", true, false); // Write directory-level rules for "clean". - this->WriteDirectoryRule2(ruleFileStream, lg, "clean", false, false); + { + std::vector cmds; + lg->AppendDirectoryCleanCommand(cmds); + this->WriteDirectoryRule2(ruleFileStream, lg, "clean", false, false, cmds); + } // Write directory-level rules for "preinstall". this->WriteDirectoryRule2(ruleFileStream, lg, "preinstall", true, true); diff --git a/Source/cmGlobalUnixMakefileGenerator3.h b/Source/cmGlobalUnixMakefileGenerator3.h index e919d38..287472c 100644 --- a/Source/cmGlobalUnixMakefileGenerator3.h +++ b/Source/cmGlobalUnixMakefileGenerator3.h @@ -165,7 +165,8 @@ protected: void WriteDirectoryRule2(std::ostream& ruleFileStream, cmLocalUnixMakefileGenerator3* lg, const char* pass, - bool check_all, bool check_relink); + bool check_all, bool check_relink, + std::vector const& commands = {}); void WriteDirectoryRules2(std::ostream& ruleFileStream, cmLocalUnixMakefileGenerator3* lg); diff --git a/Source/cmLocalUnixMakefileGenerator3.cxx b/Source/cmLocalUnixMakefileGenerator3.cxx index 857440c..6a08840 100644 --- a/Source/cmLocalUnixMakefileGenerator3.cxx +++ b/Source/cmLocalUnixMakefileGenerator3.cxx @@ -15,6 +15,7 @@ #include "cmCustomCommandGenerator.h" #include "cmFileTimeCache.h" #include "cmGeneratedFileStream.h" +#include "cmGeneratorExpression.h" #include "cmGeneratorTarget.h" #include "cmGlobalGenerator.h" #include "cmGlobalUnixMakefileGenerator3.h" @@ -1089,6 +1090,56 @@ void cmLocalUnixMakefileGenerator3::AppendCleanCommand( } } +void cmLocalUnixMakefileGenerator3::AppendDirectoryCleanCommand( + std::vector& commands) +{ + std::vector cleanFiles; + // Look for additional files registered for cleaning in this directory. + if (const char* prop_value = + this->Makefile->GetProperty("ADDITIONAL_CLEAN_FILES")) { + cmGeneratorExpression ge; + std::unique_ptr cge = ge.Parse(prop_value); + cmSystemTools::ExpandListArgument( + cge->Evaluate(this, + this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE")), + cleanFiles); + } + if (cleanFiles.empty()) { + return; + } + + cmLocalGenerator* rootLG = + this->GetGlobalGenerator()->GetLocalGenerators().at(0); + std::string const& binaryDir = rootLG->GetCurrentBinaryDirectory(); + std::string const& currentBinaryDir = this->GetCurrentBinaryDirectory(); + std::string cleanfile = currentBinaryDir; + cleanfile += "/CMakeFiles/cmake_directory_clean.cmake"; + // Write clean script + { + std::string cleanfilePath = cmSystemTools::CollapseFullPath(cleanfile); + cmsys::ofstream fout(cleanfilePath.c_str()); + if (!fout) { + cmSystemTools::Error("Could not create " + cleanfilePath); + return; + } + fout << "file(REMOVE_RECURSE\n"; + for (std::string const& cfl : cleanFiles) { + std::string fc = rootLG->MaybeConvertToRelativePath( + binaryDir, cmSystemTools::CollapseFullPath(cfl, currentBinaryDir)); + fout << " " << cmOutputConverter::EscapeForCMake(fc) << "\n"; + } + fout << ")\n"; + } + // Create command + { + std::string remove = "$(CMAKE_COMMAND) -P "; + remove += this->ConvertToOutputFormat( + rootLG->MaybeConvertToRelativePath(binaryDir, cleanfile), + cmOutputConverter::SHELL); + commands.push_back(std::move(remove)); + } +} + void cmLocalUnixMakefileGenerator3::AppendEcho( std::vector& commands, std::string const& text, EchoColor color, EchoProgress const* progress) diff --git a/Source/cmLocalUnixMakefileGenerator3.h b/Source/cmLocalUnixMakefileGenerator3.h index fed25e1..c8e4b0e 100644 --- a/Source/cmLocalUnixMakefileGenerator3.h +++ b/Source/cmLocalUnixMakefileGenerator3.h @@ -227,6 +227,7 @@ protected: const std::set& files, cmGeneratorTarget* target, const char* filename = nullptr); + void AppendDirectoryCleanCommand(std::vector& commands); // Helper methods for dependency updates. bool ScanDependencies(std::string const& targetDir, diff --git a/Source/cmMakefileTargetGenerator.cxx b/Source/cmMakefileTargetGenerator.cxx index e62b107..3a89d75 100644 --- a/Source/cmMakefileTargetGenerator.cxx +++ b/Source/cmMakefileTargetGenerator.cxx @@ -172,18 +172,6 @@ void cmMakefileTargetGenerator::WriteTargetBuildRules() this->CleanFiles.insert(files.begin(), files.end()); } - // Look for additional files registered for cleaning in this directory. - if (const char* prop_value = - this->Makefile->GetProperty("ADDITIONAL_CLEAN_FILES")) { - std::vector const files = evaluatedFiles(prop_value); - // For relative path support - std::string const& binaryDir = - this->LocalGenerator->GetCurrentBinaryDirectory(); - for (std::string const& cfl : files) { - this->CleanFiles.insert(cmSystemTools::CollapseFullPath(cfl, binaryDir)); - } - } - // Look for additional files registered for cleaning in this target. if (const char* prop_value = this->GeneratorTarget->GetProperty("ADDITIONAL_CLEAN_FILES")) { -- cgit v0.12 From f945c3e755469457bd1c89fe7c9153521005f43f Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Fri, 17 May 2019 10:30:34 +0200 Subject: Tests: Extend MakeClean test to cover subdirectories without targets This adds a subdirectory to the MakeClean test, in which files are added to the `ADDITIONAL_CLEAN_FILES` directory property, but which holds no targets. --- Tests/MakeClean/ToClean/CMakeLists.txt | 82 +++++++++++++--------- Tests/MakeClean/ToClean/EmptySubDir/CMakeLists.txt | 17 +++++ 2 files changed, 64 insertions(+), 35 deletions(-) create mode 100644 Tests/MakeClean/ToClean/EmptySubDir/CMakeLists.txt diff --git a/Tests/MakeClean/ToClean/CMakeLists.txt b/Tests/MakeClean/ToClean/CMakeLists.txt index 5d84e6c..6f16d12 100644 --- a/Tests/MakeClean/ToClean/CMakeLists.txt +++ b/Tests/MakeClean/ToClean/CMakeLists.txt @@ -2,45 +2,56 @@ cmake_minimum_required(VERSION 3.14) project(ToClean) # Utility variables -set(TSD ${ToClean_SOURCE_DIR}) -set(TBD ${ToClean_BINARY_DIR}) +set(CSD ${CMAKE_CURRENT_SOURCE_DIR}) +set(CBD ${CMAKE_CURRENT_BINARY_DIR}) set(CLEAN_FILE_CONTENT "File registered for cleaning.\n") # Lists build-time-generated files that should be cleaned away -set(TOCLEAN_FILES) +set_property(GLOBAL PROPERTY TOCLEAN_FILES "") +function(addCleanFile FILENAME) + set_property(GLOBAL APPEND PROPERTY TOCLEAN_FILES "${FILENAME}") +endfunction() +function(writeCleanFile FILENAME) + file(WRITE "${FILENAME}" ${CLEAN_FILE_CONTENT}) +endfunction() # Build a simple project whose compiled objects should be cleaned. add_executable(toclean toclean.cxx) -list(APPEND TOCLEAN_FILES - "${TBD}${CMAKE_FILES_DIRECTORY}/toclean.dir/toclean.cxx${CMAKE_CXX_OUTPUT_EXTENSION}") +addCleanFile("${CBD}${CMAKE_FILES_DIRECTORY}/toclean.dir/toclean.cxx${CMAKE_CXX_OUTPUT_EXTENSION}") + +# Create a post build custom command that copies the toclean output executable +# to a custom location +function(addToCleanPostBuildCopy FILENAME) + add_custom_command(TARGET toclean POST_BUILD + COMMAND ${CMAKE_COMMAND} + ARGS -E copy $ ${FILENAME}) +endfunction() # Create a custom command whose output should be cleaned. -set(CustomCommandFile "${TBD}/CustomCommandFile.txt") +set(CustomCommandFile "${CBD}/CustomCommandFile.txt") add_custom_command(OUTPUT ${CustomCommandFile} - DEPENDS ${TSD}/toclean.cxx + DEPENDS ${CSD}/toclean.cxx COMMAND ${CMAKE_COMMAND} - ARGS -E copy ${TSD}/toclean.cxx ${CustomCommandFile}) + ARGS -E copy ${CSD}/toclean.cxx ${CustomCommandFile}) add_custom_target(generate ALL DEPENDS ${CustomCommandFile}) -list(APPEND TOCLEAN_FILES ${CustomCommandFile}) +addCleanFile(${CustomCommandFile}) ### Tests ADDITIONAL_MAKE_CLEAN_FILES directory property if("${CMAKE_GENERATOR}" MATCHES "Makefile") # Create a file that must be registered for cleaning. - set(MakeDirPropFile "${TBD}/MakeDirPropFile.txt") - file(WRITE "${MakeDirPropFile}" ${CLEAN_FILE_CONTENT}) + set(MakeDirPropFile "${CBD}/MakeDirPropFile.txt") + writeCleanFile("${MakeDirPropFile}") set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${MakeDirPropFile}") - list(APPEND TOCLEAN_FILES "${MakeDirPropFile}") + addCleanFile(${MakeDirPropFile}) # Create a custom command whose output should be cleaned, but whose name # is not known until generate-time set(MakeDirPropExpFileRel "MakeDirProp_copy${CMAKE_EXECUTABLE_SUFFIX}") set(MakeDirPropExpFile "$/${MakeDirPropExpFileRel}") - add_custom_command(TARGET toclean POST_BUILD - COMMAND ${CMAKE_COMMAND} - ARGS -E copy $ ${MakeDirPropExpFile}) + addToCleanPostBuildCopy("${MakeDirPropExpFile}") set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ${MakeDirPropExpFile}) - list(APPEND TOCLEAN_FILES "${TBD}/${MakeDirPropExpFileRel}") + addCleanFile("${CBD}/${MakeDirPropExpFileRel}") endif() @@ -48,51 +59,52 @@ endif() # Register a file path relative to the build directory set(DirPropFileRel "DirPropFileRel.txt") -file(WRITE "${TBD}/${DirPropFileRel}" ${CLEAN_FILE_CONTENT}) +writeCleanFile("${CBD}/${DirPropFileRel}") set_directory_properties(PROPERTIES ADDITIONAL_CLEAN_FILES ${DirPropFileRel}) -list(APPEND TOCLEAN_FILES "${TBD}/${DirPropFileRel}") +addCleanFile("${CBD}/${DirPropFileRel}") # Register an absolute file path -set(DirPropFileAbs "${TBD}/DirPropFileAbs.txt") -file(WRITE "${DirPropFileAbs}" ${CLEAN_FILE_CONTENT}) +set(DirPropFileAbs "${CBD}/DirPropFileAbs.txt") +writeCleanFile("${DirPropFileAbs}") set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_CLEAN_FILES ${DirPropFileAbs}) -list(APPEND TOCLEAN_FILES "${DirPropFileAbs}") +addCleanFile("${DirPropFileAbs}") # Create a custom command whose output should be cleaned, but whose name # is not known until generate-time set(DirPropExpFileRel "DirProp_copy${CMAKE_EXECUTABLE_SUFFIX}") set(DirPropExpFile "$/${DirPropExpFileRel}") -add_custom_command(TARGET toclean POST_BUILD - COMMAND ${CMAKE_COMMAND} - ARGS -E copy $ ${DirPropExpFile}) +addToCleanPostBuildCopy("${DirPropExpFile}") set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_CLEAN_FILES ${DirPropExpFile}) -list(APPEND TOCLEAN_FILES "${TBD}/${DirPropExpFileRel}") +addCleanFile("${CBD}/${DirPropExpFileRel}") ### Tests ADDITIONAL_CLEAN_FILES target property # Register a file path relative to the build directory set(TgtPropFileRel "TargetPropFileRel.txt") -file(WRITE "${TBD}/${TgtPropFileRel}" ${CLEAN_FILE_CONTENT}) +writeCleanFile("${CBD}/${TgtPropFileRel}") set_target_properties(toclean PROPERTIES ADDITIONAL_CLEAN_FILES ${TgtPropFileRel}) -list(APPEND TOCLEAN_FILES "${TBD}/${TgtPropFileRel}") +addCleanFile("${CBD}/${TgtPropFileRel}") # Register an absolute file path -set(TgtPropFileAbs "${TBD}/TargetPropFileAbs.txt") -file(WRITE "${TgtPropFileAbs}" ${CLEAN_FILE_CONTENT}) +set(TgtPropFileAbs "${CBD}/TargetPropFileAbs.txt") +writeCleanFile("${TgtPropFileAbs}") set_property(TARGET toclean APPEND PROPERTY ADDITIONAL_CLEAN_FILES ${TgtPropFileAbs}) -list(APPEND TOCLEAN_FILES "${TgtPropFileAbs}") +addCleanFile("${TgtPropFileAbs}") # Create a custom command whose output should be cleaned, but whose name # is not known until generate-time set(TgtPropExpFileRel "TgtProp_copy${CMAKE_EXECUTABLE_SUFFIX}") set(TgtPropExpFile "$/${TgtPropExpFileRel}") -add_custom_command(TARGET toclean POST_BUILD - COMMAND ${CMAKE_COMMAND} - ARGS -E copy $ ${TgtPropExpFile}) +addToCleanPostBuildCopy("${TgtPropExpFile}") set_property(TARGET toclean APPEND PROPERTY ADDITIONAL_CLEAN_FILES ${TgtPropExpFile}) -list(APPEND TOCLEAN_FILES "${TBD}/${TgtPropExpFileRel}") +addCleanFile("${CBD}/${TgtPropExpFileRel}") + + +# Process subdirectory without targets +add_subdirectory(EmptySubDir) # Configure a file listing these build-time-generated files. -configure_file(${TSD}/ToCleanFiles.cmake.in ${TBD}/ToCleanFiles.cmake @ONLY) +get_property(TOCLEAN_FILES GLOBAL PROPERTY TOCLEAN_FILES) +configure_file(${CSD}/ToCleanFiles.cmake.in ${CBD}/ToCleanFiles.cmake @ONLY) diff --git a/Tests/MakeClean/ToClean/EmptySubDir/CMakeLists.txt b/Tests/MakeClean/ToClean/EmptySubDir/CMakeLists.txt new file mode 100644 index 0000000..55893ae --- /dev/null +++ b/Tests/MakeClean/ToClean/EmptySubDir/CMakeLists.txt @@ -0,0 +1,17 @@ +cmake_minimum_required(VERSION 3.14) + +# Subdirectory CMakeLists.txt without targets +set(CSD ${CMAKE_CURRENT_SOURCE_DIR}) +set(CBD ${CMAKE_CURRENT_BINARY_DIR}) + +# Register a file path relative to the build directory +set(DirPropFileRel "DirPropFileRel.txt") +writeCleanFile("${CBD}/${DirPropFileRel}") +set_directory_properties(PROPERTIES ADDITIONAL_CLEAN_FILES ${DirPropFileRel}) +addCleanFile("${CBD}/${DirPropFileRel}") + +# Register an absolute file path +set(DirPropFileAbs "${CBD}/DirPropFileAbs.txt") +writeCleanFile("${DirPropFileAbs}") +set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_CLEAN_FILES ${DirPropFileAbs}) +addCleanFile("${DirPropFileAbs}") -- cgit v0.12