Is whitespace in quoted generator expressions allowed?

I have a long, complex, quoted generator expression that I’d like to make more readable with whitespace, as well as splitting across several lines. For example:

        $<NOT: $<BOOL:${MYPROJ_KNOB_NO_JSON}> >,\
        "$< $<BOOL:${MYPROJ_LINK_TO_JSON_ENABLED}>: SomeJsonLib::SomeJsonLib >")

where MYPROJ_KNOB_NO_JSON is a cache variable that can be set by the user to disable the JSON feature of my library.

Compare to the same without whitespace in the generator expressions:


I’d like to know if the first version with the whitespace is acceptable. The manual doesn’t mention anything about whitespace within generator expressions, and web searches have not come up with any answers (only problems related to forgetting to quote the expression).

BTW, the reason why I skip linking RapidJSON::rapidjson if it doesn’t exist (due to a prior find_package(RapidJSON) call failing), is that I want the configuration stage to continue running to completion so that the user may change the configuration via cmake-gui or their IDE. This also allows IDEs to list source files even when the dependencies are not found, thus allowing someone to peruse the source code in an IDE without having to first install the dependencies.

If there’s a cleaner way to achieve what I’m looking for, I’m open to suggestions.

UPDATE: Sorry, I thought that attempting to link to a non-existent SomeJsonLib::SomeJsonLib target results in configuration failure, but I was mistaken. My main question about whitespace within generator expressions still stands, though.

Well, I tried and it seems that CMake doesn’t like spaces in generator expressions:

Error evaluating generator expression:

    $<NOT: $<BOOL:OFF> >

  $<NOT> parameter must resolve to exactly one '0' or '1' value.

I think the best I can do is something like:


It seems I answered my own question. :slight_smile:

It turns out I was not mistaken. Attempting to link a non-existent target does result in configuration failure. Sorry for the confusion.