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)
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?
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.
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?
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: