execute_process.rst 4.2 KB

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