# Gathering transitive shared libraries

**URL:** https://discourse.cmake.org/t/gathering-transitive-shared-libraries/1100
**Category:** Code
**Created:** [April 25, 2020, 6:00am UTC](https://discourse.cmake.org/t/gathering-transitive-shared-libraries/1100 "2020-04-25T06:00:36Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![UebelAndre](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/u/85f322/32.png) [@UebelAndre](https://discourse.cmake.org/u/UebelAndre)
#### Post date: [April 25, 2020, 6:00am UTC](https://discourse.cmake.org/t/gathering-transitive-shared-libraries/1100/1 "2020-04-25T06:00:36Z")

</div>

How would one go about gathering all the shared libraries (`.dll`'s) for a given target and making sure they’re copied into its runtime/output directory?

As an example, see the diagram below.

```auto
executable
├── shared_lib
├── static_lib1
│ └── shared_lib
└── static_lib2

```

Note: some of these shared libraries are not built by the project, they’re installed on the machine and located with `find_package`.

The way I’ve solved for this was to write some recursive functions and cmake scripts for a custom target. I feel like there has to be something I’m missing. Any suggestions?

---

<div class="post-metadata">

### Author: ![McMartin](https://discourse.cmake.org/user_avatar/discourse.cmake.org/mcmartin/32/150_2.png) [@McMartin](https://discourse.cmake.org/u/McMartin)
#### Post date: [April 25, 2020, 7:21am UTC](https://discourse.cmake.org/t/gathering-transitive-shared-libraries/1100/2 "2020-04-25T07:21:58Z")

</div>

CMake 3.16 introduced `file(GET_RUNTIME_DEPENDENCIES ...)`.  
See [https://cmake.org/cmake/help/latest/command/file.html#get-runtime-dependencies](https://cmake.org/cmake/help/latest/command/file.html#get-runtime-dependencies) for more details.

---

<div class="post-metadata">

### Author: ![UebelAndre](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/u/85f322/32.png) [@UebelAndre](https://discourse.cmake.org/u/UebelAndre)
#### Post date: [April 25, 2020, 1:45pm UTC](https://discourse.cmake.org/t/gathering-transitive-shared-libraries/1100/3 "2020-04-25T13:45:46Z")

</div>

Awesome! Thank you!

That said though, should I be writing an `install` Script for all of my executables? Does that get run every time the target is built?

Edit: Also, I was assuming I can use generator expressions with this when used in the `install` command. Is this true?
