# Setting Default Generators

**URL:** https://discourse.cmake.org/t/setting-default-generators/1315
**Category:** Development
**Tags:** os:macos, os:linux, os:windows
**Created:** [June 3, 2020, 3:20pm UTC](https://discourse.cmake.org/t/setting-default-generators/1315 "2020-06-03T15:20:53Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![UebelAndre](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/u/85f322/32.png) [@UebelAndre](https://discourse.cmake.org/u/UebelAndre)
#### Post date: [June 3, 2020, 3:20pm UTC](https://discourse.cmake.org/t/setting-default-generators/1315/1 "2020-06-03T15:20:53Z")

</div>

Is there a way to set default generators for your project? I haven’t seen any such functionality but it would be hugely beneficial to be able to do this.  
Example:  
cmake (path to project dir)

Vs  
cmake -G ‘Visual Studio 16 2019’ -A x64 (path to project dir)

---

<div class="post-metadata">

### Author: ![marc.chevrier](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/ecb155/32.png) [@marc.chevrier](https://discourse.cmake.org/u/marc.chevrier)
#### Post date: [June 3, 2020, 3:28pm UTC](https://discourse.cmake.org/t/setting-default-generators/1315/2 "2020-06-03T15:28:52Z")

</div>

Have a look at the environment variable [CMAKE\_GENERATOR](https://cmake.org/cmake/help/latest/envvar/CMAKE_GENERATOR.html#envvar:CMAKE_GENERATOR).

---

<div class="post-metadata">

### Author: ![UebelAndre](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/u/85f322/32.png) [@UebelAndre](https://discourse.cmake.org/u/UebelAndre)
#### Post date: [June 3, 2020, 5:55pm UTC](https://discourse.cmake.org/t/setting-default-generators/1315/3 "2020-06-03T17:55:17Z")

</div>

Does that work if it’s set from within a CMakeLists.txt file? My understanding is that you’d have to generate a project, where that would then be set and regenerate the desired project. Is this true?

---

<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 3, 2020, 6:06pm UTC](https://discourse.cmake.org/t/setting-default-generators/1315/4 "2020-06-03T18:06:18Z")

</div>

You cannot set the generator from inside the project. The generator is chosen by the user, not the upstream developer. The most you could do is issue a `message(FATAL_ERROR)` if the generator is not supported.

---

<div class="post-metadata">

### Author: ![greatwolf](https://discourse.cmake.org/user_avatar/discourse.cmake.org/greatwolf/32/4799_2.png) [@greatwolf](https://discourse.cmake.org/u/greatwolf)
#### Post date: [July 25, 2024, 12:56am UTC](https://discourse.cmake.org/t/setting-default-generators/1315/5 "2024-07-25T00:56:09Z")

</div>

Sorry for resurrecting an old thread but I have a similar question. Is there no way to change the default cmake generator to something else if the user omits it during invocation? eg. for example, making cmake use mingw makefile in windows instead of nmake?

---

<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: [July 25, 2024, 3:45pm UTC](https://discourse.cmake.org/t/setting-default-generators/1315/6 "2024-07-25T15:45:10Z")

</div>

Well, nmake versus the mingw makefile generator depends heavily on the toolchain in use. It needs to be known before `project()` is called (well, any languages) for sure, but the best thimg to do is:

> [@kyle.edwards](#):
>
> The generator is chosen by the user, not the upstream developer. The most you could do is issue a `message(FATAL_ERROR)` if the generator is not supported.
