[cmake] Add dune_execute_process with better error checking
1 unresolved thread
1 unresolved thread
CMake by default does not check the return codes of any commands invoked through execute_process. This can lead to very undesirable behaviour. Manually checking the return code is tedious, so this commit introduces a dune-prefixed version, which does the job.
This will be used by the python build system integration soon to be migrated to dune-common.
Merge request reports
Activity
mentioned in merge request !219 (merged)
- cmake/modules/DuneExecuteProcess.cmake 0 → 100644
6 # :single: 7 # 8 # Error message to show if command exited with non-zero exit code. 9 # Note, that if this is omitted, no return code checking is done. 10 # 11 # A thin wrapper around the cmake command :code:`execute_process`, that 12 # exits on non-zero exit codes. All arguments are forwarded to the actual 13 # cmake command. 14 # 15 16 function(dune_execute_process) 17 include(CMakeParseArguments) 18 cmake_parse_arguments(EXECUTE "" "ERROR_MESSAGE;RESULT_VARIABLE;OUTPUT_VARIABLE;ERROR_VARIABLE" "" ${ARGN}) 19 20 # Decide whether stdout and stderr have to be split 21 if(EXECUTE_OUTPUT_VARIABLE AND EXECUTE_ERROR_VARIABLE) @gruenich I had a script
script.sh
that reads something like#!/bin/bash exit 1
Then do:
dune_execute_process(COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/script.sh ERROR_MESSAGE "This failed!" )
You can now play with the script and the
{OUTPUT,ERROR}_VARIABLE
etc. to retrieve stdout, stderr and return code.- Resolved by Dominic Kempf
added 1 commit
- da08e916 - [doc] Document that error message will also cause cmake to fail.
mentioned in commit 11b3d7f6
mentioned in commit 1e4980a0
Please register or sign in to reply