mirror of
https://github.com/Kitware/CMake.git
synced 2026-05-03 12:49:50 -05:00
05ae95c864
Create a brand new implementation of `cmTarget::GetMappedConfig` which prioritized a target's `IMPORTED_CONFIGURATIONS` as the 'source of truth' for what configurations are available. In particular, this means that configuration selection when `IMPORTED_CONFIGURATIONS` is set does not depend on the library type in any manner. The fallback logic also uses a more consistent 'usability' criteria that should result in more consistent configuration selection, particularly for `INTERFACE` targets. The previous implementation is retained as a separate method for users requesting the OLD behavior. Fixes: #27022
34 lines
1.3 KiB
CMake
34 lines
1.3 KiB
CMake
# Under CMP0200 OLD, CMake fails to select a valid configuration for an
|
|
# imported INTERFACE library with no location, and will (as an implementation
|
|
# artifact) select the last configuration in IMPORTED_CONFIGURATIONS.
|
|
|
|
# Under NEW, CMake should select a configuration which matches the current
|
|
# build type, if available in IMPORTED_CONFIGURATIONS.
|
|
function(do_match_config_test)
|
|
add_library(lib_match INTERFACE IMPORTED)
|
|
set_target_properties(lib_match PROPERTIES
|
|
IMPORTED_CONFIGURATIONS "RELEASE;DEBUG"
|
|
INTERFACE_COMPILE_DEFINITIONS
|
|
"$<$<CONFIG:debug>:DEBUG>;$<$<CONFIG:release>:RELEASE>"
|
|
)
|
|
|
|
add_executable(exe_match configtest.c)
|
|
target_compile_definitions(exe_match PRIVATE ${ARGN})
|
|
target_link_libraries(exe_match PRIVATE lib_match)
|
|
endfunction()
|
|
|
|
# Under NEW, CMake should select the first of IMPORTED_CONFIGURATIONS if no
|
|
# mapping exists and no configuration matching the current build type exists.
|
|
function(do_first_config_test)
|
|
add_library(lib_first INTERFACE IMPORTED)
|
|
set_target_properties(lib_first PROPERTIES
|
|
IMPORTED_CONFIGURATIONS "TEST;DEBUG"
|
|
INTERFACE_COMPILE_DEFINITIONS
|
|
"$<$<CONFIG:debug>:DEBUG>;$<$<CONFIG:test>:TEST>"
|
|
)
|
|
|
|
add_executable(exe_first configtest.c)
|
|
target_compile_definitions(exe_first PRIVATE ${ARGN})
|
|
target_link_libraries(exe_first PRIVATE lib_first)
|
|
endfunction()
|