Caio Wakamatsu

CMake from scratch / Chapter 1

What is CMake?

CMake, like many tools in software engineering, solves a problem. The problem CMake solves is cross-platform (Windows, MacOs, *nix)1 C++ compilation and project definition.

What does CMake let you do?

CMake lets you provide a high level description of your C++ project, and hide all of the platform specific shenanigans from you. 2

The basic flow

  1. You create a CMakeLists.txt at the root of your project3, write all of your dependencies, source files, and flags.
  2. Tell CMake to configure your project’s CMakeLists.txt
  3. Tell CMake to build your program

Footnotes

  1. Technically, it’s also for cross-toolchain (Eg; gcc & clang on the same host system, Make / Ninja, etc…)

  2. In quite a few situations where CMake gets more advanced, you end up having to deal with platform specific code anyways.

  3. In reality, CMake doesn’t particularly care about where you place source files / CMakeLists.