From 1313c78a9caaa9f4ab1ed985b2132cf40f404e71 Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 21 Feb 2024 16:22:07 -0500 Subject: Tests: Update RunCMake.TargetObjects cmake_minimum_required version This was missed in commit 1edf138506 (Tests/RunCMake: Update cmake_minimum_required versions, 2023-02-06, v3.27.0-rc1~508^2~1). --- Tests/RunCMake/TargetObjects/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/RunCMake/TargetObjects/CMakeLists.txt b/Tests/RunCMake/TargetObjects/CMakeLists.txt index e9a0a3f..86f640d 100644 --- a/Tests/RunCMake/TargetObjects/CMakeLists.txt +++ b/Tests/RunCMake/TargetObjects/CMakeLists.txt @@ -1,3 +1,3 @@ -cmake_minimum_required(VERSION 3.3) +cmake_minimum_required(VERSION 3.5) project(${RunCMake_TEST} LANGUAGES NONE) include(${RunCMake_TEST}.cmake) -- cgit v0.12 From 5b8e9e068fc634459cfaeed90e20072ebaa01710 Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 21 Feb 2024 16:00:42 -0500 Subject: Restore support for TARGET_OBJECTS in link interfaces with unity builds This was broken by commit df08c37a42 (cmGlobalGenerator: Add unity/pch sources after computing compile features, 2024-02-02, v3.28.3~1^2~1^2), and 3.28.2's commit 76b5383123 (cmGlobalGenerator: add unity sources after computing target compile features, 2024-01-01, v3.28.2~17^2~1). The problem is very similar to that fixed by commit 4e8f24e977 (PCH: Clear link interface cache when adding PCH object to it, 2022-01-24, v3.23.0-rc1~44^2~9). Generalize that fix. Fixes: #25696 --- Source/cmGeneratorTarget.h | 5 ++++- Source/cmGlobalGenerator.cxx | 4 ++++ Source/cmLocalGenerator.cxx | 5 ----- Tests/RunCMake/TargetObjects/RunCMakeTest.cmake | 8 ++++++++ Tests/RunCMake/TargetObjects/Unity.cmake | 13 +++++++++++++ Tests/RunCMake/TargetObjects/UnityMain.c | 7 +++++++ Tests/RunCMake/TargetObjects/UnityObj1.c | 4 ++++ Tests/RunCMake/TargetObjects/UnityObj2.c | 4 ++++ 8 files changed, 44 insertions(+), 6 deletions(-) create mode 100644 Tests/RunCMake/TargetObjects/Unity.cmake create mode 100644 Tests/RunCMake/TargetObjects/UnityMain.c create mode 100644 Tests/RunCMake/TargetObjects/UnityObj1.c create mode 100644 Tests/RunCMake/TargetObjects/UnityObj2.c diff --git a/Source/cmGeneratorTarget.h b/Source/cmGeneratorTarget.h index c13b2f6..736aab0 100644 --- a/Source/cmGeneratorTarget.h +++ b/Source/cmGeneratorTarget.h @@ -721,7 +721,10 @@ public: */ void ClearSourcesCache(); - // Do not use. This is only for a specific call site with a FIXME comment. + /** + * Clears cached evaluations of INTERFACE_LINK_LIBRARIES. + * They will be recomputed on demand. + */ void ClearLinkInterfaceCache(); void AddSource(const std::string& src, bool before = false); diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index d44863d..ba1938f 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -1897,9 +1897,13 @@ bool cmGlobalGenerator::AddAutomaticSources() // Clear the source list and classification cache (KindedSources) of all // targets so that it will be recomputed correctly by the generators later // now that the above transformations are done for all targets. + // Also clear the link interface cache to support $ + // in INTERFACE_LINK_LIBRARIES because the list of object files may have + // been changed by conversion to a unity build or addition of a PCH source. for (const auto& lg : this->LocalGenerators) { for (const auto& gt : lg->GetGeneratorTargets()) { gt->ClearSourcesCache(); + gt->ClearLinkInterfaceCache(); } } return true; diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 86c55f5..2c3595b 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -2831,15 +2831,10 @@ void cmLocalGenerator::AddPchDependencies(cmGeneratorTarget* target) cm::nullopt, true); } else if (reuseTarget->GetType() == cmStateEnums::OBJECT_LIBRARY) { - // FIXME: This can propagate more than one level, unlike - // the rest of the object files in an object library. - // Find another way to do this. target->Target->AppendProperty( "INTERFACE_LINK_LIBRARIES", cmStrCat("$<$:$>")); - // We updated the link interface, so ensure it is recomputed. - target->ClearLinkInterfaceCache(); } } } else { diff --git a/Tests/RunCMake/TargetObjects/RunCMakeTest.cmake b/Tests/RunCMake/TargetObjects/RunCMakeTest.cmake index d2b3032..9756255 100644 --- a/Tests/RunCMake/TargetObjects/RunCMakeTest.cmake +++ b/Tests/RunCMake/TargetObjects/RunCMakeTest.cmake @@ -6,3 +6,11 @@ run_cmake(NotObjlibTarget) if(RunCMake_GENERATOR STREQUAL "Xcode" AND "$ENV{CMAKE_OSX_ARCHITECTURES}" MATCHES "[;$]") run_cmake(XcodeVariableNoGenexExpansion) endif() + +function(run_cmake_and_build case) + set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${case}-build) + run_cmake(${case}) + set(RunCMake_TEST_NO_CLEAN 1) + run_cmake_command(${case}-build ${CMAKE_COMMAND} --build .) +endfunction() +run_cmake_and_build(Unity) diff --git a/Tests/RunCMake/TargetObjects/Unity.cmake b/Tests/RunCMake/TargetObjects/Unity.cmake new file mode 100644 index 0000000..9c8e5c9 --- /dev/null +++ b/Tests/RunCMake/TargetObjects/Unity.cmake @@ -0,0 +1,13 @@ +enable_language(C) + +# Test transforming the set of object files provided by an object library. +set(CMAKE_UNITY_BUILD 1) + +add_library(UnityObj1 OBJECT UnityObj1.c) +add_library(UnityObj2 OBJECT UnityObj2.c) + +add_library(UnityObj2Iface INTERFACE) +target_link_libraries(UnityObj2Iface INTERFACE $) + +add_executable(UnityMain UnityMain.c) +target_link_libraries(UnityMain PRIVATE UnityObj1 UnityObj2Iface) diff --git a/Tests/RunCMake/TargetObjects/UnityMain.c b/Tests/RunCMake/TargetObjects/UnityMain.c new file mode 100644 index 0000000..9d52ef8 --- /dev/null +++ b/Tests/RunCMake/TargetObjects/UnityMain.c @@ -0,0 +1,7 @@ +extern int UnityObj1(void); +extern int UnityObj2(void); + +int main(void) +{ + return UnityObj1() + UnityObj2(); +} diff --git a/Tests/RunCMake/TargetObjects/UnityObj1.c b/Tests/RunCMake/TargetObjects/UnityObj1.c new file mode 100644 index 0000000..ed19d14 --- /dev/null +++ b/Tests/RunCMake/TargetObjects/UnityObj1.c @@ -0,0 +1,4 @@ +int UnityObj1(void) +{ + return 0; +} diff --git a/Tests/RunCMake/TargetObjects/UnityObj2.c b/Tests/RunCMake/TargetObjects/UnityObj2.c new file mode 100644 index 0000000..1cc350c --- /dev/null +++ b/Tests/RunCMake/TargetObjects/UnityObj2.c @@ -0,0 +1,4 @@ +int UnityObj2(void) +{ + return 0; +} -- cgit v0.12