Copy file from source directory to binary directory using CMake

后端 未结 8 1860
佛祖请我去吃肉
佛祖请我去吃肉 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条回答
  •  余生分开走
    2020-11-28 04:36

    I would suggest TARGET_FILE_DIR if you want the file to be copied to the same folder as your .exe file.

    $ Directory of main file (.exe, .so.1.2, .a).

    add_custom_command(
      TARGET ${PROJECT_NAME} POST_BUILD
      COMMAND ${CMAKE_COMMAND} -E copy 
        ${CMAKE_CURRENT_SOURCE_DIR}/input.txt 
        $)
    

    In VS, this cmake script will copy input.txt to the same file as your final exe, no matter it's debug or release.

提交回复
热议问题