Issue
In my cmake file i run a command with execute_process
. And i want to check if it failed. It doesn't print anything to stderr
.
So far I have been using a bash script that runs the command and then checks the exit status with $? == 1
.
Is there a way to do something similar with cmake?
execute_process(COMMAND "runThis")
if("{$?}" EQUAL 1)
message( FATAL_ERROR "Bad exit status")
endif()
I use cmake 3.12.1
Solution
You may find exit status of the executing process by using RESULT_VARIABLE
option for execute_process
invocation. From option's documentation:
The variable will be set to contain the result of running the processes. This will be an integer return code from the last child or a string describing an error condition.
Example:
execute_process(COMMAND "runThis" RESULT_VARIABLE ret)
if(ret EQUAL "1")
message( FATAL_ERROR "Bad exit status")
endif()
Answered By - Tsyvarev