DevTools Logo

CMake Presets Generator

CMake Presets Generator

Build schema v6 CMakePresets.json with correct inherits, hidden bases and cache variables.

Runs in your browser
Try an example

Preset forms

unnamed
Options

CMakePresets.json

7 lines · 88 bytes

No presets configured yet

Name a configure preset or load an example.

Examples

Hidden base

Input
base hidden, debug inherits base
Output
"hidden": true, "inherits": ["base"]

Hidden presets never appear in --list-presets but remain valid parents.

Release override

Input
child sets CMAKE_BUILD_TYPE=Release
Output
"CMAKE_BUILD_TYPE": { "value": "Release" }

Child values win over inherited values; conflicts are explained in the validation panel.

Toolchain file

Input
vcpkg toolchain path
Output
"CMAKE_TOOLCHAIN_FILE": { "type": "FILEPATH" }

Toolchain files belong in the configure preset's cacheVariables object.

About this tool

CMake Presets Generator turns a small set of forms into a complete CMakePresets.json at schema version 6. It covers configure presets with generators, binary directories, cache variables and toolchain files, plus build and test presets that reference them correctly.

Inheritance is modeled explicitly: presets can inherit an ordered chain of parents, hidden base presets can carry shared settings, and cache variables are merged with child-wins semantics. Conflicts are reported so you can see where a release child overrides a debug base rather than wondering why CMake picked a value.

Validation runs before copy or download. Duplicate names, inheritance cycles, unknown parents and dangling configurePreset references are hard errors; absolute binary directories are warnings because they break on other machines. The output is deterministic and paired with the four commands you will actually run: cmake --list-presets, cmake --preset, cmake --build --preset and ctest --preset.

What this tool does not do

  • Does not author CMakeLists.txt or resolve target-level build logic.
  • Workflow presets and package presets are not modeled.
  • CMakeUserPresets.json is not edited; keep machine-local overrides in that file yourself.
  • Import of existing files is out of scope in this version.

How to use this tool

  1. Name a configure preset

    Start with a name such as debug, choose a generator and set a macro-based binaryDir.

  2. Add children

    Enable the release child to see inherits and cache-variable overrides in the emitted JSON.

  3. Add build and test presets

    Choose whether to include a test preset; both reference an existing configure preset.

  4. Download and verify

    Save as CMakePresets.json, then run cmake --list-presets to confirm CMake reads it.

Use cases

First team preset file

Standardize a repository's configure and build commands without flag soup.

CI matrix

Generate explicit debug and release presets for pipeline jobs.

Teaching C++

Give students a scaffold with correct inheritance and macro-based build directories.

Emitted preset keys

Preset typeRequired
Configurename, generator, binaryDir
Buildname, configurePreset
Testname, configurePreset

The file always starts with version: 6 and object order is stable across edits.

Common mistakes

Mistake:Inheriting across preset types.

Fix:Build presets inherit build presets; configure presets inherit configure presets.

Mistake:Hard-coding /home/me/build as binaryDir.

Fix:Use ${sourceDir} or ${sourceDirName} macros.

Mistake:Expecting a hidden base to show in cmake --list-presets.

Fix:Hidden presets are intentionally omitted; their children are listed.

Mistake:Putting toolchain paths outside cacheVariables.

Fix:Set CMAKE_TOOLCHAIN_FILE as a FILEPATH cache variable.

Mistake:Using schema version 2 with conditions.

Fix:This tool emits version 6, which supports condition objects.

Frequently asked questions

What is a hidden base preset for?

A hidden preset holds shared settings such as a generator and common cache variables. It never appears in cmake --list-presets, but children can inherit from it. This keeps your visible list short while avoiding duplicated configuration.

How does inherits merge cache variables?

CMake applies parents in order and then the child's own fields. When the same cache variable appears twice, the child wins. The generator shows the final resolved value and lists the variables that were overridden so the merge is not a mystery.

Which schema version should I use?

Use version 6 for modern CMake installations. Older versions drop fields such as conditions; this tool always emits version 6 and validates that conditions are not paired with an ancient version.

Where do build and test presets reference configure presets?

Through the configurePreset key on each build or test preset. It must name an existing configure preset. The validator catches typos before you download the file.

Can I keep machine-specific presets out of git?

Yes. Put personal overrides in CMakeUserPresets.json and add that file to .gitignore. Commit only the shared CMakePresets.json your team agrees on.

How do I verify the generated file?

Save it at the project root and run cmake --list-presets. If CMake parses the file, your configure, build and test presets appear in the list; the generated usage snippet has all four commands.

References & standards