cmake的命令execute_process


execute_process(COMMAND <cmd1> [args1...]]
                [COMMAND <cmd2> [args2...] [...]]
                [WORKING_DIRECTORY <directory>]
                [TIMEOUT <seconds>]
                [RESULT_VARIABLE <variable>]
                [OUTPUT_VARIABLE <variable>]
                [ERROR_VARIABLE <variable>]
                [INPUT_FILE <file>]
                [OUTPUT_FILE <file>]
                [ERROR_FILE <file>]
                [OUTPUT_QUIET]
                [ERROR_QUIET]
                [OUTPUT_STRIP_TRAILING_WHITESPACE]
                [ERROR_STRIP_TRAILING_WHITESPACE])
執行進程
    這條命令可以執行系統命令,將輸出保存到cmake變量或文件中。比如你想通過git命令讀取版本號,在代碼中使用。又比如你想列出某些文件的名稱在代碼中使用。
    后面還會給出一個簡單的例子供大家參考。

Runs the given sequence of one or more commands with the standard output of each process piped to the standard input of the next. A single standard error pipe is used for all processes.
運行一個或多個給定的命令序列,每一個進程的標准輸出流向(管道)下一個進程的標准輸入。所有的流程使用一個單獨的標准錯誤管道。

Options:

COMMAND

    A child process command line.

    CMake executes the child process using operating system APIs directly. All arguments are passed VERBATIM to the child process. No intermediate shell is used, so shell operators such as > are treated as normal arguments. (Use the INPUT_*, OUTPUT_*, and ERROR_* options to redirect stdin, stdout, and stderr.)

命令
    子進程命令行。CMake使用操作系統的APIs直接執行子進程。所有的參數逐字傳遞。沒有中間腳本被使用,所以像>(輸出重定向)這樣的腳本操作符被當作普通參數處理。(使用INPUT_、OUTPUT_、ERROR_那些選項去重定向 stdin、stdout、stderr。)

WORKING_DIRECTORY
    The named directory will be set as the current working directory of the child processes.

工作路徑
    指定的目錄將被設置為子進程的當前工作目錄。

TIMEOUT
    The child processes will be terminated if they do not finish in the specified number of seconds (fractions are allowed).

超時
    子進程如果在指定的秒數內未結束將被中斷(允許使用分數)。

RESULT_VARIABLE
    The variable will be set to contain the result of running the processes. This will be an integer return code from the last child or a string describing an error condition.

結果變量
    變量被設置為包含子進程的運行結果。返回碼將是一個來自於最后一個子進程的整數或者一個錯誤描述字符串。

OUTPUT_VARIABLE, ERROR_VARIABLE
    The variable named will be set with the contents of the standard output and standard error pipes, respectively. If the same variable is named for both pipes their output will be merged in the order produced.

輸出變量,錯誤變量
    命名的變量將被分別設置為標准輸出和標准錯誤管道的內容。如果為2個管道命名了相同的名字,他們的輸出將按照產生順序被合並。

INPUT_FILE, OUTPUT_FILE, ERROR_FILE
    The file named will be attached to the standard input of the first process, standard output of the last process, or standard error of all processes, respectively. If the same file is named for both output and error then it will be used for both.

輸入文件,輸出文件,錯誤文件
    命名的文件將分別與第一個子進程的標准輸入,最后一個子進程的標准輸出,所有進程的標准輸出相關聯。如果為輸出和錯誤指定了相同的文件名,2個都將會被關聯。

OUTPUT_QUIET, ERROR_QUIET
    The standard output or standard error results will be quietly ignored.

輸出忽略,錯誤忽略
    標准輸出和標准錯誤的結果將被靜默地忽略。

If more than one OUTPUT_* or ERROR_* option is given for the same pipe the precedence is not specified. If no OUTPUT_* or ERROR_* options are given the output will be shared with the corresponding pipes of the CMake process itself.

如果為同一個管道指定了多個錯誤和輸出選項,優先級是未知的。如果未指定輸出和錯誤選項,輸出將和cmake進程共享管道。

The execute_process() command is a newer more powerful version of exec_program(), but the old command has been kept for compatibility. Both commands run while CMake is processing the project prior to build system generation. Use add_custom_target() and add_custom_command() to create custom commands that run at build time.

execute_process() 命令是 exec_program()的新的更強大的版本,但是舊命令仍被兼容。這兩個命令運行在cmake處理項目時,構建系統生成器之前。使用add_custom_target()和add_custom_command()創建在構建時運行的自定義命令。

下面的例子經本人測試,如果指定了OUTPUT_FILE,OUTPUT_VARIABLE將無效。
 
cmake_minimum_required(VERSION 3.0)

execute_process(COMMAND touch aaa.jpg
                COMMAND touch bbb.png
                COMMAND ls
                COMMAND grep -E "png|jpg"
                OUTPUT_FILE pics)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM