参考
cmake 宏定义
https://blog.csdn.net/bytxl/article/details/50634868
add_custom_command使用
https://www.jianshu.com/p/e6552ac81a7f
https://blog.csdn.net/qq_38410730/article/details/102797448
https://www.cnblogs.com/JoyPoint/p/11629521.html
set(TEST_FILE "log.txt")
1、方法1
add_custom_command(OUTPUT ${TEST_FILE}
COMMAND echo "Generating log.txt file..."
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_LIST_FILE} ${TEST_FILE}
COMMENT "This is a test"
)
add_custom_target(Test1 ALL DEPENDS ${TEST_FILE})
2、方法2
add_custom_target(CopyTask
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/config ${CMAKE_CURRENT_SOURCE_DIR}/etc
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/log.txt ${CMAKE_CURRENT_SOURCE_DIR}/etc
)
add_custom_command(TARGET Test1
PRE_BUILD
COMMAND echo "executing a fake command"
COMMENT "This command will be executed before building target Test1"
)