Executing custom tasks at configuration time
To execute custom tasks at configuration time, you can use the execute_process
function. Common needs for this are if the build requires additional information before a build, or if files need to be updated for any rerun of CMake. Another common case is when either the CMakeLists.txt
file or other input files are generated during the configuration step, although this can also be achieved with the specialized configure_file
command, as shown later in this chapter.
The execute_process
function works very similarly to the add_custom_target
and add_custom_command
functions we saw earlier. However, one distinction is that execute_process
can capture output to stdout
and stderr
in a variable or files. The signature of execute_process
is as follows:
execute_process(COMMAND <cmd1> [<arguments>] [COMMAND <cmd2> [<arguments>...