execute_process.rst 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. execute_process
  2. ---------------
  3. Execute one or more child processes.
  4. .. code-block:: cmake
  5. execute_process(COMMAND <cmd1> [args1...]]
  6. [COMMAND <cmd2> [args2...] [...]]
  7. [WORKING_DIRECTORY <directory>]
  8. [TIMEOUT <seconds>]
  9. [RESULT_VARIABLE <variable>]
  10. [OUTPUT_VARIABLE <variable>]
  11. [ERROR_VARIABLE <variable>]
  12. [INPUT_FILE <file>]
  13. [OUTPUT_FILE <file>]
  14. [ERROR_FILE <file>]
  15. [OUTPUT_QUIET]
  16. [ERROR_QUIET]
  17. [OUTPUT_STRIP_TRAILING_WHITESPACE]
  18. [ERROR_STRIP_TRAILING_WHITESPACE])
  19. Runs the given sequence of one or more commands with the standard
  20. output of each process piped to the standard input of the next.
  21. A single standard error pipe is used for all processes.
  22. Options:
  23. COMMAND
  24. A child process command line.
  25. CMake executes the child process using operating system APIs directly.
  26. All arguments are passed VERBATIM to the child process.
  27. No intermediate shell is used, so shell operators such as ``>``
  28. are treated as normal arguments.
  29. (Use the ``INPUT_*``, ``OUTPUT_*``, and ``ERROR_*`` options to
  30. redirect stdin, stdout, and stderr.)
  31. WORKING_DIRECTORY
  32. The named directory will be set as the current working directory of
  33. the child processes.
  34. TIMEOUT
  35. The child processes will be terminated if they do not finish in the
  36. specified number of seconds (fractions are allowed).
  37. RESULT_VARIABLE
  38. The variable will be set to contain the result of running the processes.
  39. This will be an integer return code from the last child or a string
  40. describing an error condition.
  41. OUTPUT_VARIABLE, ERROR_VARIABLE
  42. The variable named will be set with the contents of the standard output
  43. and standard error pipes, respectively. If the same variable is named
  44. for both pipes their output will be merged in the order produced.
  45. INPUT_FILE, OUTPUT_FILE, ERROR_FILE
  46. The file named will be attached to the standard input of the first
  47. process, standard output of the last process, or standard error of
  48. all processes, respectively.
  49. OUTPUT_QUIET, ERROR_QUIET
  50. The standard output or standard error results will be quietly ignored.
  51. If more than one ``OUTPUT_*`` or ``ERROR_*`` option is given for the
  52. same pipe the precedence is not specified.
  53. If no ``OUTPUT_*`` or ``ERROR_*`` options are given the output will
  54. be shared with the corresponding pipes of the CMake process itself.
  55. The :command:`execute_process` command is a newer more powerful version of
  56. :command:`exec_program`, but the old command has been kept for compatibility.
  57. Both commands run while CMake is processing the project prior to build
  58. system generation. Use :command:`add_custom_target` and
  59. :command:`add_custom_command` to create custom commands that run at
  60. build time.