gpt4 book ai didi

CMake忽略自定义目标的返回

转载 作者:行者123 更新时间:2023-12-04 03:04:27 26 4
gpt4 key购买 nike

我已将此自定义目标添加到我的 CMakeList.txt 文件中。

系统:Windows 7、TDMGCC MinGW32 和来自 GitHub 的最新版 Ninja。

ADD_CUSTOM_TARGET(unittest_run
COMMAND test1.exe > result.testresult
COMMAND test2.exe >> result.testresult
COMMAND type result.testresult
)

问题是,当 test1.exe 失败时,我会生成失败输出,但似乎还会出现一些错误代码,这会导致问题。 忍者:构建停止:子命令失败。

我如何告诉 CMake 它应该忽略返回错误?

最佳答案

您可以尝试使用条件 OR 语句,只有在前面的语句失败时才会运行该语句,并从辅助语句生成成功的返回码

来自 this page在“条件执行”上,您可以使用 || 在第一条语句失败时有条件地执行第二条语句

Execute command2 only if command1 fails (OR)

    command1 || command2

来自 this SO answer可以使用 (exit 0)

生成成功的返回代码

true is roughly equivalent to (exit 0) (the parentheses create a subshell that exits with status 0, instead of exiting your current shell.

综合起来:

ADD_CUSTOM_TARGET(unittest_run
COMMAND test1.exe > result.testresult || (exit 0)
COMMAND test2.exe >> result.testresult || (exit 0)
COMMAND type result.testresult
)

关于CMake忽略自定义目标的返回,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50027063/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com