MODULE library and copying TARGET_RUNTIME_DLLS

Hi community,

This topic is about the usage of $<TARGET_RUNTIME_DLLS:tgt> but there is a slight possibility that I’ve misunderstood something in the documentation, that states the following:

List of DLLs that the target depends on at runtime. This is determined by the locations of all the SHARED and MODULE targets in the target’s transitive dependencies.

So, let’s suppose that I have a CMake project that consist of three targets:

  • a shared library created with add_library(mylib SHARED ...). (Static library usage is omitted now for brevity)
  • a module created with add_library(mymodule MODULE ...)
  • an executable created with add_executable(myapp ...)

Furthermore

  • myapp links to the shared library mylib: target_link_libraries(myapp PRIVATE mylib)
  • myapp loads mymodule at runtime

The task is to copy all of the runtime parts (myapp.exe, mylib.dll, mymodule.dll) into one directory. Applying the example code (see below) from the documentation of $<TARGET_RUNTIME_DLLS:tgt> to my situation works well, if there is no MODULE, just the application and the shared library.

add_custom_command(TARGET exe POST_BUILD
  COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_RUNTIME_DLLS:exe> $<TARGET_FILE_DIR:exe>
  COMMAND_EXPAND_LISTS
  )

According to the documentation, MODULE dependencies could be somehow gathered with $<TARGET_RUNTIME_DLLS>, the question is, how can I set the dependency?

I’ve checked the following with cmake-3.22.3:

  • target_link_libraries will not work if the dependency is a MODULE.
  • add_dependencies will not insert a new dependency to mymodule.dll so it is not copied

Any help is highly appreciated!
Thank you!

@kyle.edwards I think the docs need clarification because adding a dependency on a MODULE target is…not really a thing.

See https://gitlab.kitware.com/cmake/cmake/-/merge_requests/7186.

Thank you for the clarification!