From e455265d72e42ccf47c27dc5068f664f9e84012d Mon Sep 17 00:00:00 2001 From: Luis Caro Campos <3535649+jcar87@users.noreply.github.com> Date: Thu, 15 Dec 2022 15:58:43 +0100 Subject: Genex: Fix CONFIG on imported target with no explicit mapping When evaluating the `$` genex on an imported target has the `IMPORTED_CONFIGURATIONS` property set, the current project has a config that does not match any of those, and no explicit configuration mappings are defined, fall back to the same configuration as `IMPORTED_LOCATION`. Fixes: #24222 --- Source/cmGeneratorExpressionNode.cxx | 8 ++++++++ Tests/GeneratorExpression/CMakeLists.txt | 7 +++++++ Tests/GeneratorExpression/check-part3.cmake | 1 + 3 files changed, 16 insertions(+) diff --git a/Source/cmGeneratorExpressionNode.cxx b/Source/cmGeneratorExpressionNode.cxx index c14012e..e33ebd7 100644 --- a/Source/cmGeneratorExpressionNode.cxx +++ b/Source/cmGeneratorExpressionNode.cxx @@ -1388,6 +1388,14 @@ static const struct ConfigurationTestNode : public cmGeneratorExpressionNode return "1"; } } + } else if (!suffix.empty()) { + // There is no explicit mapping for the tested config, so use + // the configuration of the imported location that was selected. + for (auto const& param : parameters) { + if (cmStrCat('_', cmSystemTools::UpperCase(param)) == suffix) { + return "1"; + } + } } } } diff --git a/Tests/GeneratorExpression/CMakeLists.txt b/Tests/GeneratorExpression/CMakeLists.txt index 6187966..3fb53d1 100644 --- a/Tests/GeneratorExpression/CMakeLists.txt +++ b/Tests/GeneratorExpression/CMakeLists.txt @@ -200,6 +200,12 @@ set_property(TARGET importedFallback PROPERTY IMPORTED_LOCATION fallback_loc) set_property(TARGET importedFallback PROPERTY MAP_IMPORTED_CONFIG_DEBUG "" DEBUG) set_property(TARGET importedFallback PROPERTY MAP_IMPORTED_CONFIG_RELEASE "") +add_library(importedFallback_genex STATIC IMPORTED) +set_property(TARGET importedFallback_genex PROPERTY IMPORTED_CONFIGURATIONS RELEASE) +set_property(TARGET importedFallback_genex PROPERTY IMPORTED_LOCATION_RELEASE release_loc) +set_property(TARGET importedFallback_genex PROPERTY + INTERFACE_COMPILE_DEFINITIONS $<$:FOOBAR=1>) + add_custom_target(check-part3 ALL COMMAND ${msys2_no_conv} ${CMAKE_COMMAND} -Dtest_version_greater_1=$ @@ -211,6 +217,7 @@ add_custom_target(check-part3 ALL -Dconfig=$ -Dtest_imported_includes=$ -Dtest_imported_fallback=$,fallback_loc> + -Dtest_imported_fallback_genex=$,FOOBAR=1> -Dtest_alias_file_exe=$,$> -Dtest_alias_file_lib=$,$> -Dtest_alias_target_name=$,$> diff --git a/Tests/GeneratorExpression/check-part3.cmake b/Tests/GeneratorExpression/check-part3.cmake index 5571c3d..e1b1f93 100644 --- a/Tests/GeneratorExpression/check-part3.cmake +++ b/Tests/GeneratorExpression/check-part3.cmake @@ -19,6 +19,7 @@ else() endif() check(test_imported_fallback "1") +check(test_imported_fallback_genex "1") check(test_alias_file_exe "1") check(test_alias_file_lib "1") -- cgit v0.12