Site Tools


cmake

Table of Contents

CMake

CMake is a build system generator. It reads a project description in CMakeLists.txt and generates native build files (Makefiles, Ninja, Visual Studio projects, etc.) for your platform. This solves portability—describe targets and dependencies abstractly, and CMake generates platform-specific build recipes.

CMake is the de facto standard in HPC, embedded, and scientific computing. Most numerical libraries (Eigen, OpenCV, CUDA, MPI) ship with CMakeLists.txt and expect to be consumed via find_package. Knowing CMake is about reading and extending others' build scripts, not writing elaborate ones from scratch.

$ mkdir build && cd build       # out-of-source build
$ cmake ..                      # generate build system
$ cmake --build .               # invoke generator (make, ninja, ...)
$ cmake --build . --target test # run tests

CMake separates configuration (reading CMakeLists.txt, finding libraries) from building. The configuration step generates build files; the build step invokes the underlying tool. This two-step process lets you use the same CMakeLists.txt with different generators.

Concepts

  1. Basics
  2. CMakeLists.txt
  3. Projects and targets
  4. Executables and libraries
  5. Variables
  6. Conditionals and loops
  7. Functions and macros
  8. Finding dependencies
  9. Linking
  10. Installation
  11. Testing
  12. Generators
  13. Modern practices
  14. Subdirectories
cmake.md · Last modified: