CMake and MinGW

I used to build my C/C++ toy projects in Code::Blocks, but now I have moved to CLion. And that IDE uses CMake under the hood. It automates all processes (same as Code::Blocks btw), but I was interested how to build my project w/o IDE. CMake has a nice and short tutorial, but it was missing the main point: how to start the build!!! I had to surf Internet for other tutorials for that. One of them gave me some clues. But if you follow it then you may have some interesting troubles. First of all, never run cmake in the source folder! Create a separate folder like “build” and run cmake there. Secondly, if you have MS Visual C++ compiler then cmake will detect it and use it. That wasn’t my goal. So I had to read another tutorial which gave more insight. And then I realized I should have just read cmake –help more carefully 🙂

Anyway here is a short note how to run cmake with MinGW:

mkdir build
cd build
cmake -G "MinGW Makefiles" ..


First of all don’t forget to install CMake from official website (or use choco). Secondly add it to user’s PATH variable. Then you can open command line and go to your project source. CMake generates tons of files and that’s why we better run it in another folder.

Note that running cmake for Linux/MacOS is similar: just use -G “Unix Makefiles” and then make!