Skip to content
Latchkey

cmake Configure Command Reference

Generate a build system from CMakeLists.txt into a separate build directory.

The cmake configure step reads CMakeLists.txt and emits a concrete build system (Makefiles or Ninja) into a build directory. It is the first stage of every CMake build.

What it does

cmake configures a project: it detects the compiler and dependencies, evaluates CMakeLists.txt, and generates build files for a chosen generator into the binary directory. Modern usage keeps source and build separate with -S and -B.

Common flags and usage

  • -S DIR -B DIR: source and (separate) build directories
  • -G "Ninja" | "Unix Makefiles": choose the generator
  • -D CMAKE_BUILD_TYPE=Release|Debug: set the build type
  • -D VAR=value: set any cache variable

Example

shell
- name: Configure
  run: cmake -S . -B build -G Ninja -D CMAKE_BUILD_TYPE=Release

In CI

Always configure out-of-source (-B build) so the workspace stays clean and cacheable. Pin the generator and CMAKE_BUILD_TYPE explicitly so every runner produces the same build system rather than relying on platform defaults.

Key takeaways

  • Configure out-of-source with -S . -B build to keep the tree clean.
  • Pin -G and CMAKE_BUILD_TYPE so all runners generate the same build.
  • Set cache variables with -D at configure time.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →