How to interpret ;"" in cmake - Stack Overflow

Why does the following CMake script behave the way it does?message(;"")# prints &q

Why does the following CMake script behave the way it does?

message(;"")          # prints ""
message(@"")          # prints @""
message("")           # prints nothing as expected
message("A";"B")      # emits a warning and prints A"B"
message("A"-"B")      # emits a warning and prints A-"B"

The warning reads

[...] Argument not separated from preceding token by whitespace. [...]

Apparently "A";"B" and "A"-"B" are interpreted as a list with two elements but that insight doesn't really get me anywhere.

Why does preceding a double-quoted string with a token without separating them by whitespace causes the double quotes to be part of the string?

I'm using CMake 3.31.6, but I have observed this behavior in less recent CMake versions, too.

Why does the following CMake script behave the way it does?

message(;"")          # prints ""
message(@"")          # prints @""
message("")           # prints nothing as expected
message("A";"B")      # emits a warning and prints A"B"
message("A"-"B")      # emits a warning and prints A-"B"

The warning reads

[...] Argument not separated from preceding token by whitespace. [...]

Apparently "A";"B" and "A"-"B" are interpreted as a list with two elements but that insight doesn't really get me anywhere.

Why does preceding a double-quoted string with a token without separating them by whitespace causes the double quotes to be part of the string?

I'm using CMake 3.31.6, but I have observed this behavior in less recent CMake versions, too.

Share Improve this question asked Mar 21 at 7:52 pasbipasbi 2,1911 gold badge23 silver badges33 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 2

Why does preceding a double-quoted string with a token without separating them by whitespace causes the double quotes to be part of the string?

This is because such argument is treated by CMake as Unquoted Argument. Normally, an unquoted argument doesn't contain double quotes, but is allowed to do that as legacy:

Note: To support legacy CMake code, unquoted arguments may also contain double-quoted strings ("...", possibly enclosing horizontal whitespace), and make-style variable references ($(MAKEVAR)).

That is, argument -"" is interpreted as containing all three non-space symbols: -"".

The argument ;"" is interpreted as containing all three symbols: ;"" too. But in futher processing of the command invocation CMake strips from the unquoted(!) arguments leading and terminating semicolons.


As for warning "Argument not separated from preceding token by whitespace.", it is different issue. The warning tells that the line "A";"B" is treated as two arguments, "A" and ;"B", which should be separated by at least one whitespace character.

It's not a bracket argument or a quoted argument. It's an unquoted argument. Quoting the docs for unquoted arguments:

unquoted_argument ::=  unquoted_element+ | unquoted_legacy
unquoted_element  ::=  <any character except whitespace or one of '()#"\'> |
                       escape_sequence
unquoted_legacy   ::=  <see note in text>

[...] The resulting value is divided in the same way Lists divide into elements. Each non-empty element is given to the command invocation as an argument. Therefore an unquoted argument may be given to a command invocation as zero or more arguments. [...]

To support legacy CMake code, unquoted arguments may also contain double-quoted strings ("...", possibly enclosing horizontal whitespace), and make-style variable references ($(MAKEVAR)).

;"" as a command argument is like a list where the first item is empty, and the second is two-character-long literal "". The empty item is not given to the command invocation.

Here's some more exploration:

function(test)
  message("arg1: ${ARGV0}")
  message("arg2: ${ARGV1}")
  message("arg3: ${ARGV2}")
endfunction()
test(;"")
test(;"" ;"";;;;;;;;;;; ; ; ; ;)
test(a;"")

which prints this:

arg1: ""
arg2: 
arg3: 
arg1: ""
arg2: ""
arg3: 
arg1: a
arg2: ""
arg3:

message("A";"B")      # emits a warning and prints A"B"

See the definition of separation for in the command invocation docs:

separation ::= space | line_ending

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744367883a4570798.html

相关推荐

  • How to interpret ;&quot;&quot; in cmake - Stack Overflow

    Why does the following CMake script behave the way it does?message(;"")# prints &q

    7天前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信