cmakecmake-language

How to interpret ;"" in cmake


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.


Solution

  • 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.