且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将外部测试文件添加到cmake项目

更新时间:2023-01-26 14:54:29

使用 add_custom_command()添加构建后步骤, a href = https://cmake.org/cmake/help/v3.4/manual/cmake-generator-expressions.7.html#informational-expressions rel = nofollow noreferrer>生成器表达式:

You could just add a post-build step with add_custom_command() using generator expressions:

add_custom_command(
    TARGET myBinary 
    POST_BUILD
        COMMAND ${CMAKE_COMMAND} -E copy  
                     "${CMAKE_CURRENT_SOURCE_DIR}/myTest.txt" 
                     "$<TARGET_FILE_DIR:myBinary>/myTest.txt"
)

参考

  • Copy target file to another location in a post build step in CMake