Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CMake ignore return on custom target

Tags:

cmake

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?

like image 680
mgiaco Avatar asked Nov 01 '25 08:11

mgiaco


1 Answers

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
)
like image 79
Steve Lorimer Avatar answered Nov 04 '25 10:11

Steve Lorimer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!