From 5a95b5e091fa2a2d0ad869a80c37eaa980917853 Mon Sep 17 00:00:00 2001 From: Brad King Date: Mon, 30 Mar 2020 11:08:10 -0400 Subject: target_link_libraries: Fix regression in case of $ genex Since commit b8626261e9 (Precompile headers: Add methods to generate PCH sources, 2019-07-13, v3.16.0-rc1~182^2~4) we look up source files for a target using an upper-case configuration even though an original-case name is sufficient. Since commit 36ded610af (PCH: Generate sources during Compute step, 2019-10-05, v3.16.0-rc1~2^2) the source file lookup is the first time we compute many on-demand structures that depend on the configuration name. This caused the `$` generator expression to evaluate to the upper-case configuration name in some cases where we used original-case before. Fix this by switching the source file lookup to the original-case config name. Add a test covering the symptom that led to the discovery of this problem. Fixes: #20517 --- Source/cmLocalGenerator.cxx | 7 ++----- Tests/RunCMake/target_link_libraries/ConfigCase-result.txt | 1 + Tests/RunCMake/target_link_libraries/ConfigCase-stderr.txt | 13 +++++++++++++ Tests/RunCMake/target_link_libraries/ConfigCase.cmake | 6 ++++++ Tests/RunCMake/target_link_libraries/RunCMakeTest.cmake | 8 ++++++++ 5 files changed, 30 insertions(+), 5 deletions(-) create mode 100644 Tests/RunCMake/target_link_libraries/ConfigCase-result.txt create mode 100644 Tests/RunCMake/target_link_libraries/ConfigCase-stderr.txt create mode 100644 Tests/RunCMake/target_link_libraries/ConfigCase.cmake diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index ffd46d4..af92e1b 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -2306,11 +2306,10 @@ void cmLocalGenerator::AddPchDependencies(cmGeneratorTarget* target) if (!this->GetGlobalGenerator()->IsMultiConfig()) { config = this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE"); } - const std::string buildType = cmSystemTools::UpperCase(config); // FIXME: Refactor collection of sources to not evaluate object libraries. std::vector sources; - target->GetSourceFiles(sources, buildType); + target->GetSourceFiles(sources, config); for (const std::string& lang : { "C", "CXX", "OBJC", "OBJCXX" }) { auto langSources = @@ -2481,15 +2480,13 @@ void cmLocalGenerator::AddUnityBuild(cmGeneratorTarget* target) config = this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE"); } - const std::string buildType = cmSystemTools::UpperCase(config); - std::string filename_base = cmStrCat(this->GetCurrentBinaryDirectory(), "/CMakeFiles/", target->GetName(), ".dir/Unity/"); // FIXME: Refactor collection of sources to not evaluate object libraries. std::vector sources; - target->GetSourceFiles(sources, buildType); + target->GetSourceFiles(sources, config); auto batchSizeString = target->GetProperty("UNITY_BUILD_BATCH_SIZE"); const size_t unityBatchSize = diff --git a/Tests/RunCMake/target_link_libraries/ConfigCase-result.txt b/Tests/RunCMake/target_link_libraries/ConfigCase-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/target_link_libraries/ConfigCase-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/target_link_libraries/ConfigCase-stderr.txt b/Tests/RunCMake/target_link_libraries/ConfigCase-stderr.txt new file mode 100644 index 0000000..953c972 --- /dev/null +++ b/Tests/RunCMake/target_link_libraries/ConfigCase-stderr.txt @@ -0,0 +1,13 @@ +^CMake Error at ConfigCase.cmake:[0-9]+ \(add_library\): + Target "impl" links to target "config::impl-Debug" but the target was not + found. Perhaps a find_package\(\) call is missing for an IMPORTED target, or + an ALIAS target is missing\? +Call Stack \(most recent call first\): + CMakeLists.txt:[0-9]+ \(include\) ++ +CMake Error at ConfigCase.cmake:[0-9]+ \(add_library\): + Target "impl" links to target "config::iface-Debug" but the target was not + found. Perhaps a find_package\(\) call is missing for an IMPORTED target, or + an ALIAS target is missing\? +Call Stack \(most recent call first\): + CMakeLists.txt:[0-9]+ \(include\) diff --git a/Tests/RunCMake/target_link_libraries/ConfigCase.cmake b/Tests/RunCMake/target_link_libraries/ConfigCase.cmake new file mode 100644 index 0000000..fc39478 --- /dev/null +++ b/Tests/RunCMake/target_link_libraries/ConfigCase.cmake @@ -0,0 +1,6 @@ +cmake_policy(VERSION 3.15) +enable_language(C) +add_library(iface INTERFACE) +target_link_libraries(iface INTERFACE "config::iface-$") +add_library(impl empty.c) +target_link_libraries(impl PRIVATE "config::impl-$" iface) diff --git a/Tests/RunCMake/target_link_libraries/RunCMakeTest.cmake b/Tests/RunCMake/target_link_libraries/RunCMakeTest.cmake index 0152d4c..8eed986 100644 --- a/Tests/RunCMake/target_link_libraries/RunCMakeTest.cmake +++ b/Tests/RunCMake/target_link_libraries/RunCMakeTest.cmake @@ -1,5 +1,13 @@ include(RunCMake) +if(RunCMake_GENERATOR_IS_MULTI_CONFIG) + set(RunCMake_TEST_OPTIONS -DCMAKE_CONFIGURATION_TYPES=Debug) +else() + set(RunCMake_TEST_OPTIONS -DCMAKE_BUILD_TYPE=Debug) +endif() +run_cmake(ConfigCase) +unset(RunCMake_TEST_OPTIONS) + run_cmake(CMP0023-WARN) run_cmake(CMP0023-NEW) run_cmake(CMP0023-WARN-2) -- cgit v0.12 From 3f976bf201983b399dacbcde51ef10b0a6de9b06 Mon Sep 17 00:00:00 2001 From: Brad King Date: Mon, 30 Mar 2020 11:08:10 -0400 Subject: target_link_libraries: Fix regression in case of $ genex Since commit b8626261e9 (Precompile headers: Add methods to generate PCH sources, 2019-07-13, v3.16.0-rc1~182^2~4) we look up source files for a target using an upper-case configuration even though an original-case name is sufficient. Since commit 36ded610af (PCH: Generate sources during Compute step, 2019-10-05, v3.16.0-rc1~2^2) the source file lookup is the first time we compute many on-demand structures that depend on the configuration name. This caused the `$` generator expression to evaluate to the upper-case configuration name in some cases where we used original-case before. Fix this by switching the source file lookup to the original-case config name. Add a test covering the symptom that led to the discovery of this problem. Fixes: #20517 --- Source/cmLocalGenerator.cxx | 8 ++------ Tests/RunCMake/target_link_libraries/ConfigCase-result.txt | 1 + Tests/RunCMake/target_link_libraries/ConfigCase-stderr.txt | 13 +++++++++++++ Tests/RunCMake/target_link_libraries/ConfigCase.cmake | 6 ++++++ Tests/RunCMake/target_link_libraries/RunCMakeTest.cmake | 8 ++++++++ 5 files changed, 30 insertions(+), 6 deletions(-) create mode 100644 Tests/RunCMake/target_link_libraries/ConfigCase-result.txt create mode 100644 Tests/RunCMake/target_link_libraries/ConfigCase-stderr.txt create mode 100644 Tests/RunCMake/target_link_libraries/ConfigCase.cmake diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index cf6802d..00ad62e 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -2429,11 +2429,9 @@ void cmLocalGenerator::AddPchDependencies(cmGeneratorTarget* target) } for (std::string const& config : configsList) { - const std::string buildType = cmSystemTools::UpperCase(config); - // FIXME: Refactor collection of sources to not evaluate object libraries. std::vector sources; - target->GetSourceFiles(sources, buildType); + target->GetSourceFiles(sources, config); for (const std::string& lang : { "C", "CXX", "OBJC", "OBJCXX" }) { auto langSources = std::count_if( @@ -2602,15 +2600,13 @@ void cmLocalGenerator::AddUnityBuild(cmGeneratorTarget* target) config = this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE"); } - const std::string buildType = cmSystemTools::UpperCase(config); - std::string filename_base = cmStrCat(this->GetCurrentBinaryDirectory(), "/CMakeFiles/", target->GetName(), ".dir/Unity/"); // FIXME: Refactor collection of sources to not evaluate object libraries. std::vector sources; - target->GetSourceFiles(sources, buildType); + target->GetSourceFiles(sources, config); auto batchSizeString = target->GetProperty("UNITY_BUILD_BATCH_SIZE"); const size_t unityBatchSize = diff --git a/Tests/RunCMake/target_link_libraries/ConfigCase-result.txt b/Tests/RunCMake/target_link_libraries/ConfigCase-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/target_link_libraries/ConfigCase-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/target_link_libraries/ConfigCase-stderr.txt b/Tests/RunCMake/target_link_libraries/ConfigCase-stderr.txt new file mode 100644 index 0000000..953c972 --- /dev/null +++ b/Tests/RunCMake/target_link_libraries/ConfigCase-stderr.txt @@ -0,0 +1,13 @@ +^CMake Error at ConfigCase.cmake:[0-9]+ \(add_library\): + Target "impl" links to target "config::impl-Debug" but the target was not + found. Perhaps a find_package\(\) call is missing for an IMPORTED target, or + an ALIAS target is missing\? +Call Stack \(most recent call first\): + CMakeLists.txt:[0-9]+ \(include\) ++ +CMake Error at ConfigCase.cmake:[0-9]+ \(add_library\): + Target "impl" links to target "config::iface-Debug" but the target was not + found. Perhaps a find_package\(\) call is missing for an IMPORTED target, or + an ALIAS target is missing\? +Call Stack \(most recent call first\): + CMakeLists.txt:[0-9]+ \(include\) diff --git a/Tests/RunCMake/target_link_libraries/ConfigCase.cmake b/Tests/RunCMake/target_link_libraries/ConfigCase.cmake new file mode 100644 index 0000000..fc39478 --- /dev/null +++ b/Tests/RunCMake/target_link_libraries/ConfigCase.cmake @@ -0,0 +1,6 @@ +cmake_policy(VERSION 3.15) +enable_language(C) +add_library(iface INTERFACE) +target_link_libraries(iface INTERFACE "config::iface-$") +add_library(impl empty.c) +target_link_libraries(impl PRIVATE "config::impl-$" iface) diff --git a/Tests/RunCMake/target_link_libraries/RunCMakeTest.cmake b/Tests/RunCMake/target_link_libraries/RunCMakeTest.cmake index 0152d4c..8eed986 100644 --- a/Tests/RunCMake/target_link_libraries/RunCMakeTest.cmake +++ b/Tests/RunCMake/target_link_libraries/RunCMakeTest.cmake @@ -1,5 +1,13 @@ include(RunCMake) +if(RunCMake_GENERATOR_IS_MULTI_CONFIG) + set(RunCMake_TEST_OPTIONS -DCMAKE_CONFIGURATION_TYPES=Debug) +else() + set(RunCMake_TEST_OPTIONS -DCMAKE_BUILD_TYPE=Debug) +endif() +run_cmake(ConfigCase) +unset(RunCMake_TEST_OPTIONS) + run_cmake(CMP0023-WARN) run_cmake(CMP0023-NEW) run_cmake(CMP0023-WARN-2) -- cgit v0.12