# generate or copy .dll of 3rd-party to executable folder

**URL:** https://discourse.cmake.org/t/generate-or-copy-dll-of-3rd-party-to-executable-folder/2436
**Category:** Usage
**Tags:** os:windows
**Created:** [December 29, 2020, 12:44am UTC](https://discourse.cmake.org/t/generate-or-copy-dll-of-3rd-party-to-executable-folder/2436 "2020-12-29T00:44:04Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![aopaw](https://discourse.cmake.org/user_avatar/discourse.cmake.org/aopaw/32/1051_2.png) [@aopaw](https://discourse.cmake.org/u/aopaw)
#### Post date: [December 29, 2020, 12:44am UTC](https://discourse.cmake.org/t/generate-or-copy-dll-of-3rd-party-to-executable-folder/2436/1 "2020-12-29T00:44:04Z")

</div>

Hello,  
First time at here. I am using CMakeLists.txt to configure my project, a test project only.  
Suppose that the project depends on serveral 3rd-party libraries. Every of the libraries is in different directory and was listed to a variable with  
LIST(APPEDN LIBRARIES  
${3rdParty1\_LIBS}) # it could be 3rdParty1, 3rdParty2 or 3 blabla.  
Some of them were found with find\_package such as OpenCV and some others were only given by an absolute path of .lib files.

By the end of CMakeLists.txt, I use few codes trying to copy or generate .dll to the folder of the executable file. The codes, of course, were from search engine and do not work actually.

target\_link\_libraries(${PROJECT\_NAME} ${LIBRARIES})

add\_custom\_command ( TARGET ${PROJECT\_NAME} POST\_BUILD  
COMMAND ${CMAKE\_COMMAND} -E copy\_if\_different  
${LIBRARIES} $\<TARGET\_FILE\_DIR:${PROJECT\_NAME}\>  
)

After having these codes, a few .lib files were generated there but not all. None of .dll file of the libraries was found there as I expected.  
I am using 3.12.3 and do not want to use any new characteres of cmake which could make me feel a little complex.

---

<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: [January 4, 2021, 7:02pm UTC](https://discourse.cmake.org/t/generate-or-copy-dll-of-3rd-party-to-executable-folder/2436/2 "2021-01-04T19:02:12Z")

</div>

I would recommend using `file(GET_RUNTIME_DEPENDENCIES)` to find (added in CMake 3.16). If you want to stick to 3.12, there is the `GetPrerequisites` module which does the same kind of thing, just…not as reliably.
