具有非零退出代码的依赖项的add_dependencies

时间:2016-02-04 14:54:46

标签: cmake

我这样做:

    add_custom_target(Target1
        COMMAND Command1
    )
    add_custom_target(Target2
        COMMAND Command2
    )
    add_dependencies(Target2 Target1)

但如果Command1的退出代码为非零,则永远不会运行Command2。有没有办法确保Target2Target1之后运行,但无论Command1的退出代码是什么?

1 个答案:

答案 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很丑:)