[CMake] New type of cache variable: lists

David Cole david.cole at kitware.com
Fri Dec 9 10:27:39 EST 2011


On Fri, Dec 9, 2011 at 9:59 AM, Robert Dailey <rcdailey at gmail.com> wrote:
>
> On Thu, Dec 8, 2011 at 7:59 PM, David Cole <david.cole at kitware.com> wrote:
>>
>> Well, nearly....
>>
>> You'll have to double-quote the "${documentation}" inside the function
>> in case it is the empty string...
>
>
> Or if it has spaces in it, right? Any time I have a string with spaces in
> it, or that could have spaces in it, I use quotes so the value of the string
> doesn't get interpreted as multiple parameters (like a list)
>

No, in this case, it's just in case it's empty because the CACHE form
of set expects to get the type and the docstring following the CACHE
keyword. If ${documentation} evaluates to the empty string, then the
set command only "sees" 4 arguments and yields an error.

The example CMakeLists file did have spaces in the documentation
strings, but they worked just fine.

In the case of set, the 5th argument can be ${documentation} or
"${documentation}" as long as it's non-empty, and the results are
equivalent. But if it's empty, the double-quoted form must be used.

CMake's parser is the thing that splits at space boundaries when
evaluating what to send into the set command. But since the actual
literal code ${documentation} does not have spaces in it, it's full
value (including any spaces in the value) get sent into the set
command internally as arg 5.

Understanding when you have to quote things is simply one of the
hardest things to grok when dealing with CMake language code. Stick
with it, though. It's easier than learning git. It only took me about
2 years of practice before I think something snapped into place in my
brain...


David


More information about the CMake mailing list