Reputation: 369
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?
Upvotes: 4
Views: 5397
Reputation: 369
It works only this way:
COMMAND
test1.exe > result.testresult &
test2.exe >> result.testresult ||
(exit 0) &
type result.testresult
Upvotes: 0
Reputation: 28689
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)
true
is 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
)
Upvotes: 5