參考CMake官方文檔:https://cmake.org/cmake/help/v3.14/command/set.html
1. 普通變量
set(<variable> <value>... [PARENT_SCOPE])
設置變量<variable> 的值為 <value>
如果后面增加了 PARENT_SCOPE 選項的話, 表示 在上層作用域/目錄 設置<variable> 的值為 <value>, 但是當前作用域/目錄 該<variable> 的值不變。
2. 設置緩存條目
set(<variable> <value>... CACHE <type> <docstring> [FORCE])
設置給定的緩存變量<variable> 的值為 <value>.
由於緩存項旨在提供用戶可設置的值,因此默認情況下不會覆蓋現有緩存項。使用FORCE選項覆蓋現有條目。
<type> 必須是下列類型之一:
-
BOOL
-
Boolean
ON/OFF
value. -
FILEPATH
- 文件路徑.
-
PATH
- 目錄路徑.
-
STRING
-
一行文本.
cmake-gui(1)
offers a text field or a drop-down selection if theSTRINGS
cache entry property is set. -
INTERNAL
-
一行文本.
cmake-gui(1)
does not show internal entries. They may be used to store variables persistently across runs. Use of this type impliesFORCE
.
The <docstring>
must be specified as a line of text providing a quick summary of the option for presentation to cmake-gui(1)
users.
3. 設置環境變量
set(ENV{<variable>} [<value>])
設置環境變量<variable>的值為<value>. 后面使用 $ENV{<variable>}
可以獲取該值.
This command affects only the current CMake process, not the process from which CMake was called, nor the system environment at large, nor the environment of subsequent build or test processes.
If no argument is given after ENV{<variable>}
or if <value>
is an empty string, then this command will clear any existing value of the environment variable.
Arguments after <value>
are ignored. If extra arguments are found, then an author warning is issued.