execute_process.rst 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. execute_process
  2. ---------------
  3. Execute one or more child processes.
  4. .. code-block:: cmake
  5. execute_process(COMMAND <cmd1> [<arguments>]
  6. [COMMAND <cmd2> [<arguments>]]...
  7. [WORKING_DIRECTORY <directory>]
  8. [TIMEOUT <seconds>]
  9. [RESULT_VARIABLE <variable>]
  10. [RESULTS_VARIABLE <variable>]
  11. [OUTPUT_VARIABLE <variable>]
  12. [ERROR_VARIABLE <variable>]
  13. [INPUT_FILE <file>]
  14. [OUTPUT_FILE <file>]
  15. [ERROR_FILE <file>]
  16. [OUTPUT_QUIET]
  17. [ERROR_QUIET]
  18. [COMMAND_ECHO <where>]
  19. [OUTPUT_STRIP_TRAILING_WHITESPACE]
  20. [ERROR_STRIP_TRAILING_WHITESPACE]
  21. [ENCODING <name>]
  22. [ECHO_OUTPUT_VARIABLE]
  23. [ECHO_ERROR_VARIABLE]
  24. [COMMAND_ERROR_IS_FATAL <ANY|LAST>])
  25. Runs the given sequence of one or more commands.
  26. Commands are executed concurrently as a pipeline, with the standard
  27. output of each process piped to the standard input of the next.
  28. A single standard error pipe is used for all processes.
  29. Options:
  30. ``COMMAND``
  31. A child process command line.
  32. CMake executes the child process using operating system APIs directly.
  33. All arguments are passed VERBATIM to the child process.
  34. No intermediate shell is used, so shell operators such as ``>``
  35. are treated as normal arguments.
  36. (Use the ``INPUT_*``, ``OUTPUT_*``, and ``ERROR_*`` options to
  37. redirect stdin, stdout, and stderr.)
  38. If a sequential execution of multiple commands is required, use multiple
  39. :command:`execute_process` calls with a single ``COMMAND`` argument.
  40. ``WORKING_DIRECTORY``
  41. The named directory will be set as the current working directory of
  42. the child processes.
  43. ``TIMEOUT``
  44. After the specified number of seconds (fractions allowed), all unfinished
  45. child processes will be terminated, and the ``RESULT_VARIABLE`` will be
  46. set to a string mentioning the "timeout".
  47. ``RESULT_VARIABLE``
  48. The variable will be set to contain the result of last child process.
  49. This will be an integer return code from the last child or a string
  50. describing an error condition.
  51. ``RESULTS_VARIABLE <variable>``
  52. The variable will be set to contain the result of all processes as a
  53. :ref:`semicolon-separated list <CMake Language Lists>`, in order of the
  54. given ``COMMAND`` arguments. Each entry will be an integer return code
  55. from the corresponding child or a string describing an error condition.
  56. ``OUTPUT_VARIABLE``, ``ERROR_VARIABLE``
  57. The variable named will be set with the contents of the standard output
  58. and standard error pipes, respectively. If the same variable is named
  59. for both pipes their output will be merged in the order produced.
  60. ``INPUT_FILE, OUTPUT_FILE``, ``ERROR_FILE``
  61. The file named will be attached to the standard input of the first
  62. process, standard output of the last process, or standard error of
  63. all processes, respectively. If the same file is named for both
  64. output and error then it will be used for both.
  65. ``OUTPUT_QUIET``, ``ERROR_QUIET``
  66. The standard output or standard error results will be quietly ignored.
  67. ``COMMAND_ECHO <where>``
  68. The command being run will be echo'ed to ``<where>`` with ``<where>``
  69. being set to one of ``STDERR``, ``STDOUT`` or ``NONE``.
  70. See the :variable:`CMAKE_EXECUTE_PROCESS_COMMAND_ECHO` variable for a way
  71. to control the default behavior when this option is not present.
  72. ``ENCODING <name>``
  73. On Windows, the encoding that is used to decode output from the process.
  74. Ignored on other platforms.
  75. Valid encoding names are:
  76. ``NONE``
  77. Perform no decoding. This assumes that the process output is encoded
  78. in the same way as CMake's internal encoding (UTF-8).
  79. This is the default.
  80. ``AUTO``
  81. Use the current active console's codepage or if that isn't
  82. available then use ANSI.
  83. ``ANSI``
  84. Use the ANSI codepage.
  85. ``OEM``
  86. Use the original equipment manufacturer (OEM) code page.
  87. ``UTF8`` or ``UTF-8``
  88. Use the UTF-8 codepage. Prior to CMake 3.11.0, only ``UTF8`` was accepted
  89. for this encoding. In CMake 3.11.0, ``UTF-8`` was added for consistency with
  90. the `UTF-8 RFC <https://www.ietf.org/rfc/rfc3629>`_ naming convention.
  91. ``ECHO_OUTPUT_VARIABLE``, ``ECHO_ERROR_VARIABLE``
  92. The standard output or standard error will not be exclusively redirected to
  93. the configured variables.
  94. The output will be duplicated, it will be sent into the configured variables
  95. and also on standard output or standard error.
  96. This is analogous to the ``tee`` Unix command.
  97. ``COMMAND_ERROR_IS_FATAL <ANY|LAST>``
  98. ``COMMAND_ERROR_IS_FATAL ANY`` option stops processing if any command fails.
  99. ``COMMAND_ERROR_IS_FATAL LAST`` option stops processing if the last command
  100. in the command list fails.
  101. If more than one ``OUTPUT_*`` or ``ERROR_*`` option is given for the
  102. same pipe the precedence is not specified.
  103. If no ``OUTPUT_*`` or ``ERROR_*`` options are given the output will
  104. be shared with the corresponding pipes of the CMake process itself.
  105. The :command:`execute_process` command is a newer more powerful version of
  106. :command:`exec_program`, but the old command has been kept for compatibility.
  107. Both commands run while CMake is processing the project prior to build
  108. system generation. Use :command:`add_custom_target` and
  109. :command:`add_custom_command` to create custom commands that run at
  110. build time.