Transitivity and install( ... RUNTIME_DEPENDENCIES ...)

Hello,

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>"
)

output of cmake --install . --prefix=install:

-- Install configuration: "Release"
-- Installing: C:/Users/nasos/code/source/test5/build/win10_64/Release/install/bin/myexe.exe
-- Installing: C:/Users/nasos/code/source/test5/build/win10_64/Release/install/lib/dep.lib
-- Installing: C:/Users/nasos/code/source/test5/build/win10_64/Release/install/bin/dep.dll
-- Installing: C:/Users/nasos/code/source/test5/build/win10_64/Release/install/include/dep.hpp

Edit: Changed instances of “test” to “myexe”.

Thank you!
-Nasos

That sounds like a failure to detect the dependency. Can you paste the output of dumpbin /DEPENDENTS test.exe?

FYI @kyle.edwards

Hello Ben,
Here is the dumpbin output

Microsoft (R) COFF/PE Dumper Version 14.28.29915.0
Copyright (C) Microsoft Corporation.  All rights reserved.


Dump of file myexe.exe

File Type: EXECUTABLE IMAGE

  Image has the following dependencies:

    dep.dll
    MSVCP140.dll
    VCRUNTIME140.dll
    VCRUNTIME140_1.dll
    api-ms-win-crt-runtime-l1-1-0.dll
    api-ms-win-crt-math-l1-1-0.dll
    api-ms-win-crt-stdio-l1-1-0.dll
    api-ms-win-crt-locale-l1-1-0.dll
    api-ms-win-crt-heap-l1-1-0.dll
    KERNEL32.dll

  Summary

        1000 .data
        1000 .pdata
        2000 .rdata
        1000 .reloc
        1000 .rsrc
        1000 .text

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.)

You need to install mylib and dep explicitly.

1 Like

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.

Thank you!