CMake仅在重新加载时复制文件,而不生成 [英] CMake only copies files on reload, not build

查看:136
本文介绍了CMake仅在重新加载时复制文件,而不生成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在CLion IDE中使用CMake,在CMakeLists.txt中,我使用以下命令将一些资源文件复制到二进制目录中:

I'm using CMake in the CLion IDE, and in my CMakeLists.txt I use the following command in order to copy some resource files into the binary directory:

file(COPY ${CMAKE_SOURCE_DIR}/res DESTINATION ${CMAKE_BINARY_DIR})

每当将我的CMake项目重新加载到CLion中时,此方法均起作用。但是,只要我尝试构建,就不会再次复制文件。我该如何解决?我是否使用了错误的命令?

This works whenever my CMake project is reloaded in CLion. However, whenever I just try to build, the files aren't copied again. How do I fix this? Am I using the wrong command?

推荐答案

使用 add_custom_target

add_custom_target(copy_res_directory ALL
    COMMAND ${CMAKE_COMMAND} -E copy_directory 
        "${CMAKE_SOURCE_DIR}/res" "${CMAKE_BINARY_DIR}/res"
    COMMENT "Copy res directory to build tree"
    VERBATIM)

这篇关于CMake仅在重新加载时复制文件,而不生成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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