Gathering transitive shared libraries

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.

├── 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?

CMake 3.16 introduced file(GET_RUNTIME_DEPENDENCIES ...).
See for more details.

1 Like

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?