# Generator expression to get the generator name?

**URL:** <https://discourse.cmake.org/t/generator-expression-to-get-the-generator-name/5911>\
**Category:** Code\
**Created:** [June 22, 2022, 6:40pm UTC](https://discourse.cmake.org/t/generator-expression-to-get-the-generator-name/5911 "2022-06-22T18:40:01Z")\
**Posts on this page:** 4\
**Page:** 1

<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:** [June 22, 2022, 6:40pm UTC](https://discourse.cmake.org/t/generator-expression-to-get-the-generator-name/5911/1 "2022-06-22T18:40:01Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![kyle.edwards](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/k/65b543/32.png) [@kyle.edwards](https://discourse.cmake.org/u/kyle.edwards)\
**Post date:** [June 22, 2022, 7:01pm UTC](https://discourse.cmake.org/t/generator-expression-to-get-the-generator-name/5911/2 "2022-06-22T19:01:56Z")

</div>

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.

---

<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:** [June 22, 2022, 7:07pm UTC](https://discourse.cmake.org/t/generator-expression-to-get-the-generator-name/5911/3 "2022-06-22T19:07:09Z")

</div>

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.

---

<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:** [June 22, 2022, 9:12pm UTC](https://discourse.cmake.org/t/generator-expression-to-get-the-generator-name/5911/4 "2022-06-22T21:12:21Z")

</div>

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