Unity Build: target_sources(... $<CONFIG>/path_to_file.cpp) does not work
CMake version: 3.22.2
Some related issues: #22436 (closed) #20648 (closed)
Simply put, when I have $<CONFIG> as part of the filename, or file path, of the source file to include into a target, the $<CONFIG> text is not substituted with the current configuration, it is simply removed from the string.
As a work-around, I've used the same workaround as from the issues above:
get_property(IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
if(IS_MULTI_CONFIG)
foreach(cfg ${CMAKE_CONFIGURATION_TYPES})
cmake_path(SET PER_CFG_RC NORMALIZE "${CMAKE_CURRENT_BINARY_DIR}/${TARGETNAME}${cfg}.rc")
add_library(${TARGETNAME}_${cfg}_rc OBJECT ${PER_CFG_RC})
target_link_libraries(${TARGETNAME} PRIVATE $<$<CONFIG:${cfg}>:${TARGETNAME}_${cfg}_rc>)
endforeach()
else()
target_sources(${TARGETNAME} PRIVATE ${MAIN_RC})
endif()
Note that the bug doesn't appear to be influenced by the language. I have to use this same work-around for cpp files as well as rc files.
Edited by Brad King