# MODULE library and copying TARGET\_RUNTIME\_DLLS

**URL:** https://discourse.cmake.org/t/module-library-and-copying-target-runtime-dlls/5488
**Category:** Usage
**Created:** [April 19, 2022, 12:51pm UTC](https://discourse.cmake.org/t/module-library-and-copying-target-runtime-dlls/5488 "2022-04-19T12:51:07Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![bukuli.norbert](https://discourse.cmake.org/user_avatar/discourse.cmake.org/bukuli.norbert/32/2356_2.png) [@bukuli.norbert](https://discourse.cmake.org/u/bukuli.norbert)
#### Post date: [April 19, 2022, 12:51pm UTC](https://discourse.cmake.org/t/module-library-and-copying-target-runtime-dlls/5488/1 "2022-04-19T12:51:07Z")

</div>

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.

```auto
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!

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [April 19, 2022, 1:34pm UTC](https://discourse.cmake.org/t/module-library-and-copying-target-runtime-dlls/5488/2 "2022-04-19T13:34:18Z")

</div>

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

---

<div class="post-metadata">

### Author: ![kyle.edwards](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/k/65b543/32.png) [@kyle.edwards](https://discourse.cmake.org/u/kyle.edwards)
#### Post date: [April 19, 2022, 1:47pm UTC](https://discourse.cmake.org/t/module-library-and-copying-target-runtime-dlls/5488/3 "2022-04-19T13:47:25Z")

</div>

See [https://gitlab.kitware.com/cmake/cmake/-/merge\_requests/7186](https://gitlab.kitware.com/cmake/cmake/-/merge_requests/7186).

---

<div class="post-metadata">

### Author: ![bukuli.norbert](https://discourse.cmake.org/user_avatar/discourse.cmake.org/bukuli.norbert/32/2356_2.png) [@bukuli.norbert](https://discourse.cmake.org/u/bukuli.norbert)
#### Post date: [April 20, 2022, 5:48am UTC](https://discourse.cmake.org/t/module-library-and-copying-target-runtime-dlls/5488/4 "2022-04-20T05:48:53Z")

</div>

Thank you for the clarification!
