1# SPDX-License-Identifier: Apache-2.0
2
3# Parameter names identical to the execute_process() CMake command, and
4# "ARGS" for the process command-line arguments.
5# Use set(ARGS ...) to build the ARGS list and then quote the list
6# when invoking the COMMAND. Example:
7# set(ARGS a b c)
8# -DARGS="${ARGS}"
9
10if(NOT DEFINED COMMAND)
11  message(FATAL_ERROR "No COMMAND argument supplied")
12endif()
13
14if(NOT DEFINED ARGS)
15  set(ARGS )
16else()
17  separate_arguments(ARGS)
18endif()
19
20if(DEFINED OUTPUT_FILE)
21  set(OF OUTPUT_FILE ${OUTPUT_FILE})
22endif()
23
24if(DEFINED ERROR_FILE)
25  set(EF ERROR_FILE ${ERROR_FILE})
26endif()
27
28if(DEFINED WORKING_DIRECTORY)
29  set(WD WORKING_DIRECTORY ${WORKING_DIRECTORY})
30endif()
31
32execute_process(
33  COMMAND ${COMMAND}
34  ${ARGS}
35  ${OF}
36  ${EF}
37  ${WD}
38  RESULT_VARIABLE ret
39)
40
41if(NOT "${ret}" STREQUAL "0")
42  message(FATAL_ERROR "Process failed: '${ret}'")
43endif()
44