execute_processΒΆ
Execute one or more child processes.
execute_process(COMMAND <cmd1> [<arguments>]
[COMMAND <cmd2> [<arguments>]]...
[WORKING_DIRECTORY <directory>]
[TIMEOUT <seconds>]
[RESULT_VARIABLE <variable>]
[RESULTS_VARIABLE <variable>]
[OUTPUT_VARIABLE <variable>]
[ERROR_VARIABLE <variable>]
[INPUT_FILE <file>]
[OUTPUT_FILE <file>]
[ERROR_FILE <file>]
[OUTPUT_QUIET]
[ERROR_QUIET]
[COMMAND_ECHO <where>]
[OUTPUT_STRIP_TRAILING_WHITESPACE]
[ERROR_STRIP_TRAILING_WHITESPACE]
[ENCODING <name>]
[ECHO_OUTPUT_VARIABLE]
[ECHO_ERROR_VARIABLE]
[COMMAND_ERROR_IS_FATAL <ANY|LAST>])
Runs the given sequence of one or more commands.
Commands are executed concurrently as a pipeline, with the standard output of each process piped to the standard input of the next. A single standard error pipe is used for all processes.
execute_process runs commands while CMake is configuring the project,
prior to build system generation. Use the add_custom_target() and
add_custom_command() commands to create custom commands that run
at build time.
Options:
COMMANDA child process command line.
CMake executes the child process using operating system APIs directly:
On POSIX platforms, the command line is passed to the child process in an
argv[]style array.On Windows platforms, the command line is encoded as a string such that child processes using
CommandLineToArgvWwill decode the original arguments.
No intermediate shell is used, so shell operators such as
>are treated as normal arguments. (Use theINPUT_*,OUTPUT_*, andERROR_*options to redirect stdin, stdout, and stderr.)For sequential execution of multiple commands use multiple
execute_processcalls each with a singleCOMMANDargument.WORKING_DIRECTORYThe named directory will be set as the current working directory of the child processes.
TIMEOUTAfter the specified number of seconds (fractions allowed), all unfinished child processes will be terminated, and the
RESULT_VARIABLEwill be set to a string mentioning the "timeout".RESULT_VARIABLEThe variable will be set to contain the result of last child process. This will be an integer return code from the last child or a string describing an error condition.
RESULTS_VARIABLE <variable>Added in version 3.10.
The variable will be set to contain the result of all processes as a semicolon-separated list, in order of the given
COMMANDarguments. Each entry will be an integer return code from the corresponding child or a string describing an error condition.INPUT_FILE <file><file>is attached to the standard input pipe of the firstCOMMANDprocess.OUTPUT_FILE <file><file>is attached to the standard output pipe of the lastCOMMANDprocess.ERROR_FILE <file><file>is attached to the standard error pipe of allCOMMANDprocesses.
Added in version 3.3: If the same <file> is named for both OUTPUT_FILE and ERROR_FILE
then it will be used for both standard output and standard error pipes.
OUTPUT_QUIET,ERROR_QUIETThe standard output on
OUTPUT_VARIABLEor standard error onERROR_VARIABLEare not connected (no variable content). The*_FILEandECHO_*_VARIABLEoptions are not affected.OUTPUT_VARIABLE,ERROR_VARIABLEThe variable named will be set with the contents of the standard output and standard error pipes, respectively. If the same variable is named for both pipes their output will be merged in the order produced.
ECHO_OUTPUT_VARIABLE,ECHO_ERROR_VARIABLEAdded in version 3.18.
The standard output or standard error will not be exclusively redirected to the specified variables.
The output will be duplicated into the specified variables and also onto standard output or standard error analogous to the
teeUnix command.
Note
If more than one OUTPUT_* or ERROR_* option is given for the
same pipe the precedence is not specified.
If no OUTPUT_* or ERROR_* options are given the output will
be shared with the corresponding pipes of the CMake process itself.
COMMAND_ECHO <where>Added in version 3.15.
The command being run will be echo'ed to
<where>with<where>being set to one ofSTDERR,STDOUTorNONE. See theCMAKE_EXECUTE_PROCESS_COMMAND_ECHOvariable for a way to control the default behavior when this option is not present.ENCODING <name>Added in version 3.8.
On Windows, the encoding that is used to decode output from the process. Ignored on other platforms. Valid encoding names are:
NONEPerform no decoding. This assumes that the process output is encoded in the same way as CMake's internal encoding (UTF-8).
This was the default in CMake 3.14 and older.
AUTOUse the current active console's codepage or if that isn't available then use ANSI.
This was the default in CMake 3.15 through 3.30.
ANSIUse the ANSI codepage.
OEMUse the original equipment manufacturer (OEM) code page.
UTF-8Added in version 3.11.
Use the UTF-8 codepage.
This is the default since CMake 3.31. See policy
CMP0176.UTF8Use the UTF-8 codepage. Use of this name is discouraged in favor of
UTF-8to match the UTF-8 RFC naming convention.
COMMAND_ERROR_IS_FATAL <ANY|LAST>Added in version 3.19.
The option following
COMMAND_ERROR_IS_FATALdetermines the behavior when an error is encountered:ANYIf any of the commands in the list of commands fail, theexecute_process()command halts with an error.LASTIf the last command in the list of commands fails, theexecute_process()command halts with an error. Commands earlier in the list will not cause a fatal error.