Skip to content

Intro to Cmake

CMake is an open-source build system introduced by developers & engineers at Kitware in 2000 as a part of the Visible Human Project managed by the National Library of Medicine (NLM). CMake is typically used for C and C++ projects. Naturally, this also includes many embedded software/systems projects.

What separates CMake from something like make is that CMake is not directly responsible for producing the compiled artifacts. In essence, CMake produces the configuration for tools like make and ninja which then can use that template to produce the desired artifacts.

NOTE: You may hear some developers refer to CMake as a meta build system.

(TODO) Topology/Hierarchy/Architecture

How Does CMake Work

We shall build on these principles more in the following guides but lets establish some fundamentals now.

  1. You will write most commands and instructions in CMakeLists.txt files. The CMakeLists.txt is what determines what artifacts of your project shall be compiled and linked. You will likely see multiple of these files spread across the project at both the top-level directory and in multiple subfolders.

NOTE: At a minimum, every CMake project shall have at least one CMakeLists.txt file which will likely be in the top-level directory of your project.

  1. CMake has it's own language (affenctionately refered to as the CMake Language). While we won't cover all the features of it, for the most part, it has similar constructs to regular programming languages and other build systems (i.e. variables, conditionals, libraries, targets, etc.)

  2. (TODO Insert 3rd point)

Why CMake

We noted that there are multiple options for build systems so why consider CMake? This is not a complete list but here are a few features that we've come to appreciate during out time with the tool:

  1. Cross-platofrm - CMake is usable on Windows, Mac OS, and most Linux distributions
  2. Extensible - It's extremely easy to integrate tooling such as Doxygen with your build process through CMake
  3. Consistency - Getting reproducible and consistent builds between developers and students has been easier after integrating a build system
  4. Testing integration - CMake tends to play well with unit/module tests with through it's testing tool CTest