Generator expression to get the generator name?

Is there a generator expression that evaluates to the name of the CMake generator being used? If not, is there a reason why not?

There is no such generator expression, but in general it shouldn’t be necessary, because the generator can’t be changed, and is known right from the beginning of CMakeLists.txt in the ${CMAKE_GENERATOR} variable. I would suggest using that.

1 Like

I see. The reason I was asking is, part of my understanding of generator expressions is that it allows you to specify configuration logic that is evaluated at generation time, and not during scripting time – so if you specify some properties for a target only for a certain compiler using generator expressions, then the exported CMake files can be loaded by another project and the configuration of the target would still be correct regardless of the compiler being used. I was hoping to apply this to the generator as well.

Projects should not care what generator consumers use; they should (ideally) work regardless.