How to install CMake on Windows
CMake is a SCons for automating compilation tasks.
Today we will see how to install CMake on Windows.
Now let’s go step by step!
01. Download CMake by clicking the button below:
After downloading, double-click on the downloaded file:
cmake-3.26.0-rc6-windows-x86_64.msi and give administrator permissions to start the installation setup.
02. Setup presentation
Just click on
03. Accept the license terms
And then click
04. Add CMake to your
Add CMake to the system PATH for all users option for the command to be available to all system users. And then click on
05. Select installation path
Hint: Keep what already appears and click
06. Start the installation
Install and wait for the installation to finish.
Open PowerShell or
CMD and type the command:
If the output is similar to the image below, everything is right and installed perfectly:
Compiling with CMake
Create a folder, for example
MyProject, enter it (by CMD or PowerShell,
cd MyProject) and inside it do:
Create a file named
CMakeLists.txtwith your Preferred Code Editor or IDE and fill it with the code below:
- Also create a
main.cppfile with a basic code, example:
At the end your
MyProject folder will have 2 files:
main.cpp as shown in the image below:
- Now run the command:
It will create a folder called
buildinside your project. If you don’t say
-G "Unix Makefiles"it will prepare files for Visual Studio, in which case we want a Unix-like Makefile.
The output will be similar to the image below:
- Once finished, enter the build folder (
cd build) and run the
makecommand (if this command does not exist, it is because you did not rename the MinGW file to that name as mentioned in the article about MinGW cited above, then most likely the command will be
mingw32-make). And then run the final binary: