execute_process.rst 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. [ENCODING <name>])
  20. Runs the given sequence of one or more commands in parallel with the standard
  21. output of each process piped to the standard input of the next.
  22. A single standard error pipe is used for all processes.
  23. Options:
  24. ``COMMAND``
  25. A child process command line.
  26. CMake executes the child process using operating system APIs directly.
  27. All arguments are passed VERBATIM to the child process.
  28. No intermediate shell is used, so shell operators such as ``>``
  29. are treated as normal arguments.
  30. (Use the ``INPUT_*``, ``OUTPUT_*``, and ``ERROR_*`` options to
  31. redirect stdin, stdout, and stderr.)
  32. If a sequential execution of multiple commands is required, use multiple
  33. :command:`execute_process` calls with a single ``COMMAND`` argument.
  34. ``WORKING_DIRECTORY``
  35. The named directory will be set as the current working directory of
  36. the child processes.
  37. ``TIMEOUT``
  38. The child processes will be terminated if they do not finish in the
  39. specified number of seconds (fractions are allowed).
  40. ``RESULT_VARIABLE``
  41. The variable will be set to contain the result of running the processes.
  42. This will be an integer return code from the last child or a string
  43. describing an error condition.
  44. ``OUTPUT_VARIABLE``, ``ERROR_VARIABLE``
  45. The variable named will be set with the contents of the standard output
  46. and standard error pipes, respectively. If the same variable is named
  47. for both pipes their output will be merged in the order produced.
  48. ``INPUT_FILE, OUTPUT_FILE``, ``ERROR_FILE``
  49. The file named will be attached to the standard input of the first
  50. process, standard output of the last process, or standard error of
  51. all processes, respectively. If the same file is named for both
  52. output and error then it will be used for both.
  53. ``OUTPUT_QUIET``, ``ERROR_QUIET``
  54. The standard output or standard error results will be quietly ignored.
  55. ``ENCODING <name>``
  56. On Windows, the encoding that is used to decode output from the process.
  57. Ignored on other platforms.
  58. Valid encoding names are:
  59. ``NONE``
  60. Perform no decoding. This assumes that the process output is encoded
  61. in the same way as CMake's internal encoding (UTF-8).
  62. This is the default.
  63. ``AUTO``
  64. Use the current active console's codepage or if that isn't
  65. available then use ANSI.
  66. ``ANSI``
  67. Use the ANSI codepage.
  68. ``OEM``
  69. Use the original equipment manufacturer (OEM) code page.
  70. ``UTF8``
  71. Use the UTF-8 codepage.
  72. If more than one ``OUTPUT_*`` or ``ERROR_*`` option is given for the
  73. same pipe the precedence is not specified.
  74. If no ``OUTPUT_*`` or ``ERROR_*`` options are given the output will
  75. be shared with the corresponding pipes of the CMake process itself.
  76. The :command:`execute_process` command is a newer more powerful version of
  77. :command:`exec_program`, but the old command has been kept for compatibility.
  78. Both commands run while CMake is processing the project prior to build
  79. system generation. Use :command:`add_custom_target` and
  80. :command:`add_custom_command` to create custom commands that run at
  81. build time.