0

I'm trying to learn CMake so I started with the tutorial on their website. Some functioniality like versioning with .h.in files I couldn't get to work in Visual Studio so I decided to just use CMD and CMake. Due to VS being installed CMake defaulted to creating a VS solution, after uninstalling VS it now defaults to NMake Makefiles. I want to use the MinGW generator. I know I can pass this by using the -G flag but I would like to make this to CMake's default behavior.

So that: cmake . would behave the same as cmake -G "MinGW Makefiles" .

I've tried the solution suggested here but it seems to not work. Setting default compiler in CMake

Maybe I set the environtment variable wrong I don't know. Here is how I proceeded:

  1. open CMake GUI
  2. open the Environment Tab
  3. add new Entry
  4. set name to CMAKE_GENERATOR
  5. set value to MinGW Makefiles
  6. press OK

But still if I create a new project and run CMake it still defaults to the NMake generator. Do you have any suggestions.

Fatih
  • 1
  • 1
  • After changing your OS environment variable did you logoff and login? Or did you do set the environment variable in a cmd.exe window and run cmake from that window? If so did you delete the CMakeCache.txt file from a previous configure? – drescherjm Mar 22 '22 at 14:26
  • ***But still if I create a new project and run CMake it still defaults to the NMake generator*** The environment tab only affects the current instance of CMake-Gui. – drescherjm Mar 22 '22 at 14:29
  • 1
    The value you entered in the cmake GUI only applies to the cmake build directory you were working on at the time, you need to set an OS environment variable – Alan Birtles Mar 22 '22 at 14:30
  • See here: [https://phoenixnap.com/kb/windows-set-environment-variable](https://phoenixnap.com/kb/windows-set-environment-variable) – drescherjm Mar 22 '22 at 14:31

2 Answers2

1
  1. Open the Control Panel
  2. Search for and open "Environment Variables"
  3. Click "New..."
  4. Variable name: CMAKE_GENERATOR
  5. Variable value: MinGW Makefiles
  6. Click ok -> Click Ok
  7. Restart your Terminal
  8. Generate your Makefiles ~\build cmake ..
Agent49
  • 133
  • 1
  • 11
0

I had to create the CMAKE_GENERATOR variable in the Windows environment variables not in CMake.

genpfault
  • 51,148
  • 11
  • 85
  • 139
Fatih
  • 1
  • 1
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 23 '22 at 10:19