瀏覽代碼

Merge topic 'nmc-target-objects' into release-3.21

cb777dd81e Ninja Multi-Config: Restore TARGET_OBJECTS support in cross-configs
83c8272280 cmGeneratorExpressionNode: Factor out local variable for global generator

Acked-by: Kitware Robot <[email protected]>
Merge-request: !6371
Brad King 4 年之前
父節點
當前提交
e06c60f7e9

+ 5 - 4
Source/cmGeneratorExpressionNode.cxx

@@ -1635,10 +1635,11 @@ static const struct TargetObjectsNode : public cmGeneratorExpressionNode
       reportError(context, content->GetOriginalExpression(), e.str());
       return std::string();
     }
-    if (!context->EvaluateForBuildsystem) {
-      cmGlobalGenerator* gg = context->LG->GetGlobalGenerator();
+    cmGlobalGenerator* gg = context->LG->GetGlobalGenerator();
+    {
       std::string reason;
-      if (!gg->HasKnownObjectFileLocation(&reason)) {
+      if (!context->EvaluateForBuildsystem &&
+          !gg->HasKnownObjectFileLocation(&reason)) {
         std::ostringstream e;
         e << "The evaluation of the TARGET_OBJECTS generator expression "
              "is only suitable for consumption by CMake (limited"
@@ -1664,7 +1665,7 @@ static const struct TargetObjectsNode : public cmGeneratorExpressionNode
       gt->GetTargetObjectNames(context->Config, objects);
 
       std::string obj_dir;
-      if (context->EvaluateForBuildsystem) {
+      if (context->EvaluateForBuildsystem && !gg->SupportsCrossConfigs()) {
         // Use object file directory with buildsystem placeholder.
         obj_dir = gt->ObjectDirectory;
         context->HadContextSensitiveCondition =

+ 2 - 0
Tests/RunCMake/NinjaMultiConfig/RunCMakeTest.cmake

@@ -100,6 +100,8 @@ run_ninja(Simple release-file build-Release.ninja ${simpleexe_Release})
 run_cmake_build(Simple all-configs Release simplestatic:all)
 run_ninja(Simple default-build-file build.ninja simpleexe)
 run_cmake_build(Simple all-clean Release clean:all)
+run_ninja(Simple debug-in-release-graph-target build-Release.ninja simpleexe2:Debug)
+run_cmake_build(Simple all-clean Release clean:all)
 run_cmake_build(Simple debug-subdir Debug SimpleSubdir/all)
 run_ninja(Simple release-in-minsizerel-graph-subdir build-MinSizeRel.ninja SimpleSubdir/all:Release)
 run_cmake_build(Simple all-subdir Release SimpleSubdir/all:all)

+ 37 - 0
Tests/RunCMake/NinjaMultiConfig/Simple-debug-in-release-graph-target-ninja-check.cmake

@@ -0,0 +1,37 @@
+check_files("${RunCMake_TEST_BINARY_DIR}"
+  INCLUDE
+    ${GENERATED_FILES}
+
+    ${TARGET_FILE_simpleexe2_Debug}
+    ${TARGET_OBJECT_FILES_simpleexe2_Debug}
+
+    ${TARGET_FILE_simpleshared_Debug}
+    ${TARGET_LINKER_FILE_simpleshared_Debug}
+    ${TARGET_OBJECT_FILES_simpleshared_Debug}
+
+    ${TARGET_OBJECT_FILES_simpleobj_Debug}
+
+  EXCLUDE
+    ${TARGET_FILE_simpleexe_Debug}
+
+    ${TARGET_OBJECT_FILES_simpleexe_Debug}
+    ${TARGET_OBJECT_FILES_simplestatic_Debug}
+
+    ${TARGET_OBJECT_FILES_simpleexe_Release}
+    ${TARGET_OBJECT_FILES_simpleexe2_Release}
+    ${TARGET_OBJECT_FILES_simpleshared_Release}
+    ${TARGET_OBJECT_FILES_simplestatic_Release}
+    ${TARGET_OBJECT_FILES_simpleobj_Release}
+
+    ${TARGET_OBJECT_FILES_simpleexe_MinSizeRel}
+    ${TARGET_OBJECT_FILES_simpleexe2_MinSizeRel}
+    ${TARGET_OBJECT_FILES_simpleshared_MinSizeRel}
+    ${TARGET_OBJECT_FILES_simplestatic_MinSizeRel}
+    ${TARGET_OBJECT_FILES_simpleobj_MinSizeRel}
+
+    ${TARGET_OBJECT_FILES_simpleexe_RelWithDebInfo}
+    ${TARGET_OBJECT_FILES_simpleexe2_RelWithDebInfo}
+    ${TARGET_OBJECT_FILES_simpleshared_RelWithDebInfo}
+    ${TARGET_OBJECT_FILES_simplestatic_RelWithDebInfo}
+    ${TARGET_OBJECT_FILES_simpleobj_RelWithDebInfo}
+  )

+ 1 - 1
Tests/RunCMake/NinjaMultiConfig/Simple.cmake

@@ -10,6 +10,6 @@ add_subdirectory(SimpleSubdir)
 add_library(simplestatic STATIC simplelib.c)
 
 include(${CMAKE_CURRENT_LIST_DIR}/Common.cmake)
-generate_output_files(simpleexe simpleshared simplestatic simpleobj)
+generate_output_files(simpleexe simpleexe2 simpleshared simplestatic simpleobj)
 
 file(APPEND "${CMAKE_BINARY_DIR}/target_files.cmake" "set(GENERATED_FILES [==[${CMAKE_BINARY_DIR}/empty.cmake]==])\n")

+ 7 - 2
Tests/RunCMake/NinjaMultiConfig/SimpleSubdir/CMakeLists.txt

@@ -1,4 +1,9 @@
-add_library(simpleobj OBJECT ../empty.c)
-add_executable(simpleexe ../main.c $<TARGET_OBJECTS:simpleobj>)
+add_library(simpleobj OBJECT ../empty.c "$<$<CONFIG:Debug>:../empty_dbg.c>" "$<$<CONFIG:Release>:../empty_rel.c>")
 add_library(simpleshared SHARED ../simplelib.c)
+
+add_executable(simpleexe ../main.c $<TARGET_OBJECTS:simpleobj>)
 target_link_libraries(simpleexe PRIVATE simpleshared)
+
+add_executable(simpleexe2 ../main.c)
+target_link_libraries(simpleexe2 PRIVATE simpleshared $<TARGET_OBJECTS:simpleobj>)
+set_property(TARGET simpleexe2 PROPERTY EXCLUDE_FROM_ALL 1)

+ 0 - 0
Tests/RunCMake/NinjaMultiConfig/empty_dbg.c


+ 0 - 0
Tests/RunCMake/NinjaMultiConfig/empty_rel.c


+ 2 - 14
Tests/RunCMake/ObjectLibrary/OwnSources-stderr.txt

@@ -1,19 +1,7 @@
-^CMake Error at OwnSources.cmake:[0-9]+ \(add_library\):
+^(CMake Error at OwnSources.cmake:[0-9]+ \(add_library\):
   The SOURCES of "A" use a generator expression that depends on the SOURCES
   themselves.
 Call Stack \(most recent call first\):
   CMakeLists.txt:[0-9]+ \(include\)
-+
-CMake Error at OwnSources.cmake:[0-9]+ \(add_library\):
-  The SOURCES of "A" use a generator expression that depends on the SOURCES
-  themselves.
-Call Stack \(most recent call first\):
-  CMakeLists.txt:[0-9]+ \(include\)
-+
-CMake Error at OwnSources.cmake:[0-9]+ \(add_library\):
-  The SOURCES of "A" use a generator expression that depends on the SOURCES
-  themselves.
-Call Stack \(most recent call first\):
-  CMakeLists.txt:[0-9]+ \(include\)
-+
++)+
 CMake Generate step failed\.  Build files cannot be regenerated correctly\.$