1. 命令
CMake 源码文件
基本上由命令组成。
2. 命令参数
命令调用中由三种类型
的参数
:
- 括号参数
- 带引号的参数
- 不带引号的参数
2.1 括号参数
括号参数
的参数内容
,是左括号 [
跟零个或多个 =
以右括号 ]
结束。
括号参数
,不执行 转义序列
或 变量引用
。
例如:
message([=[
This is the first line in a bracket argument with bracket length 1.
No \-escape sequences or ${variable} references are evaluated.
This is always one argument even though it contains a ; character.
The text does not end on a closing bracket of length 0 like ]].
It does end in a closing bracket of length 1.
]=])
注意: 3.0
之前的 CMake
版本不支持括号参数
。
2.2 带引号的参数
带引号的参数
的参数内容
,在双引号 "
之间 。
例如:
message("This is a quoted argument containing multiple lines.
This is always one argument even though it contains a ; character.
Both \\-escape sequences and ${variable} references are evaluated.
The text does not end on an escaped double-quote like \".
It does end in an unescaped double quote.
")
使用反斜杠 \
,连接行。
message("\
This is the first line of a quoted argument. \
In fact it is the only line but since it is long \
the source code uses line continuation.\
")
注意: 3.0
之前的 CMake
版本不支持继续使用 \
.
2.3 不带引号的参数
参数
用 空格 、分号
;
、换行 \n
分隔不同的参数,如果使用转义字符 \
,并不分隔参数
。
例如:
foreach(arg
NoSpace
Escaped\ Space
This;Divides;Into
Five Arguments
Escaped\;Semicolon
)
message("${arg}")
endforeach()
3. 转义序列
我们通过 \
之后跟一个字符,组成转义序列
。
转义编码
,包括'\t'
、'\r'
、'\n'
转义符号
,包括'\;'
、'\\'
转移序列作为参数的值。
案例: 说明 命令、命令参数、转义序列
cmake_minimum_required(VERSION 3.0.0)
# 1. Bracket Argument
message("======> Bracket Argument")
message([=[
This is the first line in a bracket argument with bracket length 1.
No \-escape sequences or ${variable} references are evaluated.
This is always one argument even though it contains a ; character.
The text does not end on a closing bracket of length 0 like ]].
It does end in a closing bracket of length 1.
]=])
# 2. Quoted Argument
message("======> Quoted Argument")
message("This is a quoted argument containing multiple lines.
This is always one argument even though it contains a ; character.
Both \\-escape sequences and ${variable} references are evaluated.
The text does not end on an escaped double-quote like \".
It does end in an unescaped double quote.
")
# 3. Connecting line
message("======> Connecting line")
message("\
This is the first line of a quoted argument. \
In fact it is the only line but since it is long \
the source code uses line continuation.\
")
# 4. Unquoted Argument
message("======> Unquoted Argument")
foreach(arg
NoSpace
Escaped\ Space
This;Divides;Into
Five Arguments
Escaped\;Semicolon
)
message("${arg}")
endforeach()
# 5. Escape Sequences
message("======> Escape Sequences")
message("
This is the first.\r\n\tline of a quoted argument.
")