I’ve got some config files (xml, ini, …) in the config directory next to the source files. How can I copy all the files in the config directory into the build directory (next to the executable file) each time I make the project?
I’ve got some config files (xml, ini, …) in the config directory next to
Share
You can use
add_custom_command.Say your target is called
MyTarget, then you can do this:This executes every time you build
MyTargetand copies the contents of "/config" into the directory where the target exe/lib will end up.As Mark Lakata points out in a comment below, replacing
PRE_BUILDwithPOST_BUILDin theadd_custom_commandensures that copying will only happen if the build succeeds.Explanation
${CMAKE_COMMAND}is the path to CMake (if CMake is added to your PATH environment variable, "cmake" is enough)-Emakes CMake run commands instead of buildingcopy_directoryis a Command-Line Toolconfigis the directory (that falls under the root of the project) whose contents will be copied into the build target$<TARGET_FILE_DIR:MyTarget>is a generator expression, described in theadd_custom_commanddocumentation.