CMake忽略自定义目标的回报 [英] CMake ignore return on custom target
问题描述
我已将此自定义目标添加到我的 CMakeList.txt
文件中。
I have added this custom target to my CMakeList.txt
file.
系统:Windows 7,TDMGCC MinGW32和Ninja是GitHub上的最新版本。
System: Windows 7, TDMGCC MinGW32, and Ninja latest from GitHub.
ADD_CUSTOM_TARGET(unittest_run
COMMAND test1.exe > result.testresult
COMMAND test2.exe >> result.testresult
COMMAND type result.testresult
)
问题是,当 test1.exe
失败时,我会生成失败输出,但似乎还会出现一些错误代码,这会导致问题。 忍者:构建停止:子命令失败。
The problem is that when test1.exe
fails I generate a fail output, but it seems that there is also some error code coming which causes a problem. ninja: build stopped: subcommand failed.
我如何告诉CMake应该忽略返回错误?
How can I tell CMake it should ignore return errors?
推荐答案
您可以尝试使用条件OR语句,该条件OR语句仅在前面的语句失败时才运行,并从中生成成功的返回码次要声明
You can try use a conditional OR statement, which will be run only if the preceding statement fails, and generate a successful return code from the secondary statement
来自此页面 ;有条件的执行如果第一个失败,则可以使用 |||
有条件地执行第二条语句
From this page on "Conditional Execution" you can use ||
to conditionally execute a secondary statement if the first fails
仅在以下情况下执行command2 command1失败(或)
Execute command2 only if command1 fails (OR)
command1 || command2
来自此SO答案可以使用(出口0)
生成成功的返回码
true
大致等效于(退出0)
(括号中会创建一个退出的子外壳状态为0,而不是退出当前shell。
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忽略自定义目标的回报的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!