From cb777dd81e71746fcd324dc157d1b41f3ae3ce24 Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 20 Jul 2021 14:51:06 -0400 Subject: Ninja Multi-Config: Restore TARGET_OBJECTS support in cross-configs Since commit 2ae72ef74b (Xcode: Enable multi-arch TARGET_OBJECTS genex in [INTERFACE_]LINK_LIBRARIES, 2021-05-26, v3.21.0-rc1~126^2) the TARGET_OBJECTS genex, when referenced for linking, is now evaluated with EvaluateForBuildsystem enabled. This causes the object file paths to be computed with a buildsystem-specific placeholder for the configuration. This is normally fine because the placeholder will be evaluated by the native buildsystem tool using the proper configuration. However, the Ninja Multi-Config generator's `${CONFIGURATION}` placeholder may not have the correct value for cross-config object files. Switch back to using the per-config location of each object file for this generator. Fixes: #22436 --- Source/cmGeneratorExpressionNode.cxx | 2 +- Tests/RunCMake/NinjaMultiConfig/RunCMakeTest.cmake | 2 ++ ...debug-in-release-graph-target-ninja-check.cmake | 37 ++++++++++++++++++++++ Tests/RunCMake/NinjaMultiConfig/Simple.cmake | 2 +- .../NinjaMultiConfig/SimpleSubdir/CMakeLists.txt | 9 ++++-- Tests/RunCMake/NinjaMultiConfig/empty_dbg.c | 0 Tests/RunCMake/NinjaMultiConfig/empty_rel.c | 0 Tests/RunCMake/ObjectLibrary/OwnSources-stderr.txt | 16 ++-------- 8 files changed, 50 insertions(+), 18 deletions(-) create mode 100644 Tests/RunCMake/NinjaMultiConfig/Simple-debug-in-release-graph-target-ninja-check.cmake create mode 100644 Tests/RunCMake/NinjaMultiConfig/empty_dbg.c create mode 100644 Tests/RunCMake/NinjaMultiConfig/empty_rel.c diff --git a/Source/cmGeneratorExpressionNode.cxx b/Source/cmGeneratorExpressionNode.cxx index 6ace49d..217ebe5 100644 --- a/Source/cmGeneratorExpressionNode.cxx +++ b/Source/cmGeneratorExpressionNode.cxx @@ -1665,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 = diff --git a/Tests/RunCMake/NinjaMultiConfig/RunCMakeTest.cmake b/Tests/RunCMake/NinjaMultiConfig/RunCMakeTest.cmake index 559c8f7..885ae13 100644 --- a/Tests/RunCMake/NinjaMultiConfig/RunCMakeTest.cmake +++ b/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) diff --git a/Tests/RunCMake/NinjaMultiConfig/Simple-debug-in-release-graph-target-ninja-check.cmake b/Tests/RunCMake/NinjaMultiConfig/Simple-debug-in-release-graph-target-ninja-check.cmake new file mode 100644 index 0000000..2f81bc0 --- /dev/null +++ b/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} + ) diff --git a/Tests/RunCMake/NinjaMultiConfig/Simple.cmake b/Tests/RunCMake/NinjaMultiConfig/Simple.cmake index 3f4ecbe..e2d393b 100644 --- a/Tests/RunCMake/NinjaMultiConfig/Simple.cmake +++ b/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") diff --git a/Tests/RunCMake/NinjaMultiConfig/SimpleSubdir/CMakeLists.txt b/Tests/RunCMake/NinjaMultiConfig/SimpleSubdir/CMakeLists.txt index 7e754a3..0ca6d02 100644 --- a/Tests/RunCMake/NinjaMultiConfig/SimpleSubdir/CMakeLists.txt +++ b/Tests/RunCMake/NinjaMultiConfig/SimpleSubdir/CMakeLists.txt @@ -1,4 +1,9 @@ -add_library(simpleobj OBJECT ../empty.c) -add_executable(simpleexe ../main.c $) +add_library(simpleobj OBJECT ../empty.c "$<$:../empty_dbg.c>" "$<$:../empty_rel.c>") add_library(simpleshared SHARED ../simplelib.c) + +add_executable(simpleexe ../main.c $) target_link_libraries(simpleexe PRIVATE simpleshared) + +add_executable(simpleexe2 ../main.c) +target_link_libraries(simpleexe2 PRIVATE simpleshared $) +set_property(TARGET simpleexe2 PROPERTY EXCLUDE_FROM_ALL 1) diff --git a/Tests/RunCMake/NinjaMultiConfig/empty_dbg.c b/Tests/RunCMake/NinjaMultiConfig/empty_dbg.c new file mode 100644 index 0000000..e69de29 diff --git a/Tests/RunCMake/NinjaMultiConfig/empty_rel.c b/Tests/RunCMake/NinjaMultiConfig/empty_rel.c new file mode 100644 index 0000000..e69de29 diff --git a/Tests/RunCMake/ObjectLibrary/OwnSources-stderr.txt b/Tests/RunCMake/ObjectLibrary/OwnSources-stderr.txt index 69230b6..5c27b8a 100644 --- a/Tests/RunCMake/ObjectLibrary/OwnSources-stderr.txt +++ b/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\.$ -- cgit v0.12