How to split strings across multiple lines in CMake?

后端 未结 7 1592
花落未央
花落未央 2021-01-06 19:03

I usually have a policy in my project, to never create lines in text files that exceed a line length of 80, so they are easily editable in all kinds of editors (you know the

7条回答
  •  难免孤独
    2021-01-06 19:18

    The example in the original question is only about a relatively short string. For longer strings (including the examples given in other answers), a bracket argument could be better. From the documentation:

    An opening bracket is written [ followed by zero or more = followed by [. The corresponding closing bracket is written ] followed by the same number of = followed by ]. Brackets do not nest. A unique length may always be chosen for the opening and closing brackets to contain closing brackets of other lengths.

    [...]

    For example:

    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.
    ]=])```
    

提交回复
热议问题