1. Introduction

  • It’s a meta-build system generator.
  • How it works:
    • We write high-level instructions in a CMakeLists.txt file (platform-agnostic).Then CMake generates build system files for the platform we choose:
    • On Linux/Unix → generates Makefile (for make) or build.ninja (for ninja).
    • On Windows → generates Visual Studio solutions (.sln).
    • On macOS → can generate Xcode projects.

2. Setup

  • Linux: Install: sudo apt install cmake , Verify: cmake --version

3. How to work with CMake

  1. Create CMakeLists.txt and resources file
  2. Create and cd to project-build folder & Run cmake <dir-contain-CMakeLists.txt> (cmake ../) to set up & generate build system.
  3. Run cmake --build <dir-contain-buildsystem> ( cmake --build ./) to actually build/compile the project.
  4. Run the target build (e.g. ./targetName)

3.1.

CMakeLists.txt

cmake_minimum_required(VERSION 3.0)	// specifying a minimum CMake version
project(CmakeprojectName)	// set the project name
add_executeable(targetName "headerfile.h" "sourcefile1.cpp" "sourcefile2.cpp") // specified source code files