Feature request: execute_process() should make it easy to fail on an error result
Currently, if a command spawned through execute_process()
fails by returning an error code other than zero, CMake just keeps going. The only way to abort in that case is to explicitly check the RESULT_VARIABLE
.
This can lead to one of three outcomes:
- It's actually okay for that command to fail. I'm willing to bet that's a rare use case.
- Error checking was left out due to oversight: when the command fails, the script keeps going and then falls over itself in possibly confusing ways, or worse, it succeeds and then does the wrong thing (fail-deadly).
- Someone actually thought of checking for errors, which involves pointless, fiddly boilerplate (example 1, example 2)
A few suggestions for improving this, in order of personal preference:
- Make the command generate a fatal error if the result is non-zero and the caller is not checking the error code (i.e. the
RESULT_VARIABLE
parameter wasn't used). This might break existing scripts, but maybe that could be alleviated through the policy system? - Add a new command, e.g.
execute_process_fatal()
, that does the above. - Add a new parameter to the command, e.g.
ABORT_ON_ERROR
, that generates a fatal error if the result is non-zero.
Edited by Etienne Dechamps