[cmake-developers] conditionals in generator expressions

Stephen Kelly steveire at gmail.com
Mon Sep 3 13:05:15 EDT 2012


Brad King wrote:

> On 08/31/2012 07:21 AM, Stephen Kelly wrote:
>> The above is not necessary. It can instead be literally:
>> 
>>   "$<$<CONFIG:Debug>:-Wl,no-undefined>"
>>   "$<$<AND:$<CONFIG:Debug>,$<STREQUAL:$<TGT_PROP:FOO>,b>>:-Wl,no-
undefined>"
>> 
>> The comma is ambiguous to the parser, but not to the generator
>> expression. I've updated my -refactor branch to deal with it.
> 
> Okay.  The branch looks like a good start so far.  It will need to
> be re-formatted into a clean patch series

Yes.

> but let's focus on the
> net change for now.
> 
>> my preference is to keep the existing design in next, and add something
>> similar to the parser now in my branch.
> 
> Okay.  The "always-:" syntax leaves the door open for the
> whitespace/quoting approach in the future anyway.
> 
> In your branch why do you create separate helper classes for each
> expression type but then use manual dispatch while evaluating the
> parse tree?  Doesn't this beg for virtual dispatch during eval?

Yes. The separate helper classes are a left-over from wanting to use virtual 
dispatch from the start, but finding it not-possible as I went on. 

I based this stuff on the design of the Grantlee lexer/parser, but the major 
difference is that Grantlee knows the nodes at parse-time:

  {% if foo %}bar{% endif %}

I can create an IfNode there.

With the CMake generator expressions, I don't know the nodes at parse time, 
because 'if' is not literal in that sub-language. Everything is a lazily-
evaluated node. At least from the language point of view, one could do this:

  $<$<STREQUAL:$<TARGET_FILE$<CONFIG:Release:_DIR>>,BAT>:/some/include>

To mean:

* If Config is Release and TARGET_FILE_DIR is BAT, include /some/include
* If Config is not Release and TARGET_FILE is BAT, include /some/include
* Otherwise don't include /some/include

I don't know at parse time whether to create a node for TARGET_FILE_DIR or 
TARGET_FILE. I only know that at evaluation time, so I can't create the 
nodes at parse time and use virtual dispatch at evaluation time.

So now that we've agreed on the language, and unless I've missed something, 
I'll refactor that code to use helper methods rather than helper classes and 
generally clean up and rewrite the branch.

Thanks,

Steve.





More information about the cmake-developers mailing list