CMake:如何在make之后将目录的内容复制到build目录中 [英] CMake: How to copy contents of a directory into build directory after make

查看:2098
本文介绍了CMake:如何在make之后将目录的内容复制到build目录中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些配置文件(xml,ini,...)在config目录旁边的源文件。

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?

推荐答案

如何将配置目录中的所有文件复制到构建目录(可执行文件旁边) >

您可以使用 add_custom_command

You can use add_custom_command.

假设你的目标叫做 MyTarget ,你可以:

Say your target is called MyTarget, you could do:

add_custom_command(TARGET MyTarget PRE_BUILD
                   COMMAND ${CMAKE_COMMAND} -E copy_directory
                       ${CMAKE_SOURCE_DIR}/config $<TARGET_FILE_DIR:MyTarget>)



每次构建 MyTarget 并将/ config的内容复制到目标exe / lib将要结束的目录中。

This executes every time you build MyTarget and copies the contents of "/config" into the directory where the target exe/lib will end up.

As Mark Lakata 在下面的评论中指出,用替换 PRE_BUILD add_custom_command 中的POST_BUILD 可确保只有在构建成功时才能进行复制。

As Mark Lakata points out in a comment below, replacing PRE_BUILD with POST_BUILD in the add_custom_command ensures that copying will only happen if the build succeeds.

这篇关于CMake:如何在make之后将目录的内容复制到build目录中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆