فهرست منبع

Genex: Fix CONFIG on imported target with no explicit mapping

When evaluating the `$<CONFIG>` 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
Luis Caro Campos 2 سال پیش
والد
کامیت
e455265d72

+ 8 - 0
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";
+            }
+          }
         }
       }
     }

+ 7 - 0
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 $<$<CONFIG:Release>:FOOBAR=1>)
+
 add_custom_target(check-part3 ALL
   COMMAND ${msys2_no_conv} ${CMAKE_COMMAND}
     -Dtest_version_greater_1=$<VERSION_GREATER:1.0,1.1.1>
@@ -211,6 +217,7 @@ add_custom_target(check-part3 ALL
     -Dconfig=$<CONFIGURATION>
     -Dtest_imported_includes=$<TARGET_PROPERTY:imported4,INCLUDE_DIRECTORIES>
     -Dtest_imported_fallback=$<STREQUAL:$<TARGET_FILE_NAME:importedFallback>,fallback_loc>
+    -Dtest_imported_fallback_genex=$<STREQUAL:$<TARGET_PROPERTY:importedFallback_genex,INTERFACE_COMPILE_DEFINITIONS>,FOOBAR=1>
     -Dtest_alias_file_exe=$<STREQUAL:$<TARGET_FILE:Alias::SomeExe>,$<TARGET_FILE:someexe>>
     -Dtest_alias_file_lib=$<STREQUAL:$<TARGET_FILE:Alias::SomeLib>,$<TARGET_FILE:empty1>>
     -Dtest_alias_target_name=$<STREQUAL:$<TARGET_PROPERTY:Alias::SomeLib,NAME>,$<TARGET_PROPERTY:empty1,NAME>>

+ 1 - 0
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")