add_custom_command 執行錯誤
add_custom_command: 帶有OUTPUT引數的呼叫 用於生成專案中自動產生的原始檔。
add_custom_command(OUTPUT output1 [output2 ...]
# COMMAND command1 [ARGS] [args1...]
# [COMMAND command2 [ARGS] [args2...] ...]
# [MAIN_DEPENDENCY depend]
# [DEPENDS [depends...]]
# [IMPLICIT_DEPENDS <lang1> depend1 ...]
# [WORKING_DIRECTORY dir]
# [COMMENT comment] [VERBATIM] [APPEND])
add_custom_command(OUTPUT ${TEST_FILE} COMMAND echo "this is output log.txt" COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_LIST_FILE} ${TEST_FILE} COMMENT "This is a test1")
以上命令,照著例子抄寫,竟然提示內部出現錯誤,經過反覆檢查和理解,最終發現, 是最後一個COMMAND和COMMENT之間多寫了幾個空格導致錯誤。真是個坑啊,同時也覺得,沒事別亂寫空格,自己個自己挖了個坑。
set(TEST_FILE "log.txt")
add_custom_command(OUTPUT ${TEST_FILE} COMMAND echo "this is output log.txt" COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_LIST_FILE} ${TEST_FILE} COMMENT "This is a test1")
add_custom_target(Test1 ALL DEPENDS ${TEST_FILE})