Genex: $<CONFIG:...> true for multiple MAP_IMPORTED_CONFIG_XXX entries
My project links an IMPORTED target utils that has an other library in its INTERFACE_LINK_LIBRARIES. Both libraries are available for the Debug and Release config, but the indirect other library has been linked with the old-style "optimized other.lib debug otherd.lib" notation.
CMake incorrectly links utils and otherd in the Release config, if I specify CMAKE_MAP_IMPORTED_CONFIG_XXX mappings. It works correctly without the mappings. Tested with CMake 3.23.2 and the Visual Studio 15 2017 generator.
I have attached a minimal CMakeLists.txt that demonstrates the issue.CMakeLists.txt
CMakeLists.txt
cmake_minimum_required(VERSION 3.13)
project(test CXX)
set(CMAKE_MAP_IMPORTED_CONFIG_RELWITHDEBINFO RelWithDebInfo Release MinSizeRel Debug "")
set(CMAKE_MAP_IMPORTED_CONFIG_RELEASE Release RelWithDebInfo MinSizeRel Debug "")
set(CMAKE_MAP_IMPORTED_CONFIG_MINSIZEREL MinSizeRel RelWithDebInfo Release Debug "")
set(CMAKE_MAP_IMPORTED_CONFIG_DEBUG Debug RelWithDebInfo MinSizeRel Release "")
#### some imported target
add_library(utils SHARED IMPORTED)
set_target_properties(utils PROPERTIES
INTERFACE_LINK_LIBRARIES "\$<\$<NOT:\$<CONFIG:DEBUG>>:other.lib>;\$<\$<CONFIG:DEBUG>:otherd.lib>"
)
set_property(TARGET utils APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
set_target_properties(utils PROPERTIES
IMPORTED_IMPLIB_RELEASE "utils.lib"
IMPORTED_LOCATION_RELEASE "utils.dll"
)
set_property(TARGET utils APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG)
set_target_properties(utils PROPERTIES
IMPORTED_IMPLIB_DEBUG "utilsd.lib"
IMPORTED_LOCATION_DEBUG "utilsd.dll"
)
####
set(PROJECT_SOURCES dummy.cpp)
# incorrectly links 'otherd.lib' and 'utils.lib' in Release config if CMAKE_MAP_IMPORTED_CONFIG* is used
add_library(${PROJECT_NAME} SHARED ${PROJECT_SOURCES})
target_link_libraries(${PROJECT_NAME} PUBLIC utils)
Edited by Brad King