From 0cfbd85e7b0d61affda6450b1cc081860b5543a6 Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 24 Sep 2019 13:07:14 -0400 Subject: Tests: Teach RunCMake to support a custom working directory --- Tests/RunCMake/RunCMake.cmake | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Tests/RunCMake/RunCMake.cmake b/Tests/RunCMake/RunCMake.cmake index ce71677..644da60 100644 --- a/Tests/RunCMake/RunCMake.cmake +++ b/Tests/RunCMake/RunCMake.cmake @@ -82,9 +82,12 @@ function(run_cmake test) set(maybe_input_file "") endif() if(RunCMake_TEST_COMMAND) + if(NOT RunCMake_TEST_COMMAND_WORKING_DIRECTORY) + set(RunCMake_TEST_COMMAND_WORKING_DIRECTORY "${RunCMake_TEST_BINARY_DIR}") + endif() execute_process( COMMAND ${RunCMake_TEST_COMMAND} - WORKING_DIRECTORY "${RunCMake_TEST_BINARY_DIR}" + WORKING_DIRECTORY "${RunCMake_TEST_COMMAND_WORKING_DIRECTORY}" OUTPUT_VARIABLE actual_stdout ERROR_VARIABLE ${actual_stderr_var} RESULT_VARIABLE actual_result -- cgit v0.12 From 21442d72a44c2bd732f2ff19ed89ce488854d25d Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 24 Sep 2019 12:39:33 -0400 Subject: Tests: Revise RunCMake.add_subdirectory ExcludeFromAll to avoid globbing Also simplify the clean step. --- .../RunCMake/add_subdirectory/ExcludeFromAll.cmake | 7 +++ .../add_subdirectory/ExcludeFromAll/CMakeLists.txt | 12 ---- .../add_subdirectory/ExcludeFromAll/check.cmake | 69 +++++++++------------- Tests/RunCMake/add_subdirectory/RunCMakeTest.cmake | 16 ++--- 4 files changed, 43 insertions(+), 61 deletions(-) diff --git a/Tests/RunCMake/add_subdirectory/ExcludeFromAll.cmake b/Tests/RunCMake/add_subdirectory/ExcludeFromAll.cmake index f686005..cc31428 100644 --- a/Tests/RunCMake/add_subdirectory/ExcludeFromAll.cmake +++ b/Tests/RunCMake/add_subdirectory/ExcludeFromAll.cmake @@ -4,3 +4,10 @@ add_subdirectory(ExcludeFromAll EXCLUDE_FROM_ALL) add_executable(main main.cpp) target_link_libraries(main PRIVATE foo) + +file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/check-$>.cmake CONTENT " +set(main_exe \"$\") +set(foo_lib \"$\") +set(bar_lib \"$\") +set(baz_lib \"$\") +") diff --git a/Tests/RunCMake/add_subdirectory/ExcludeFromAll/CMakeLists.txt b/Tests/RunCMake/add_subdirectory/ExcludeFromAll/CMakeLists.txt index 9e6462b..99add23 100644 --- a/Tests/RunCMake/add_subdirectory/ExcludeFromAll/CMakeLists.txt +++ b/Tests/RunCMake/add_subdirectory/ExcludeFromAll/CMakeLists.txt @@ -5,16 +5,4 @@ add_library(foo STATIC foo.cpp) add_library(baz STATIC foo.cpp) set_target_properties(baz PROPERTIES EXCLUDE_FROM_ALL OFF) -file(GENERATE - OUTPUT "${CMAKE_BINARY_DIR}/main.txt" - CONTENT "$") - -file(GENERATE - OUTPUT "${CMAKE_BINARY_DIR}/bar.txt" - CONTENT "$") - -file(GENERATE - OUTPUT "${CMAKE_BINARY_DIR}/baz.txt" - CONTENT "$") - target_include_directories(foo PUBLIC .) diff --git a/Tests/RunCMake/add_subdirectory/ExcludeFromAll/check.cmake b/Tests/RunCMake/add_subdirectory/ExcludeFromAll/check.cmake index 14ec482..2a0179e 100644 --- a/Tests/RunCMake/add_subdirectory/ExcludeFromAll/check.cmake +++ b/Tests/RunCMake/add_subdirectory/ExcludeFromAll/check.cmake @@ -1,44 +1,31 @@ -# Use globbing to check if exes / libs were built because determining -# exactly where these files will live inside a CMake -P script is -# pretty challenging. - -file(READ "${RunCMake_TEST_BINARY_DIR}/main.txt" main_exe) -file(READ "${RunCMake_TEST_BINARY_DIR}/bar.txt" bar_lib) -file(READ "${RunCMake_TEST_BINARY_DIR}/baz.txt" baz_lib) - -set(found_main FALSE) -file(GLOB_RECURSE files - LIST_DIRECTORIES FALSE - RELATIVE "${RunCMake_TEST_BINARY_DIR}" - "${RunCMake_TEST_BINARY_DIR}/*") -foreach (file IN LISTS files) - if (file MATCHES "${main_exe}") - set(found_main TRUE) +if(EXISTS ${RunCMake_TEST_BINARY_DIR}/check-debug.cmake) + include(${RunCMake_TEST_BINARY_DIR}/check-debug.cmake) + if(RunCMake_TEST_FAILED) + return() endif() -endforeach() -if (NOT found_main) - set(RunCMake_TEST_FAILED "'main' missing from ${RunCMake_TEST_BINARY_DIR}") -endif() -set(found_bar FALSE) -set(found_baz FALSE) -file(GLOB_RECURSE files - LIST_DIRECTORIES FALSE - RELATIVE "${RunCMake_TEST_BINARY_DIR}/ExcludeFromAll" - "${RunCMake_TEST_BINARY_DIR}/ExcludeFromAll/*") -foreach (file IN LISTS files) - if (file MATCHES "${bar_lib}") - set(found_bar TRUE) - endif() - if (file MATCHES "${baz_lib}") - set(found_baz TRUE) - endif() -endforeach() -if (found_bar) - set(RunCMake_TEST_FAILED - "'bar' was not excluded from ${RunCMake_TEST_BINARY_DIR}/ExcludeFromAll") -endif() -if (NOT found_baz) - set(RunCMake_TEST_FAILED - "'baz' missing from ${RunCMake_TEST_BINARY_DIR}/ExcludeFromAll") + foreach(file + "${foo_lib}" + "${baz_lib}" + "${main_exe}" + ) + if(NOT EXISTS "${file}") + set(RunCMake_TEST_FAILED + "Artifact should exist but is missing:\n ${file}") + return() + endif() + endforeach() + foreach(file + "${bar_lib}" + ) + if(EXISTS "${file}") + set(RunCMake_TEST_FAILED + "Artifact should be missing but exists:\n ${file}") + return() + endif() + endforeach() +else() + set(RunCMake_TEST_FAILED " + '${RunCMake_TEST_BINARY_DIR}/check-debug.cmake' missing +") endif() diff --git a/Tests/RunCMake/add_subdirectory/RunCMakeTest.cmake b/Tests/RunCMake/add_subdirectory/RunCMakeTest.cmake index 781e483..e9ba92f 100644 --- a/Tests/RunCMake/add_subdirectory/RunCMakeTest.cmake +++ b/Tests/RunCMake/add_subdirectory/RunCMakeTest.cmake @@ -27,14 +27,14 @@ run_cmake_install(CMP0082-OLD -DCMP0082_VALUE=OLD) run_cmake_install(CMP0082-NEW -DCMP0082_VALUE=NEW) set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/ExcludeFromAll-build) -set(RunCMake_TEST_NO_CLEAN 1) - -file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}") -file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}") - +if(NOT RunCMake_GENERATOR_IS_MULTI_CONFIG) + set(RunCMake_TEST_OPTIONS -DCMAKE_BUILD_TYPE=Debug) +endif() run_cmake(ExcludeFromAll) +set(RunCMake_TEST_NO_CLEAN 1) set(RunCMake-check-file ExcludeFromAll/check.cmake) -run_cmake_command(ExcludeFromAll-build ${CMAKE_COMMAND} --build .) - -unset(RunCMake_TEST_BINARY_DIR) +run_cmake_command(ExcludeFromAll-build ${CMAKE_COMMAND} --build . --config Debug) +unset(RunCMake-check-file) unset(RunCMake_TEST_NO_CLEAN) +unset(RunCMake_TEST_OPTIONS) +unset(RunCMake_TEST_BINARY_DIR) -- cgit v0.12 From cf01d3d2bd649ab1157641b3212a360b06db747f Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 26 Sep 2019 14:47:53 -0400 Subject: Tests: Clarify target names in RunCMake.add_subdirectory ExcludeFromAll Rename the `baz` target to `subinc` to clarify that its role is to be included even though it is in an otherwise excluded subdirectory. --- Tests/RunCMake/add_subdirectory/ExcludeFromAll.cmake | 2 +- Tests/RunCMake/add_subdirectory/ExcludeFromAll/CMakeLists.txt | 7 +++---- Tests/RunCMake/add_subdirectory/ExcludeFromAll/check.cmake | 2 +- Tests/RunCMake/add_subdirectory/ExcludeFromAll/subinc.cpp | 4 ++++ 4 files changed, 9 insertions(+), 6 deletions(-) create mode 100644 Tests/RunCMake/add_subdirectory/ExcludeFromAll/subinc.cpp diff --git a/Tests/RunCMake/add_subdirectory/ExcludeFromAll.cmake b/Tests/RunCMake/add_subdirectory/ExcludeFromAll.cmake index cc31428..16f39d9 100644 --- a/Tests/RunCMake/add_subdirectory/ExcludeFromAll.cmake +++ b/Tests/RunCMake/add_subdirectory/ExcludeFromAll.cmake @@ -9,5 +9,5 @@ file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/check-$>.c set(main_exe \"$\") set(foo_lib \"$\") set(bar_lib \"$\") -set(baz_lib \"$\") +set(subinc_lib \"$\") ") diff --git a/Tests/RunCMake/add_subdirectory/ExcludeFromAll/CMakeLists.txt b/Tests/RunCMake/add_subdirectory/ExcludeFromAll/CMakeLists.txt index 99add23..9d7922f 100644 --- a/Tests/RunCMake/add_subdirectory/ExcludeFromAll/CMakeLists.txt +++ b/Tests/RunCMake/add_subdirectory/ExcludeFromAll/CMakeLists.txt @@ -1,8 +1,7 @@ add_library(bar STATIC bar.cpp) add_library(foo STATIC foo.cpp) - -add_library(baz STATIC foo.cpp) -set_target_properties(baz PROPERTIES EXCLUDE_FROM_ALL OFF) - target_include_directories(foo PUBLIC .) + +add_library(subinc STATIC subinc.cpp) +set_target_properties(subinc PROPERTIES EXCLUDE_FROM_ALL OFF) diff --git a/Tests/RunCMake/add_subdirectory/ExcludeFromAll/check.cmake b/Tests/RunCMake/add_subdirectory/ExcludeFromAll/check.cmake index 2a0179e..56a8abd 100644 --- a/Tests/RunCMake/add_subdirectory/ExcludeFromAll/check.cmake +++ b/Tests/RunCMake/add_subdirectory/ExcludeFromAll/check.cmake @@ -6,7 +6,7 @@ if(EXISTS ${RunCMake_TEST_BINARY_DIR}/check-debug.cmake) foreach(file "${foo_lib}" - "${baz_lib}" + "${subinc_lib}" "${main_exe}" ) if(NOT EXISTS "${file}") diff --git a/Tests/RunCMake/add_subdirectory/ExcludeFromAll/subinc.cpp b/Tests/RunCMake/add_subdirectory/ExcludeFromAll/subinc.cpp new file mode 100644 index 0000000..e9faacd --- /dev/null +++ b/Tests/RunCMake/add_subdirectory/ExcludeFromAll/subinc.cpp @@ -0,0 +1,4 @@ +int subinc() +{ + return 0; +} -- cgit v0.12 From 156b56480a786db4d967bde5eb6d5edee56a27d0 Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 27 Sep 2019 13:06:56 -0400 Subject: Makefiles: Revert "Make build root targets ... recursive" Revert the main logic change from commit 827da1119e (Makefiles: Make build root targets "all", "clean" and "preinstall" recursive, 2019-05-17, v3.15.0-rc1~96^2~2) for the "all" and "preinstall" targets. The commit cleaned up the Makefile generator to use the same logic for the "all" target in the top-level directory as for subdirectories. It exposed a long-existing bug that caused the "all" target in a subdirectory to include the "all" targets from sub-subdirectories even if they are marked `EXCLUDE_FROM_ALL`. The `Tests/SubDir` test should fail but the problem is currently covered up by another bug introduced by commit dc6888573d (Pass EXCLUDE_FROM_ALL from directory to targets, 2019-01-15, v3.14.0-rc1~83^2) that causes the "all" targets in `EXCLUDE_FROM_ALL` subdirectories to be empty. Revert the top-level "all" and "preinstall" targets to the old approach to prepare to fix the latter bug without exposing the long-existing bug at the top-level. Leave the "clean" target in the new approach because it does not honor `EXCLUDE_FROM_ALL` anyway. Issue: #19753 --- Source/cmGlobalUnixMakefileGenerator3.cxx | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/Source/cmGlobalUnixMakefileGenerator3.cxx b/Source/cmGlobalUnixMakefileGenerator3.cxx index aa584ad..c636334 100644 --- a/Source/cmGlobalUnixMakefileGenerator3.cxx +++ b/Source/cmGlobalUnixMakefileGenerator3.cxx @@ -232,6 +232,14 @@ 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 out the "special" stuff lg->WriteSpecialTargetsTop(makefileStream); @@ -473,8 +481,13 @@ void cmGlobalUnixMakefileGenerator3::WriteDirectoryRules2( ruleFileStream << "\n\n"; } - // Write directory-level rules for "all". - this->WriteDirectoryRule2(ruleFileStream, lg, "all", true, false); + if (!lg->IsRootMakefile()) { + // Write directory-level rules for "all". + this->WriteDirectoryRule2(ruleFileStream, lg, "all", true, false); + + // Write directory-level rules for "preinstall". + this->WriteDirectoryRule2(ruleFileStream, lg, "preinstall", true, true); + } // Write directory-level rules for "clean". { @@ -482,9 +495,6 @@ void cmGlobalUnixMakefileGenerator3::WriteDirectoryRules2( lg->AppendDirectoryCleanCommand(cmds); this->WriteDirectoryRule2(ruleFileStream, lg, "clean", false, false, cmds); } - - // Write directory-level rules for "preinstall". - this->WriteDirectoryRule2(ruleFileStream, lg, "preinstall", true, true); } std::vector @@ -707,6 +717,15 @@ 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(); -- cgit v0.12 From b3b1c7bf3afc8f33fa69b79f47f778cb781ac3c7 Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 24 Sep 2019 11:50:18 -0400 Subject: Restore "all" target in subdirectories marked EXCLUDE_FROM_ALL The "all" target in each directory is supposed to have targets from that directory even if the directory itself is marked `EXCLUDE_FROM_ALL` in its parent. This was broken by commit dc6888573d (Pass EXCLUDE_FROM_ALL from directory to targets, 2019-01-15, v3.14.0-rc1~83^2) which made the participation of a target in "all" independent of context. Revert much of the logic change from that commit to restore the old behavior. Then re-implement the behavior intended by the commit to keep its test working. Extend the test to cover the old behavior too. Fixes: #19753 --- Help/prop_dir/EXCLUDE_FROM_ALL.rst | 20 ++++++-------- Help/prop_tgt/EXCLUDE_FROM_ALL.rst | 16 +++++------ Source/cmGlobalGenerator.cxx | 14 ++++++++-- Source/cmGlobalGenerator.h | 2 +- Source/cmGlobalNinjaGenerator.h | 4 +-- Source/cmGlobalUnixMakefileGenerator3.cxx | 4 +-- Source/cmGlobalVisualStudioGenerator.cxx | 2 +- Source/cmGlobalXCodeGenerator.cxx | 2 +- Source/cmLocalNinjaGenerator.cxx | 4 ++- Source/cmMakefile.cxx | 10 +++---- .../ExcludeFromAll-build-sub-stderr.txt | 1 + .../RunCMake/add_subdirectory/ExcludeFromAll.cmake | 1 + .../add_subdirectory/ExcludeFromAll/CMakeLists.txt | 6 +++- .../ExcludeFromAll/check-sub.cmake | 32 ++++++++++++++++++++++ .../add_subdirectory/ExcludeFromAll/check.cmake | 6 +++- .../add_subdirectory/ExcludeFromAll/zot.cpp | 4 +++ Tests/RunCMake/add_subdirectory/RunCMakeTest.cmake | 20 ++++++++++++++ 17 files changed, 110 insertions(+), 38 deletions(-) create mode 100644 Tests/RunCMake/add_subdirectory/ExcludeFromAll-build-sub-stderr.txt create mode 100644 Tests/RunCMake/add_subdirectory/ExcludeFromAll/check-sub.cmake create mode 100644 Tests/RunCMake/add_subdirectory/ExcludeFromAll/zot.cpp diff --git a/Help/prop_dir/EXCLUDE_FROM_ALL.rst b/Help/prop_dir/EXCLUDE_FROM_ALL.rst index 9d3192c..8e3cca0 100644 --- a/Help/prop_dir/EXCLUDE_FROM_ALL.rst +++ b/Help/prop_dir/EXCLUDE_FROM_ALL.rst @@ -1,15 +1,13 @@ EXCLUDE_FROM_ALL ---------------- -Exclude the directory from the all target of its parent. +Set this directory property to a true value on a subdirectory to exclude +its targets from the "all" target of its ancestors. If excluded, running +e.g. ``make`` in the parent directory will not build targets the +subdirectory by default. This does not affect the "all" target of the +subdirectory itself. Running e.g. ``make`` inside the subdirectory will +still build its targets. -A property on a directory that indicates if its targets are excluded -from the default build target. If it is not, then with a Makefile for -example typing make will cause the targets to be built. The same -concept applies to the default build of other generators. - -Targets inherit the :prop_tgt:`EXCLUDE_FROM_ALL` property from the directory -that they are created in. When a directory is excluded, all of its targets will -have :prop_tgt:`EXCLUDE_FROM_ALL` set to ``TRUE``. After creating such a target -you can change its :prop_tgt:`EXCLUDE_FROM_ALL` property to ``FALSE``. This -will cause the target to be included in the default build target. +If the :prop_tgt:`EXCLUDE_FROM_ALL` target property is set on a target +then its value determines whether the target is included in the "all" +target of this directory and its ancestors. diff --git a/Help/prop_tgt/EXCLUDE_FROM_ALL.rst b/Help/prop_tgt/EXCLUDE_FROM_ALL.rst index 0eee297..3aa296d 100644 --- a/Help/prop_tgt/EXCLUDE_FROM_ALL.rst +++ b/Help/prop_tgt/EXCLUDE_FROM_ALL.rst @@ -1,12 +1,15 @@ EXCLUDE_FROM_ALL ---------------- -Exclude the target from the all target. +Set this target property to a true (or false) value to exclude (or include) +the target from the "all" target of the containing directory and its +ancestors. If excluded, running e.g. ``make`` in the containing directory +or its ancestors will not build the target by default. -A property on a target that indicates if the target is excluded from -the default build target. If it is not, then with a Makefile for -example typing make will cause this target to be built. The same -concept applies to the default build of other generators. +If this target property is not set then the target will be included in +the "all" target of the containing directory. Furthermore, it will be +included in the "all" target of its ancestor directories unless the +:prop_dir:`EXCLUDE_FROM_ALL` directory property is set. With ``EXCLUDE_FROM_ALL`` set to false or not set at all, the target will be brought up to date as part of doing a ``make install`` or its @@ -16,6 +19,3 @@ target has undefined behavior. Note that such a target can still safely be listed in an :command:`install(TARGETS)` command as long as the install components the target belongs to are not part of the set of components that anything tries to install. - -This property is enabled by default for targets that are created in -directories that have :prop_dir:`EXCLUDE_FROM_ALL` set to ``TRUE``. diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index 386a3f7..8a3720f 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -2029,10 +2029,18 @@ bool cmGlobalGenerator::IsExcluded(cmLocalGenerator* root, return this->IsExcluded(rootSnp, snp); } -bool cmGlobalGenerator::IsExcluded(cmGeneratorTarget* target) const +bool cmGlobalGenerator::IsExcluded(cmLocalGenerator* root, + cmGeneratorTarget* target) const { - return target->GetType() == cmStateEnums::INTERFACE_LIBRARY || - target->GetPropertyAsBool("EXCLUDE_FROM_ALL"); + if (target->GetType() == cmStateEnums::INTERFACE_LIBRARY) { + return true; + } + if (const char* exclude = target->GetProperty("EXCLUDE_FROM_ALL")) { + return cmSystemTools::IsOn(exclude); + } + // This target is included in its directory. Check whether the + // directory is excluded. + return this->IsExcluded(root, target->GetLocalGenerator()); } void cmGlobalGenerator::GetEnabledLanguages( diff --git a/Source/cmGlobalGenerator.h b/Source/cmGlobalGenerator.h index ac01326..0e40610 100644 --- a/Source/cmGlobalGenerator.h +++ b/Source/cmGlobalGenerator.h @@ -522,7 +522,7 @@ protected: bool IsExcluded(cmStateSnapshot const& root, cmStateSnapshot const& snp) const; bool IsExcluded(cmLocalGenerator* root, cmLocalGenerator* gen) const; - bool IsExcluded(cmGeneratorTarget* target) const; + bool IsExcluded(cmLocalGenerator* root, cmGeneratorTarget* target) const; virtual void InitializeProgressMarks() {} struct GlobalTargetInfo diff --git a/Source/cmGlobalNinjaGenerator.h b/Source/cmGlobalNinjaGenerator.h index c619e67..226b73d 100644 --- a/Source/cmGlobalNinjaGenerator.h +++ b/Source/cmGlobalNinjaGenerator.h @@ -329,9 +329,9 @@ public: return LocalGenerators; } - bool IsExcluded(cmGeneratorTarget* target) + bool IsExcluded(cmLocalGenerator* root, cmGeneratorTarget* target) { - return cmGlobalGenerator::IsExcluded(target); + return cmGlobalGenerator::IsExcluded(root, target); } int GetRuleCmdLength(const std::string& name) { return RuleCmdLength[name]; } diff --git a/Source/cmGlobalUnixMakefileGenerator3.cxx b/Source/cmGlobalUnixMakefileGenerator3.cxx index dac6ea6..f1a128a 100644 --- a/Source/cmGlobalUnixMakefileGenerator3.cxx +++ b/Source/cmGlobalUnixMakefileGenerator3.cxx @@ -713,7 +713,7 @@ void cmGlobalUnixMakefileGenerator3::WriteConvenienceRules2( localName, depends, commands, true); // add the all/all dependency - if (!this->IsExcluded(gtarget)) { + if (!this->IsExcluded(this->LocalGenerators[0], gtarget)) { depends.clear(); depends.push_back(localName); commands.clear(); @@ -777,7 +777,7 @@ void cmGlobalUnixMakefileGenerator3::WriteConvenienceRules2( "Pre-install relink rule for target.", localName, depends, commands, true); - if (!this->IsExcluded(gtarget)) { + if (!this->IsExcluded(this->LocalGenerators[0], gtarget)) { depends.clear(); depends.push_back(localName); commands.clear(); diff --git a/Source/cmGlobalVisualStudioGenerator.cxx b/Source/cmGlobalVisualStudioGenerator.cxx index f3ed76b..cc5a880 100644 --- a/Source/cmGlobalVisualStudioGenerator.cxx +++ b/Source/cmGlobalVisualStudioGenerator.cxx @@ -209,7 +209,7 @@ void cmGlobalVisualStudioGenerator::AddExtraIDETargets() tgt->IsImported()) { continue; } - if (!this->IsExcluded(tgt)) { + if (!this->IsExcluded(gen[0], tgt)) { allBuild->AddUtility(tgt->GetName()); } } diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index 57de60e..dc63ce6 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -567,7 +567,7 @@ void cmGlobalXCodeGenerator::AddExtraTargets( false, "", false, cmMakefile::AcceptObjectLibraryCommands); } - if (!this->IsExcluded(target)) { + if (!this->IsExcluded(gens[0], target)) { allbuild->AddUtility(target->GetName()); } } diff --git a/Source/cmLocalNinjaGenerator.cxx b/Source/cmLocalNinjaGenerator.cxx index c0afc25..69656a2 100644 --- a/Source/cmLocalNinjaGenerator.cxx +++ b/Source/cmLocalNinjaGenerator.cxx @@ -88,7 +88,9 @@ void cmLocalNinjaGenerator::Generate() if (tg) { tg->Generate(); // Add the target to "all" if required. - if (!this->GetGlobalNinjaGenerator()->IsExcluded(target)) { + if (!this->GetGlobalNinjaGenerator()->IsExcluded( + this->GetGlobalNinjaGenerator()->GetLocalGenerators()[0], + target)) { this->GetGlobalNinjaGenerator()->AddDependencyToAll(target); } delete tg; diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 7e33bda..2735122 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -1151,7 +1151,7 @@ cmTarget* cmMakefile::AddUtilityCommand( // Create a target instance for this utility. cmTarget* target = this->AddNewTarget(cmStateEnums::UTILITY, utilityName); target->SetIsGeneratorProvided(origin == TargetOrigin::Generator); - if (excludeFromAll || this->GetPropertyAsBool("EXCLUDE_FROM_ALL")) { + if (excludeFromAll) { target->SetProperty("EXCLUDE_FROM_ALL", "TRUE"); } if (!comment) { @@ -1689,7 +1689,7 @@ void cmMakefile::AddSubDirectory(const std::string& srcPath, cmMakefile* subMf = new cmMakefile(this->GlobalGenerator, newSnapshot); this->GetGlobalGenerator()->AddMakefile(subMf); - if (excludeFromAll || this->GetPropertyAsBool("EXCLUDE_FROM_ALL")) { + if (excludeFromAll) { subMf->SetProperty("EXCLUDE_FROM_ALL", "TRUE"); } @@ -1985,9 +1985,7 @@ cmTarget* cmMakefile::AddLibrary(const std::string& lname, // over changes in CMakeLists.txt, making the information stale and // hence useless. target->ClearDependencyInformation(*this); - if (excludeFromAll || - (type != cmStateEnums::INTERFACE_LIBRARY && - this->GetPropertyAsBool("EXCLUDE_FROM_ALL"))) { + if (excludeFromAll) { target->SetProperty("EXCLUDE_FROM_ALL", "TRUE"); } target->AddSources(srcs); @@ -2000,7 +1998,7 @@ cmTarget* cmMakefile::AddExecutable(const std::string& exeName, bool excludeFromAll) { cmTarget* target = this->AddNewTarget(cmStateEnums::EXECUTABLE, exeName); - if (excludeFromAll || this->GetPropertyAsBool("EXCLUDE_FROM_ALL")) { + if (excludeFromAll) { target->SetProperty("EXCLUDE_FROM_ALL", "TRUE"); } target->AddSources(srcs); diff --git a/Tests/RunCMake/add_subdirectory/ExcludeFromAll-build-sub-stderr.txt b/Tests/RunCMake/add_subdirectory/ExcludeFromAll-build-sub-stderr.txt new file mode 100644 index 0000000..8d98f9d --- /dev/null +++ b/Tests/RunCMake/add_subdirectory/ExcludeFromAll-build-sub-stderr.txt @@ -0,0 +1 @@ +.* diff --git a/Tests/RunCMake/add_subdirectory/ExcludeFromAll.cmake b/Tests/RunCMake/add_subdirectory/ExcludeFromAll.cmake index 16f39d9..ff676a6 100644 --- a/Tests/RunCMake/add_subdirectory/ExcludeFromAll.cmake +++ b/Tests/RunCMake/add_subdirectory/ExcludeFromAll.cmake @@ -9,5 +9,6 @@ file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/check-$>.c set(main_exe \"$\") set(foo_lib \"$\") set(bar_lib \"$\") +set(zot_lib \"$\") set(subinc_lib \"$\") ") diff --git a/Tests/RunCMake/add_subdirectory/ExcludeFromAll/CMakeLists.txt b/Tests/RunCMake/add_subdirectory/ExcludeFromAll/CMakeLists.txt index 9d7922f..790da54 100644 --- a/Tests/RunCMake/add_subdirectory/ExcludeFromAll/CMakeLists.txt +++ b/Tests/RunCMake/add_subdirectory/ExcludeFromAll/CMakeLists.txt @@ -1,4 +1,8 @@ -add_library(bar STATIC bar.cpp) +project(ExcludeFromAllSub NONE) + +add_library(bar STATIC EXCLUDE_FROM_ALL bar.cpp) + +add_library(zot STATIC zot.cpp) add_library(foo STATIC foo.cpp) target_include_directories(foo PUBLIC .) diff --git a/Tests/RunCMake/add_subdirectory/ExcludeFromAll/check-sub.cmake b/Tests/RunCMake/add_subdirectory/ExcludeFromAll/check-sub.cmake new file mode 100644 index 0000000..297ad1e --- /dev/null +++ b/Tests/RunCMake/add_subdirectory/ExcludeFromAll/check-sub.cmake @@ -0,0 +1,32 @@ +if(EXISTS ${RunCMake_TEST_BINARY_DIR}/check-debug.cmake) + include(${RunCMake_TEST_BINARY_DIR}/check-debug.cmake) + if(RunCMake_TEST_FAILED) + return() + endif() + + foreach(file + "${foo_lib}" + "${subinc_lib}" + "${zot_lib}" + ) + if(NOT EXISTS "${file}") + set(RunCMake_TEST_FAILED + "Artifact should exist but is missing:\n ${file}") + return() + endif() + endforeach() + foreach(file + "${main_exe}" + "${bar_lib}" + ) + if(EXISTS "${file}") + set(RunCMake_TEST_FAILED + "Artifact should be missing but exists:\n ${file}") + return() + endif() + endforeach() +else() + set(RunCMake_TEST_FAILED " + '${RunCMake_TEST_BINARY_DIR}/check-debug.cmake' missing +") +endif() diff --git a/Tests/RunCMake/add_subdirectory/ExcludeFromAll/check.cmake b/Tests/RunCMake/add_subdirectory/ExcludeFromAll/check.cmake index 56a8abd..433c032 100644 --- a/Tests/RunCMake/add_subdirectory/ExcludeFromAll/check.cmake +++ b/Tests/RunCMake/add_subdirectory/ExcludeFromAll/check.cmake @@ -9,13 +9,17 @@ if(EXISTS ${RunCMake_TEST_BINARY_DIR}/check-debug.cmake) "${subinc_lib}" "${main_exe}" ) - if(NOT EXISTS "${file}") + if(EXISTS "${file}") + # Remove for next step of test. + file(REMOVE "${file}") + else() set(RunCMake_TEST_FAILED "Artifact should exist but is missing:\n ${file}") return() endif() endforeach() foreach(file + "${zot_lib}" "${bar_lib}" ) if(EXISTS "${file}") diff --git a/Tests/RunCMake/add_subdirectory/ExcludeFromAll/zot.cpp b/Tests/RunCMake/add_subdirectory/ExcludeFromAll/zot.cpp new file mode 100644 index 0000000..ba7e966 --- /dev/null +++ b/Tests/RunCMake/add_subdirectory/ExcludeFromAll/zot.cpp @@ -0,0 +1,4 @@ +int zot() +{ + return 0; +} diff --git a/Tests/RunCMake/add_subdirectory/RunCMakeTest.cmake b/Tests/RunCMake/add_subdirectory/RunCMakeTest.cmake index e9ba92f..951e03c 100644 --- a/Tests/RunCMake/add_subdirectory/RunCMakeTest.cmake +++ b/Tests/RunCMake/add_subdirectory/RunCMakeTest.cmake @@ -34,6 +34,26 @@ run_cmake(ExcludeFromAll) set(RunCMake_TEST_NO_CLEAN 1) set(RunCMake-check-file ExcludeFromAll/check.cmake) run_cmake_command(ExcludeFromAll-build ${CMAKE_COMMAND} --build . --config Debug) +if(RunCMake_GENERATOR STREQUAL "Ninja") + if(WIN32) + set(slash [[\]]) + else() + set(slash [[/]]) + endif() + set(RunCMake-check-file ExcludeFromAll/check-sub.cmake) + run_cmake_command(ExcludeFromAll-build-sub ${CMAKE_COMMAND} --build . --target "ExcludeFromAll${slash}all") +elseif(RunCMake_GENERATOR MATCHES "Make") + set(RunCMake-check-file ExcludeFromAll/check-sub.cmake) + set(RunCMake_TEST_COMMAND_WORKING_DIRECTORY ${RunCMake_BINARY_DIR}/ExcludeFromAll-build/ExcludeFromAll) + run_cmake_command(ExcludeFromAll-build-sub "${RunCMake_MAKE_PROGRAM}") +elseif(RunCMake_GENERATOR MATCHES "^Visual Studio [1-9][0-9]") + set(RunCMake-check-file ExcludeFromAll/check-sub.cmake) + run_cmake_command(ExcludeFromAll-build-sub ${CMAKE_COMMAND} --build ExcludeFromAll --config Debug) +elseif(RunCMake_GENERATOR STREQUAL "Xcode") + set(RunCMake-check-file ExcludeFromAll/check-sub.cmake) + set(RunCMake_TEST_COMMAND_WORKING_DIRECTORY ${RunCMake_BINARY_DIR}/ExcludeFromAll-build/ExcludeFromAll) + run_cmake_command(ExcludeFromAll-build-sub xcodebuild -configuration Debug) +endif() unset(RunCMake-check-file) unset(RunCMake_TEST_NO_CLEAN) unset(RunCMake_TEST_OPTIONS) -- cgit v0.12 From 62d45d91e83f537b19d9bfc7b1e8d909a0c5c322 Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 24 Sep 2019 14:24:55 -0400 Subject: Help: Add release note for EXCLUDE_FROM_ALL fix in 3.14.7 --- Help/release/3.14.rst | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Help/release/3.14.rst b/Help/release/3.14.rst index 229d8dc..8a9738c 100644 --- a/Help/release/3.14.rst +++ b/Help/release/3.14.rst @@ -428,3 +428,11 @@ Changes made since CMake 3.14.0 include the following. policy :policy:`CMP0088` ``NEW`` behavior accidentally interpreted a relative path to the ``.y`` input as relative to the build tree directory instead of the source tree directory. This has been fixed. + +3.14.7 +------ + +* In CMake 3.14.0 through 3.14.6, the :prop_dir:`EXCLUDE_FROM_ALL` + directory property was regressed from pre-3.14 behavior and caused + targets within the directory to be excluded even from its own "all". + This has been fixed. -- cgit v0.12 From 1fe450159278fd30138ef5133daf26f931537de4 Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 24 Sep 2019 14:31:00 -0400 Subject: Help: Add release note for EXCLUDE_FROM_ALL fix in 3.15.4 --- Help/release/3.15.rst | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Help/release/3.15.rst b/Help/release/3.15.rst index 48f3aa4..148c2d2 100644 --- a/Help/release/3.15.rst +++ b/Help/release/3.15.rst @@ -376,3 +376,11 @@ Changes made since CMake 3.15.0 include the following. * ``CrayPrgEnv`` compiler wrapper support has been updated for the 19.06 release of the Cray Programming Environment for which the default linking mode on XC Cray systems is now dynamic instead of static. + +3.15.4 +------ + +* In CMake 3.15.0 through 3.15.3, the :prop_dir:`EXCLUDE_FROM_ALL` + directory property was regressed from pre-3.14 behavior and caused + targets within the directory to be excluded even from its own "all". + This has been fixed. -- cgit v0.12 From 013d7dd48420b7040355066724ede9eb7050c94a Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 24 Sep 2019 14:31:23 -0400 Subject: Help: Mention 3.14.7 EXCLUDE_FROM_ALL fix in 3.15.4 release note --- Help/release/3.15.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/Help/release/3.15.rst b/Help/release/3.15.rst index 148c2d2..957e6e9 100644 --- a/Help/release/3.15.rst +++ b/Help/release/3.15.rst @@ -384,3 +384,4 @@ Changes made since CMake 3.15.0 include the following. directory property was regressed from pre-3.14 behavior and caused targets within the directory to be excluded even from its own "all". This has been fixed. + The bug also existed in 3.14.0 through 3.14.6 and is fixed in 3.14.7. -- cgit v0.12