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
- name: Configure
run: cmake -S . -B build -G Ninja -D CMAKE_BUILD_TYPE=ReleaseIn 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.