我这样做:
add_custom_target(Target1
COMMAND Command1
)
add_custom_target(Target2
COMMAND Command2
)
add_dependencies(Target2 Target1)
但如果Command1
的退出代码为非零,则永远不会运行Command2
。有没有办法确保Target2
在Target1
之后运行,但无论Command1
的退出代码是什么?
答案 0 :(得分:0)
我最终得到了这个:
file(WRITE ${CMAKE_BINARY_DIR}/NoExitCodeTests.cmake "execute_process(COMMAND ctest)")
add_custom_target(Target1
COMMAND ${CMAKE_COMMAND} -P NoExitCodeTests.cmake
)
无论ctest
中发生什么,这都会使Target1始终返回0。丑陋,但有时CMake很丑:)