# Verbose format for generator expressions?

**URL:** https://discourse.cmake.org/t/verbose-format-for-generator-expressions/10284
**Category:** Development
**Created:** [March 5, 2024, 1:19am UTC](https://discourse.cmake.org/t/verbose-format-for-generator-expressions/10284 "2024-03-05T01:19:04Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![dabrahams](https://discourse.cmake.org/user_avatar/discourse.cmake.org/dabrahams/32/4265_2.png) [@dabrahams](https://discourse.cmake.org/u/dabrahams)
#### Post date: [March 5, 2024, 1:19am UTC](https://discourse.cmake.org/t/verbose-format-for-generator-expressions/10284/1 "2024-03-05T01:19:04Z")

</div>

It’s gotten to the point where generator expressions are their own little programming language. They’re super-powerful, which is great, but it doesn’t take a very complex generator expression before the syntax becomes overwhelming. A similar phenomenon occurs with regular expressions in many contexts, which has prompted many languages to add a “verbose” format that allows comments and insertion of whitespace to help the reader ([here’s](https://docs.python.org/3/library/re.html#re.X) a simple example from Python). Has any thought been given to something similar for CMake generator expressions?

For CMake, I’d probably just make a special “verbose string” type, and let generator expression support fall out of that.

---

<div class="post-metadata">

### Author: ![brad.king](https://discourse.cmake.org/user_avatar/discourse.cmake.org/brad.king/32/11_2.png) [@brad.king](https://discourse.cmake.org/u/brad.king)
#### Post date: [March 5, 2024, 2:05pm UTC](https://discourse.cmake.org/t/verbose-format-for-generator-expressions/10284/2 "2024-03-05T14:05:50Z")

</div>

For reference, generator expressions are not part of the [cmake-language(7)](https://cmake.org/cmake/help/v3.29/manual/cmake-language.7.html). During configuration they are carried inside string arguments, just like regular expressions are in C++. Some projects have developed conventions for constructing generator expression strings from smaller blocks, e.g., using `string(CONCAT)`.

I’m not interested in adding another generator expression representation.

---

<div class="post-metadata">

### Author: ![benthevining](https://discourse.cmake.org/user_avatar/discourse.cmake.org/benthevining/32/1924_2.png) [@benthevining](https://discourse.cmake.org/u/benthevining)
#### Post date: [March 5, 2024, 7:55pm UTC](https://discourse.cmake.org/t/verbose-format-for-generator-expressions/10284/3 "2024-03-05T19:55:16Z")

</div>

I believe you currently can insert whitespace, and even newlines, between the `<` and `>` of a generator expression.

---

<div class="post-metadata">

### Author: ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)
#### Post date: [March 5, 2024, 9:06pm UTC](https://discourse.cmake.org/t/verbose-format-for-generator-expressions/10284/4 "2024-03-05T21:06:44Z")

</div>

There are a few special cases where that’s true, but it isn’t true in enough cases that personally I don’t recommend using or relying on these special cases at all. It is all too easy to write an expression that silently gets interpreted completely differently to what you intended. I have seen users asking for help precisely because of this many times.

Instead, for more complex generator expressions, define them in smaller pieces and build them up with some helper variables. You can then add comments and whitespace around those `set(...)` commands as desired, and the names of the helper variables also assist with understanding the expression.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [March 29, 2024, 11:32am UTC](https://discourse.cmake.org/t/verbose-format-for-generator-expressions/10284/5 "2024-03-29T11:32:48Z")

</div>

Agreed. See for example, [this code](https://gitlab.kitware.com/vtk/vtk/-/blob/5bc81c620ce7ffd3f9dea141095cdc5092959826/Utilities/Python/CMakeLists.txt#L125-128) and the later usages of these variables.
