瀏覽代碼

Ninja,Makefile: Fix subdir "all" with nested EXCLUDE_FROM_ALL subdir

The "all" target defined for a subdirectory (e.g. `cd sub; make` or
`ninja sub/all`) should not include the "all" targets from nested
subdirectories (e.g. `sub/sub`) that are marked as `EXCLUDE_FROM_ALL`.
Fix this and add a test case.

Issue: #19753
Co-Author: Sebastian Holtermann <[email protected]>
Brad King 6 年之前
父節點
當前提交
0733a94f64

+ 3 - 0
Source/cmGlobalNinjaGenerator.cxx

@@ -1123,6 +1123,9 @@ void cmGlobalNinjaGenerator::WriteFolderTargets(std::ostream& os)
     // The directory-level rule should depend on the directory-level
     // rules of the subdirectories.
     for (cmStateSnapshot const& state : lg->GetStateSnapshot().GetChildren()) {
+      if (state.GetDirectory().GetPropertyAsBool("EXCLUDE_FROM_ALL")) {
+        continue;
+      }
       std::string const& currentBinaryDir =
         state.GetDirectory().GetCurrentBinary();
       folderTargets.push_back(

+ 3 - 0
Source/cmGlobalUnixMakefileGenerator3.cxx

@@ -429,6 +429,9 @@ void cmGlobalUnixMakefileGenerator3::WriteDirectoryRule2(
   // The directory-level rule should depend on the directory-level
   // rules of the subdirectories.
   for (cmStateSnapshot const& c : lg->GetStateSnapshot().GetChildren()) {
+    if (check_all && c.GetDirectory().GetPropertyAsBool("EXCLUDE_FROM_ALL")) {
+      continue;
+    }
     std::string subdir =
       cmStrCat(c.GetDirectory().GetCurrentBinary(), '/', pass);
     depends.push_back(std::move(subdir));

+ 1 - 0
Tests/RunCMake/add_subdirectory/ExcludeFromAll.cmake

@@ -11,4 +11,5 @@ set(foo_lib \"$<TARGET_FILE:foo>\")
 set(bar_lib \"$<TARGET_FILE:bar>\")
 set(zot_lib \"$<TARGET_FILE:zot>\")
 set(subinc_lib \"$<TARGET_FILE:subinc>\")
+set(subsub_lib \"$<TARGET_FILE:subsub>\")
 ")

+ 2 - 0
Tests/RunCMake/add_subdirectory/ExcludeFromAll/CMakeLists.txt

@@ -1,5 +1,7 @@
 project(ExcludeFromAllSub NONE)
 
+add_subdirectory(SubSub EXCLUDE_FROM_ALL)
+
 add_library(bar STATIC EXCLUDE_FROM_ALL bar.cpp)
 
 add_library(zot STATIC zot.cpp)

+ 1 - 0
Tests/RunCMake/add_subdirectory/ExcludeFromAll/SubSub/CMakeLists.txt

@@ -0,0 +1 @@
+add_library(subsub STATIC subsub.cpp)

+ 4 - 0
Tests/RunCMake/add_subdirectory/ExcludeFromAll/SubSub/subsub.cpp

@@ -0,0 +1,4 @@
+int subsub()
+{
+  return 0;
+}

+ 1 - 0
Tests/RunCMake/add_subdirectory/ExcludeFromAll/check-sub.cmake

@@ -18,6 +18,7 @@ if(EXISTS ${RunCMake_TEST_BINARY_DIR}/check-debug.cmake)
   foreach(file
       "${main_exe}"
       "${bar_lib}"
+      "${subsub_lib}"
       )
     if(EXISTS "${file}")
       set(RunCMake_TEST_FAILED

+ 1 - 0
Tests/RunCMake/add_subdirectory/ExcludeFromAll/check.cmake

@@ -21,6 +21,7 @@ if(EXISTS ${RunCMake_TEST_BINARY_DIR}/check-debug.cmake)
   foreach(file
       "${zot_lib}"
       "${bar_lib}"
+      "${subsub_lib}"
       )
     if(EXISTS "${file}")
       set(RunCMake_TEST_FAILED