Verbose format for generator expressions?

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 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.

For reference, generator expressions are not part of the cmake-language(7). 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.

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

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.

Agreed. See for example, this code and the later usages of these variables.