Post

CMake - Installation On Windows

Here is a quick way to get started into development with CMake on Windows x64.

1. Getting Started

1.1. Downloads

  • Download MinGW64 (posix, seh, msvcrt) from here.
  • Download CMake (Windows x64) from here.

1.2. Installation

  • Install CMake in C:\Program Files\Cmake.
  • Copy the minGW64 folder into C:\.
  • Add the following binary paths to the PATH variable:
    • C:\minGW64\bin
    • C:\Program Files\Cmake\bin

1.3. First Project

  • The simplest project to build is a Hello world program. Hence we will add a main.cpp source:
#include <iostream>

int main() {
    std::cout << "Hello World!\n";
    return 0;
}
  • The corresponding cmake instruction would be the file CMakeLists.txt:
cmake_minimum_required(VERSION 3.10)

# Project Name
project(HelloWorld)

# Add an executable with sources
add_executable(
    ${PROJECT_NAME} main.cpp
)
  • To build the project now you should run the following commands
# compile
mkdir build
cd build
cmake .. -G "MinGW Makefiles"   # Makefile for minGW
mingw32-make

# clean
cd ..
rmdir /s /q build

2. More

This post is licensed under CC BY 4.0 by the author.