diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 1dbb2ee2f0..9d1b286232 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -3234,10 +3234,14 @@ bool cmTarget::GetMappedConfig(std::string const& desiredConfig, cmValue& loc, bool const newResult = this->GetMappedConfigNew(desiredConfig, newLoc, newImp, newSuffix); + auto configFromSuffix = [](cm::string_view s) -> cm::string_view { + return s.empty() ? "(none)"_s : s.substr(1); + }; + if (!this->GetMappedConfigOld(desiredConfig, loc, imp, suffix)) { if (newResult) { // NEW policy found a configuration, OLD did not. - auto newConfig = cm::string_view{ newSuffix }.substr(1); + cm::string_view newConfig = configFromSuffix(newSuffix); std::string const err = cmStrCat( cmPolicies::GetPolicyWarning(cmPolicies::CMP0200), "\nConfiguration selection for imported target \"", this->GetName(), @@ -3249,7 +3253,7 @@ bool cmTarget::GetMappedConfig(std::string const& desiredConfig, cmValue& loc, return false; } - auto oldConfig = cm::string_view{ suffix }.substr(1); + cm::string_view oldConfig = configFromSuffix(suffix); if (!newResult) { // NEW policy did not find a configuration, OLD did. std::string const err = @@ -3260,7 +3264,7 @@ bool cmTarget::GetMappedConfig(std::string const& desiredConfig, cmValue& loc, this->GetMakefile()->IssueMessage(MessageType::AUTHOR_WARNING, err); } else if (suffix != newSuffix) { // OLD and NEW policies found different configurations. - auto newConfig = cm::string_view{ newSuffix }.substr(1); + cm::string_view newConfig = configFromSuffix(newSuffix); std::string const err = cmStrCat(cmPolicies::GetPolicyWarning(cmPolicies::CMP0200), "\nConfiguration selection for imported target \"", diff --git a/Tests/RunCMake/GeneratorExpression/CMP0200-WARN-stderr.txt b/Tests/RunCMake/GeneratorExpression/CMP0200-WARN-stderr.txt index aa0402ca95..52b8671360 100644 --- a/Tests/RunCMake/GeneratorExpression/CMP0200-WARN-stderr.txt +++ b/Tests/RunCMake/GeneratorExpression/CMP0200-WARN-stderr.txt @@ -4,7 +4,7 @@ CMake Warning \(dev\) in CMakeLists\.txt: policy details\. Use the cmake_policy command to set the policy and suppress this warning\. - Configuration selection for imported target "lib_test" selected + Configuration selection for imported target "lib_test1" selected configuration "CAT", but would select configuration "DOG" under the NEW policy\. diff --git a/Tests/RunCMake/GeneratorExpression/CMP0200-WARN.cmake b/Tests/RunCMake/GeneratorExpression/CMP0200-WARN.cmake index a91bc55875..92bfded965 100644 --- a/Tests/RunCMake/GeneratorExpression/CMP0200-WARN.cmake +++ b/Tests/RunCMake/GeneratorExpression/CMP0200-WARN.cmake @@ -2,10 +2,15 @@ project(test-CMP0200-WARN C) set(CMAKE_POLICY_WARNING_CMP0200 ON) -add_library(lib_test INTERFACE IMPORTED) -set_target_properties(lib_test PROPERTIES +add_library(lib_test1 INTERFACE IMPORTED) +set_target_properties(lib_test1 PROPERTIES IMPORTED_CONFIGURATIONS "DOG;CAT" ) -add_executable(exe_test configtest.c) -target_link_libraries(exe_test PRIVATE lib_test) +add_executable(exe_test1 configtest.c) +target_link_libraries(exe_test1 PRIVATE lib_test1) + +add_library(lib_test2 INTERFACE IMPORTED) + +add_executable(exe_test2 configtest.c) +target_link_libraries(exe_test2 PRIVATE lib_test2)