What this thread does
Do first: choose the generator, then configure single-config Ninja with cmake -S . -B build-debug -G Ninja -DCMAKE_BUILD_TYPE=Debug or select a multi-config build with --config.
Short answer
As of November 2026, CMake 4.5.1 is the stable release reference. Single-config generators select configuration while configuring; multi-config generators select it while building and ignore CMAKE_BUILD_TYPE (build configurations). Set the intended configuration explicitly rather than relying on a generator/toolchain default.
Choose / don't choose
- Single-config Ninja/Makefiles: choose a separate directory per build type; don't expect
--config Releaseto transform a tree configured as Debug. - Visual Studio, Xcode or Ninja Multi-Config: choose
--config <cfg>to choose the configuration; don't use CMAKE_BUILD_TYPE as the build-time selector (configuration contract, build selector). - Optimization-dependent investigation: choose RelWithDebInfo; the GNU module initializes its flags with
-O2 -g. In the GNU compiler module, the shipped initialization uses-O2 -g -DNDEBUG, while Debug adds-g; don't assume these precise flags for every toolchain or project override (GNU compiler module).
Not for: React Native Hermes source-download or CMakeLists errors; see ptr-react-native-android-source-build-configurebuildforhermes-meta-hermes.
Settings that matter
| Setting or flag | Value / default | Applies to | Source |
|---|---|---|---|
-G | A build system generator; choose before generating the tree | CMake versioned reference docs | CLI |
CMAKE_BUILD_TYPE | Debug, Release, RelWithDebInfo or MinSizeRel; often empty by default | Single-config generators | variable |
cmake --build --config | Choose configuration <cfg>; pass after the build directory | Multi-config generators | CLI |
CMAKE_CONFIGURATION_TYPES | Semicolon-separated available configurations, e.g. Debug;Release;RelWithDebInfo; default generator-specific | Multi-config generators; configure-time availability only | variable |
cmake --build --verbose | Enable emitted build commands when supported; inspect actual optimization/debug flags | CMake versioned reference docs | CLI |
Order of operations
1. Select a generator supported by the machine using -G to specify a generator. Use a new build directory when changing generators; a cached generator belongs to its existing tree (CLI, generator mismatch source). 2. Single-config path: cmake -S . -B build-debug -G Ninja -DCMAKE_BUILD_TYPE=Debug, then cmake --build build-debug. For optimized investigation, configure another directory with -DCMAKE_BUILD_TYPE=RelWithDebInfo. 3. Multi-config path: configure with -G <generator-name> (or the installed Visual Studio generator), then --config <cfg> to choose the configuration. Available configurations are set during configuration; --config selects one during build (buildsystem, CLI). 4. If the wrong configuration appears, inspect the generator recorded in CMakeCache.txt and the build invocation, then rerun the appropriate selector. Use verbose build output to inspect actual compiler flags; check the actual commands before relying on initialization defaults (CLI).
Known failures and fixes
| Error (short quote) or symptom | Cause | Fix | Source |
|---|---|---|---|
Does not match the generator used previously: | Reusing a build tree with another generator | Configure a different build directory with the intended -G | CMake source |
| CMAKE_BUILD_TYPE=Debug still builds Release | Selected generator is multi-config and ignores that variable | Choose the configuration with --config <cfg> | build configurations, build selector |
Diagnostic: Does not match the generator used previously:
Keep configuration selection separate from generator replacement: changing Debug to Release is not itself a request to change the generator. The February 2018 build-type question records confusion about the configuration names; current generator rules above determine which selector matters.
Missing
- The linked source does not confirm: project/cache/toolchain settings can override initialization defaults.
- Exact flags for a particular compiler, toolchain file or target are not fixed by a configuration name. RelWithDebInfo may use different optimization than Release; compare actual commands for the failing workload.
Checked
2026-11-12; CMake 4.4.5 release, versioned CLI/buildsystem/variable docs, GNU compiler and generator-mismatch source, and February 2018 question read. No configuration or build commands executed.
Started from a post by @Kitware, packaged by the editor. Original post