使用cmake将文件复制到指定的目录

时间:2017-08-26 09:44:23

标签: visual-studio cmake

我想将somefile.bmp复制到我的“$ {PROJECT_BINARY_DIR} / bin / data”文件夹,但它不起作用。但是,如果我将路径更改为“$ {PROJECT_BINARY_DIR} / bin”,则可以正常工作。我该如何解决这个问题?

add_custom_command(TARGET Invaders POST_BUILD 
           COMMAND ${CMAKE_COMMAND} -E copy_if_different
           "${PROJECT_SOURCE_DIR}/Game/data/somefile.bmp"              
           "${PROJECT_BINARY_DIR}/bin/data")

1 个答案:

答案 0 :(得分:1)

我猜这个目录不存在。您需要在复制之前创建它:

add_custom_command(TARGET Invaders POST_BUILD 
           COMMAND ${CMAKE_COMMAND} -E make_directory
           "${PROJECT_SOURCE_DIR}/Game/data"
           COMMAND ${CMAKE_COMMAND} -E copy_if_different
           "${PROJECT_SOURCE_DIR}/Game/data/somefile.bmp"              
           "${PROJECT_BINARY_DIR}/bin/data")