I have added this custom target to my CMakeList.txt file.
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
)
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.
How can I tell CMake it should ignore return errors?
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
Execute command2 only if command1 fails (OR)
command1 || command2
From this SO answer it is possible to generate a successful return code using (exit 0)
trueis roughly equivalent to(exit 0)(the parentheses create a subshell that exits with status 0, instead of exiting your current shell.
Putting it all together:
ADD_CUSTOM_TARGET(unittest_run
COMMAND test1.exe > result.testresult || (exit 0)
COMMAND test2.exe >> result.testresult || (exit 0)
COMMAND type result.testresult
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With