CMake文档(例如当前版本3.11.2)状态
使用简单的标记语言显示CMake警告和错误消息文本。非缩进文本以换行符分隔的换行段落的格式设置。缩进的文本被认为是预格式化的。
但是,它没有提及任何标记格式。除非是“非缩进”还是“缩进”,否则都将涉及“简单标记”。
无论如何,我无法使其与FATAL_ERROR模式一起使用。
此外,我注意到with STATUSmode消息打印有前导--(两个破折号和空格)。而与FATAL_ERROR在该消息中的每个换行变成两条线,其中(IMHO)看上去可怕。
现在,我有一条多行消息,其中列出了错误所在CMAKE_BUILD_TYPE和可接受的值。由于上述问题,我最终将消息打印为,STATUS并在随后的行中缩进了三个空格(因此它们与对齐--)。然后,我FATAL_ERROR仅重复一个简单的“标题行”(说明CMAKE_BUILD_TYPE错误)。控制台输出和都可以接受cmake-gui。(尽管在cmake-gui... 上不需要3个空格缩进)
但是,我很惊讶地描述了这个主题。似乎已经很久了-例如,请参阅问题[CMake]带有SEND_ERROR和FATAL_ERROR的多余空白行吗?至今仍未解决将近9年...
是否有处理此类消息的良好实践,建议或技巧?还是应该首先避免使用它们?
你是对的。“简单标记”可以是非缩进(未格式化)或缩进(格式化)的。同样,非缩进文本在换行符分隔的段落中。这就是为什么您在段落之间以空白行结尾的原因。
这是各种消息的运行说明。警告类型和错误类型在格式化和未格式化文本方面表现相同。当然,区别在于CMake的处理和生成阶段会发生什么。为了提高可读性,您可以将字符串拆分为多个双引号,并将其串联起来。
# STATUS
message(STATUS
"This is a status message. It is prefixed with \"-- \". It goes to stdout. The "
"lines will wrap according to the width of your terminal.\n"
"New lines will begin a new line at column 1, but without the \"-- \" prefix, "
"unless you provide it; they will not create a blank line (i.e., new "
"paragraph). Spacing between sentences is unaltered by CMake.\n"
"-- Here's a new paragraph with an explicit \"-- \" prefix added.")
# no mode given (informational)
message(
"This is an informational message. It goes to stderr. Each line begins at column "
"1. The lines will wrap according to the width of your terminal.\n"
"New lines will begin a new line at column 1; they will not create a blank line "
"(i.e., new paragraph). Spacing between sentences is unaltered by CMake (3 spaces "
"preceded this sentence.).")
# WARNING--unformatted
message(WARNING
"This is an unformatted warning message. It goes to stderr. Each line begins "
"at column 3. The lines will wrap at a particular column (it appears to be "
"column 77, set within CMake) and wrap back to column 3.\n"
"New lines will begin a new paragraph, so they will create a blank line. A final "
"thing about unformatted messages: They will separate sentences with 2 spaces, "
"even if your string had something different.")
# WARNING--formatted and unformatted
message(WARNING
" This is a formatted warning message. It goes to stderr. Formatted lines will"
" be indented an additional 2 spaces beyond what was provided in the output"
" string. The lines will wrap according to the width of your terminal.\n"
" Indented new lines will begin a new line. They will not create a blank line."
" If you separate sentences with 1 space, that's what you'll get. If you"
" separate them with 2 spaces, that's also what you'll get.\n"
" If you want to control the width of the formatted paragraphs\n"
" (a good practice), just keep track of the width of each line and place\n"
" a \"\\n\" at the end of each line.\n \n"
" And, if you want a blank line between paragraphs, just place \"\\n \\n\"\n"
" (i.e., 2 newlines separated by a space) at the end of the first paragraph.\n"
"Non-indented new lines, however, will be treated like unformatted warning "
"messages, described above. They will begin at and wrap to column 3. They begin "
"a new paragraph, so they will create a blank line. There will be 2 spaces "
"between sentences, regardless of how many you placed after the period (In the "
"script, there were 4 spaces before this sentence).\n"
"And, as you'd expect, a second unindented paragraph will be preceded by a "
"blank line. But why would you mix formatted and unformatted text?")
Run Code Online (Sandbox Code Playgroud)
我将其保存到Message.cmake中,并使用调用了它cmake -P Message.cmake 2> output.txt。结果为以下标准输出:
-- This is a status message. It is prefixed with "-- ". It goes to stdout. The lines will wrap according to the width of your terminal.
New lines will begin a new line at column 1, but without the "-- " prefix, unless you provide it; they will not create a blank line (i.e., new paragraph). Spacing between sentences is unaltered by CMake.
-- Here's a new paragraph with an explicit "-- " prefix added.
Run Code Online (Sandbox Code Playgroud)
文件output.txt包含:
This is an informational message. It goes to stderr. Each line begins at column 1. The lines will wrap according to the width of your terminal.
New lines will begin a new line at column 1; they will not create a blank line (i.e., new paragraph). Spacing between sentences is unaltered by CMake (3 spaces preceded this sentence.).
CMake Warning at MessageScript.cmake:19 (message):
This is an unformatted warning message. It goes to stderr. Each line
begins at column 3. The lines will wrap at a particular column (it appears
to be column 77, set within CMake) and wrap back to column 3.
New lines will begin a new paragraph, so they will create a blank line. A
final thing about unformatted messages: They will separate sentences with 2
spaces, even if your string had something different.
CMake Warning at MessageScript.cmake:28 (message):
This is a formatted warning message. It goes to stderr. Formatted lines will be indented an additional 2 spaces beyond what was provided in the output string. The lines will wrap according to the width of your terminal.
Indented new lines will begin a new line. They will not create a blank line. If you separate sentences with 1 space, that's what you'll get. If you separate them with 2 spaces, that's also what you'll get.
If you want to control the width of the formatted paragraphs
(a good practice), just keep track of the width of each line and place
a "\n" at the end of each line.
And, if you want a blank line between paragraphs, just place "\n \n"
(i.e., 2 newlines separated by a space) at the end of the first paragraph.
Non-indented new lines, however, will be treated like unformatted warning
messages, described above. They will begin at and wrap to column 3. They
begin a new paragraph, so they will create a blank line. There will be 2
spaces between sentences, regardless of how many you placed after the
period (In the script, there were 4 spaces before this sentence).
And, as you'd expect, a second unindented paragraph will be preceded by a
blank line. But why would you mix formatted and unformatted text?
Run Code Online (Sandbox Code Playgroud)
摘要
信息性消息(未提供模式)
状态讯息
未格式化的警告和错误消息(字符串缩进)
格式化的警告和错误消息(缩进的字符串)
| 归档时间: |
|
| 查看次数: |
1658 次 |
| 最近记录: |