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)
相關文章
相關標籤/搜索