cmake howto - MarekBykowski/readme GitHub Wiki

Invoking cmake

Use make generator

cmake -G "UNix Makefiles" -DCMAKE_BUILD_TYPE=Release -S <source_path> -B <build_path>

Then you can either run make from the build_path or from the top dir using cmake

cd <build_path>; make

or

cmake --build <build_path>

Use Ninja generator

cmake -G "Ninja" -DCMAKE_BUILD_TYPE=Release -S <source-path> -B <build_path>

Then build

cd <build_path>; ninja
cmake --build <build_path>

Complete hello world example

main.cpp is

#include <stdio.h>
int main(int argc, char** argv){
	printf("Hello World\n");
	return 0;
}

CMakeLists.txt is

project(HelloWorld)
cmake_minimum_required(VERSION 3.0)
add_executable(hello_world main.cpp)

Build and run

cmake -G "UNix Makefiles" -DCMAKE_BUILD_TYPE=Release -S . -B ./build
cmake --build ./build
cd ./build; ./hello_world
⚠️ **GitHub.com Fallback** ⚠️