Cmake set variables9/27/2023 ![]() ![]() As a special case, if the opening brackets are immediately followed by a newline, CMake discards that newline.You must match the same number of equal signs at the opening and closing brackets.Bracket syntax uses a pair of square brackets with zero or more equal signs between them.This can be useful when defining strings with CMake code that you don’t want evaluated immediately. CMake will also not substitute variables inside bracket-quoted values. This makes them very handy for defining regular expressions. CMake interprets values quoted with bracket syntax literally, so you do not need to escape quotes or backslashes. With CMake 3.0 or later, you can use lua-style bracket syntax instead of surrounding the value with double-quotes. You can express a value with embedded quotes more clearly by quoting the whole string and escaping the embedded quotes with a backslash: set(args "something=\"I contain spaces\"" anotherArg) Quoting With Bracket Syntax The output from the above would be: arg: something="unexpected perhaps" Set(args something="unexpected perhaps" anotherArg) # Relies on legacy behavior, don't do this You should avoid using unescaped quotes anywhere other than the start and end of a value. CMake’s documentation warns that this is legacy behavior. The quotes do still prevent spaces from acting as argument separators. If a value does not start with double-quotes, any double-quotes after the first character become part of the value. Some languages support quoting that starts part way through a value, but CMake’s handling of such arguments is different to most. add_library(MyThings STATIC someFile.cpp "I need quotes.cpp") Directory separators do not require quoting. However, you only need quotes if the file name contains whitespace or semicolons (and file names should never contain semicolons, since they would almost certainly lead to other problems). To demonstrate, the following are all equivalent: add_library(MyThings STATIC someFile.cpp)Īdd_library(MyThings STATIC "someFile.cpp")Īdd_library("MyThings" "STATIC" "someFile.cpp")ĭevelopers often feel the need to treat file names and paths specially, often adding quotes when not required. It is up to the command’s implementation to give those strings meaning as keywords. We might think of those as being special, but from CMake’s point of view, they too are just strings. ![]() In fact, much of the time, you can pass strings to commands without quoting. Unlike many scripting languages, CMake doesn’t always require strings to be quoted. ![]() Command Arguments From Substituted Content. ![]()
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |