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

I’d use add_custom_command to achieve this along with cmake -E copy_if_different…. For full info run cmake –help-command add_custom_command cmake -E So in your case, if you have the following directory structure: /CMakeLists.txt /src /libs/test.dll and your CMake target to which the command applies is MyTest, then you could add the following to your CMakeLists.txt: add_custom_command(TARGET … Read more

How do I add a linker or compile flag in a CMake file?

Note: Given CMake evolution since this was answer was written in 2012, most of the suggestions here are now outdated/deprecated and have better alternatives. Suppose you want to add those flags (better to declare them in a constant): SET(GCC_COVERAGE_COMPILE_FLAGS “-fprofile-arcs -ftest-coverage”) SET(GCC_COVERAGE_LINK_FLAGS “-lgcov”) There are several ways to add them: The easiest one (not clean, … Read more

CMake link to external library

arrowdodger’s answer is correct and preferred on many occasions. I would simply like to add an alternative to his answer: You could add an “imported” library target, instead of a link-directory. Something like: # Your-external “mylib”, add GLOBAL if the imported library is located in directories above the current. add_library( mylib SHARED IMPORTED ) # … Read more