Copy file from source directory to binary directory using CMake

后端 未结 8 1819
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-28 03:37

I\'m trying to create a simple project on CLion. It uses CMake (I\'m new here) to generate Makefiles to build project (or some sort of it)

All I need to is transfer

8条回答
  •  -上瘾入骨i
    2020-11-28 04:36

    The suggested configure_file is probably the easiest solution. However, it will not rerun the copy command to if you manually deleted the file from the build directory. To also handle this case, the following works for me:

    add_custom_target(copy-test-makefile ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/input.txt)
    add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/input.txt
                       COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/input.txt
                                                        ${CMAKE_CURRENT_BINARY_DIR}/input.txt
                       DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/input.txt)
    

提交回复
热议问题