# Is whitespace in quoted generator expressions allowed?

**URL:** https://discourse.cmake.org/t/is-whitespace-in-quoted-generator-expressions-allowed/5473
**Category:** Usage
**Created:** [April 16, 2022, 2:03am UTC](https://discourse.cmake.org/t/is-whitespace-in-quoted-generator-expressions-allowed/5473 "2022-04-16T02:03:05Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![ecorm](https://discourse.cmake.org/user_avatar/discourse.cmake.org/ecorm/32/2351_2.png) [@ecorm](https://discourse.cmake.org/u/ecorm)
#### Post date: [April 16, 2022, 2:03am UTC](https://discourse.cmake.org/t/is-whitespace-in-quoted-generator-expressions-allowed/5473/1 "2022-04-16T02:03:06Z")

</div>

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:

```cmake
set(MYPROJ_LINK_TO_JSON_ENABLED
    "$<AND:\
        $<NOT: $<BOOL:${MYPROJ_KNOB_NO_JSON}> >,\
        $<TARGET_EXISTS:SomeJsonLib::SomeJsonLib>\
      >")
target_link_libraries(mylib
    PRIVATE
        "$< $<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:

```cmake
set(MYPROJ_LINK_TO_JSON_ENABLED
    "$<AND:$<NOT:$<BOOL:${MYPROJ_KNOB_NO_JSON}>>,$<TARGET_EXISTS:SomeJsonLib::SomeJsonLib>>")
target_link_libraries(mylib
    PRIVATE
        "$<$<BOOL:${MYPROJ_LINK_TO_JSON_ENABLED}>:SomeJsonLib::SomeJsonLib>")

```

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.

---

<div class="post-metadata">

### Author: ![ecorm](https://discourse.cmake.org/user_avatar/discourse.cmake.org/ecorm/32/2351_2.png) [@ecorm](https://discourse.cmake.org/u/ecorm)
#### Post date: [April 16, 2022, 2:52am UTC](https://discourse.cmake.org/t/is-whitespace-in-quoted-generator-expressions-allowed/5473/2 "2022-04-16T02:52:09Z")

</div>

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

```nohighlight
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:

```cmake
string(APPEND MYPROJ_LINK_TO_JSON_ENABLED
    "$<AND:"
        "$<NOT:$<BOOL:${MYPROJ_KNOB_NO_JSON}>>,"
        "$<TARGET_EXISTS:SomeJsonLib::SomeJsonLib>"
     ">")

```

It seems I answered my own question. 🙂

---

<div class="post-metadata">

### Author: ![ecorm](https://discourse.cmake.org/user_avatar/discourse.cmake.org/ecorm/32/2351_2.png) [@ecorm](https://discourse.cmake.org/u/ecorm)
#### Post date: [April 19, 2022, 10:38pm UTC](https://discourse.cmake.org/t/is-whitespace-in-quoted-generator-expressions-allowed/5473/3 "2022-04-19T22:38:05Z")

</div>

> [@ecorm](#):
>
> Sorry, I thought that attempting to link to a non-existent `SomeJsonLib::SomeJsonLib` target results in configuration failure, but I was mistaken.

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