Install(IMPORTED_RUNTIME_ARTIFACTS) and related functionality should optionally recurse through INTERFACE targets
INTERFACE
targets are often used as an indirection and grouping mechanism to bundle up other targets:
# Top level file
add_library(INTERFACE IMPORTED MainLib)
# We'd actually use a glob here...
include(MainLibDeps*.cmake)
# MainLibDepsRelease.cmake
add_library(INTERFACE IMPORTED MainLibDepsRelease)
set_target_properties(MainLibDepsRelease PROPERTY INTERFACE_LINK_LIBRARIES actual_lib_release $<SomeGeneratorExpression>...)
set_target_properties(MainLibDepsRelease PROPERTY IMPORTED_LOCATION_RELEASE dll_location ...)
# ... etc ...
set_target_properties(MainLib PROPERTY INTERFACE_LINK_LIBRARIES $<$<CONFIG:Release>:MainLibDepsRelease> APPEND)
# MainLibDepsDebug.cmake
add_library(INTERFACE IMPORTED MainLibDepsDebug)
# ... etc...
set_target_properties(MainLibDepsDebug PROPERTY INTERFACE_LINK_LIBRARIES $<$<CONFIG:Debug>:MainLibDepsDebug> APPEND)
This seems like a legitimate enough usecase for these kinds of targets.
Unfortunately, DLL-related functionality such as install(IMPORTED_RUNTIME_ARTIFACTS tgt)
, $<TARGET_RUNTIME_DLLS:tgt>
currently only operate on the provided target tgt
and fail if a target is provided that doesn't meet certain constraints - IMPORTED_RUNTIME_ARTIFACTS
requires that the target is a library, executable or module; TARGET_RUNTIME_DLLs
require an IMPORTED_LOCATION
, etc.
One possible solution to this problem would be to extend these methods to support a RECURSE
flag or generator expression variant that will best-effort recurse through the provided target's dependencies and perform the same basic operation as exists at the moment. The pervasive use of generator expressions in INTERFACE_LINK_LIBRARIES
properties means that a practical workaround doesn't exist.
Conan currently uses this approach to indirection in it's CMakeDeps generator, meaning that all of CMake's DLL-related functions fail when used with the targets it produces (see https://github.com/conan-io/conan/issues/12654#issuecomment-1573095138).