I am trying to understand how to use the RUNTIME_DEPENDENCIES feature. Here I have a simple example that defines a SHARED library (dep), and then a library that uses it (mylib) and then an executable (myexe) that uses mylib. When installing myexe, the behavior I want to achieve is to only install myexe.exe and dep.dll, but in addition, my cmake script below installs dep.lib and dep.hpp. Removing dep from the install targets installs only myexe.exe. Can this be modified to achieve the desired behavior, or I have to rely on components?
add_library( dep SHARED dep.cpp )
set_target_properties( dep PROPERTIES PUBLIC_HEADER dep.hpp )
add_library( mylib mylib.cpp )
set_target_properties( mylib PROPERTIES PUBLIC_HEADER mylib.hpp )
target_link_libraries( mylib PRIVATE dep )
add_executable( myexe main.cpp )
target_link_libraries( myexe PRIVATE mylib )
install( TARGETS myexe dep RUNTIME_DEPENDENCIES
PRE_INCLUDE_REGEXES dep
PRE_EXCLUDE_REGEXES "api-ms-" "ext-ms-"
POST_EXCLUDE_REGEXES ".*system32/.*\\.dll"
DIRECTORIES "$<TARGET_FILE_DIR:dep>"
)
From the install(RUNTIME_DEPENDENCY_SET)documentation:
Targets built within the build tree will never be installed as runtime dependencies, nor will their own dependencies, unless the targets themselves are installed with install(TARGETS).
This is deliberate. CMake has its own procedure for installing targets that it builds. Installing them with install(RUNTIME_DEPENDENCY_SET) would bypass this procedure. This command is meant for bringing in libraries external to the CMake buildsystem (either imported targets or libraries linked the “dumb” way with a -l flag.)
I see. Our use case is more complex than the simple snippet above. Currently we rely on components to bring in imported runtime dependencies of -Fetchontent populated dependencies-. Will reevaluate based on this info.