Derive DLLs for INSTALL (to be used with CPack)

I have written a little example project to show how to integrate vcpkg with various CMake features, including cmake, ctest, and cpack: GitHub - SamuelMarks/cmake-example-with-vcpkg: CMake example project with vcpkg dependencies

Unfortunately I’ve come against an issue with the CPack generated installer. It doesn’t include the DLLs from vcpkg. In this circumstance, it’s zlibd1.dll that is not being installed.

How do I get the DLLs depended on by my target—and include them in the installer—in the same directory as the executable?

Related: https://stackoverflow.com/q/10671916 https://gitlab.kitware.com/cmake/cmake/-/issues/18822 https://gitlab.kitware.com/cmake/cmake/-/merge_requests/6186

You’ve got the right idea in your “related” section - CMake 3.21 includes install(TARGETS... RUNTIME_DEPENDENCIES), which does exactly what you’re looking for.

(on the IRC channel I mentioned that I tried that solution but it didn’t copy zlib’s DLL)

Did you make sure to include zlib’s directory in the DIRECTORIES argument?

Oh wait this needs 3.21? - The one released two days ago?

https://blog.kitware.com/cmake-3-21-0-available-for-download

Okay, fine testing with that now. Looks like its blacklist is missing some things, maybe I’ll report a bug:

  • file Could not resolve file api-ms-win-core-apiquery-l1-1-0.dll

EDIT: https://gitlab.kitware.com/cmake/cmake/-/issues/22431