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
| |
| mkdir build |
| cd build |
| cmake .. -G "MinGW Makefiles" |
| mingw32-make |
| |
| |
| cd .. |
| rmdir /s /q build |
2. More