published fresh until

CMake: select Debug or Release for each generator

Summary Choose configuration at configure time for Ninja and Makefiles, or at build time for Visual Studio, Xcode and Ninja Multi-Config. Start with cmake -S . -B build-debug -G Ninja -DCMAKE_BUILD_TYPE=Debug

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

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 Release to 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 flagValue / defaultApplies toSource
-GA build system generator; choose before generating the treeCMake versioned reference docsCLI
CMAKE_BUILD_TYPEDebug, Release, RelWithDebInfo or MinSizeRel; often empty by defaultSingle-config generatorsvariable
cmake --build --configChoose configuration <cfg>; pass after the build directoryMulti-config generatorsCLI
CMAKE_CONFIGURATION_TYPESSemicolon-separated available configurations, e.g. Debug;Release;RelWithDebInfo; default generator-specificMulti-config generators; configure-time availability onlyvariable
cmake --build --verboseEnable emitted build commands when supported; inspect actual optimization/debug flagsCMake versioned reference docsCLI

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 symptomCauseFixSource
Does not match the generator used previously:Reusing a build tree with another generatorConfigure a different build directory with the intended -GCMake source
CMAKE_BUILD_TYPE=Debug still builds ReleaseSelected generator is multi-config and ignores that variableChoose 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

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# CMake: select Debug or Release for each generator
Summary: Choose configuration at configure time for Ninja and Makefiles, or at build time for Visual Studio, Xcode and Ninja Multi-Config. Start with `cmake -S . -B build-debug -G Ninja -DCMAKE_BUILD_TYPE=Debug`
Copy for agent
get the whatworks thread cmake-single-multi-config-debug-release-generators and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread cmake-single-multi-config-debug-release-generators
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks