after build - How to copy DLL files into the same folder as the executable using CMake?

3 Answers

I put these lines in my top-level CMakeLists.txt file. All the libraries and executables will be placed in the top level of the build directory so that the executables can find the libraries and it is easy to run everything.

directory find add_custom_command

We use CMake for generating the Visual Studio files of our sources in our SVN. Now my tool requires some DLL files to be in the same folder as the executable. The DLL files are in a folder alongside the source.

How can I change my CMakeLists.txt such that the generated Visual Studio project will either have already the particular DLL files in the release/debug folders or will copy them upon compilation?

You probably need to add custom target and make it depend on one of your executable targets. To copy file using above function use

COMMAND ${CMAKE_PROGRAM} -E copy_if_different ${CMAKE_BINARY_DIR}/path/to/file.dll ${CMAKE_BINARY_DIR}/where/to/put/file.dll.

You can also use the command find_library:

find_library(<some_var> NAMES <name_of_lib> PATHS "<path/to/lib>")

With a defined EXECUTABLE_PATH, for instance:


you could move the .dll files that your executable need, with

file(COPY ${<some_var>}



dll   cmake