presets-vs-kits
Skill1.7k starsChanged 7 months agoMITView on GitHub
Use when writing or reviewing code that must work in both CMake Presets and Kits/Variants modes. Covers configure, build, test, environment, and generator paths. Triggers: "presets vs kits", "useCMakePresets", "works in both modes".
Trending
Quiet this year.thin dataabout the whole repository
Who's talking about microsoft/vscode-cmake-tools
- clangd/vscode-clangd“support commands in settings”GitHub · Jun 27, 2020 · 17 reactions
- fredericbonnet/cmake-test-explorer“trigger BuildBeforeRun also by running a test in the testexplorer”GitHub · Mar 12, 2021 · 8 reactions
- twxs/vs.language.cmake“CMake Tools Extension & twxs.cmake extension”GitHub · Jan 29, 2024 · 5 reactions
- disroop/vs-code-conan“configuration provider for cpptools / IntelliSense”GitHub · Jan 14, 2021 · 3 reactions
- microsoft/vscode-cmake-tools-api“Update APIs”GitHub · Aug 1, 2025 · 2 reactions
The biggest 5 of 14 mentions linking to the repository that our crawl found. Each line is their own headline.
See all 14
Talked about on GitHub (14 times).
On GitHub · 14
- Jun 27, 2020support commands in settings — clangd/vscode-clangd17 reactions · 8 comments
- Mar 12, 2021trigger BuildBeforeRun also by running a test in the testexplorer — fredericbonnet/cmake-test-explorer8 reactions
- Jan 29, 2024CMake Tools Extension & twxs.cmake extension — twxs/vs.language.cmake5 reactions · 1 comment
- Jan 14, 2021configuration provider for cpptools / IntelliSense — disroop/vs-code-conan3 reactions · 5 comments
- Aug 1, 2025Update APIs — microsoft/vscode-cmake-tools-api2 reactions · 4 comments
9 more on GitHub
- Nov 15, 2024Add C++26 support (setting values only) — microsoft/vscode-cpptools2 reactions · 3 comments
- Oct 25, 2024cmake-kits.json incorrect CXX compiler — raspberrypi/pico-vscode2 reactions · 3 comments
- Oct 24, 2024Add support for `${command:<name-of-command>}` in c_cpp_properties.json — microsoft/vscode-cpptools2 reactions · 7 comments
- Feb 28, 2022Add support for resolving commands — microsoft/vscode-cpptools2 reactions · 4 comments
- Jun 19, 2025Cleanup standard version handling. — microsoft/vscode-makefile-tools1 reaction
- Mar 5, 2025Pixi builds / VSCode / CMake issues and differences — FreeCAD/FreeCAD1 reaction · 15 comments
- Jan 31, 2025Feature request: Improved variable and command substitution for build directories setting — JacquesLucke/gcov-viewer1 reaction
- Sep 26, 2024Replace CMake grammar — github-linguist/linguist1 reaction
- Sep 16, 2024Newest macos-latest environment update not working for VS Code tests — actions/runner-images1 reaction · 2 comments
In this repository7 other files it gives its agents.
- .github/copilot-instructions.mdCopilot instructions
- add-commandSkill
- add-diagnostic-parserSkill
- add-settingSkill
- backend-testsSkill
- pr-readinessSkill
- validation-projectSkill
The file
We split this skill into the rules it gives an agent
7 rules. About 0 are common, 2 are distinctive, and 5 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
5
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 88
Use PresetsController (in src/presets/presetsController.ts) to access the merged, expanded preset tree.
- Very specific: line 102
All preset interfaces are defined in src/presets/preset.ts.
- Distinctive: line 191
Always check the generator before any build-type logic:
- Very specific: line 210
When this setting is true, CMAKE_BUILD_TYPE is also set at configure time for multi-config generators (used by some CMake scripts that read …
- Distinctive: line 223
If you add or change behavior in a shared code path, you must verify it works in both presets mode and kits/variants mode.
- Very specific: line 227
Never assume CMAKE_BUILD_TYPE is the way to set the build configuration.
- Very specific: line 273
Always handle null driver returns in calling code.
≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Presets Mode vs Kits/Variants Mode
Guide for writing code that works correctly in both operating modes of CMake Tools. Any shared code path (configure, build, test, environment, targets) must handle both modes.
The two modes
CMake Tools operates in one of two mutually exclusive modes per project folder:
| Presets mode | Kits/variants mode | |
| Source of truth | CMakePresets.json / CMakeUserPresets.json | Kit selection + variant settings |
| When active | cmake.useCMakePresets is 'always', or 'auto' and preset files exist | cmake.useCMakePresets is 'never', or 'auto' and no preset files exist |
| Runtime check | CMakeProject.useCMakePresets === true | CMakeProject.useCMakePresets === false |
How the mode is determined
// src/config.ts
export type UseCMakePresets = 'always' | 'never' | 'auto';
// src/cmakeProject.ts — doUseCMakePresetsChange()
const usingCMakePresets =
useCMakePresets === 'always' ? true :
useCMakePresets === 'never' ? false :
await this.hasPresetsFiles(); // 'auto' — check for CMakePresets.jsonThe resolved boolean is stored in CMakeProject._useCMakePresets and exposed via the useCMakePresets getter.
When you MUST handle both modes
Any shared code path that touches configure, build, test, environment setup, or target resolution must branch on the mode. Omitting the check for one mode is a latent bug.
The canonical branching pattern
// From src/cmakeProject.ts — configure validation (real code)
if (!this.useCMakePresets) {
// Kits mode: require a kit and variant
if (!this.activeKit) {
await vscode.window.showErrorMessage(
localize('cannot.configure.no.kit', 'Cannot configure: No kit is active for this CMake project')
);
return { exitCode: -1, resultType: ConfigureResultType.Other };
}
if (!this.variantManager.haveVariant) {
await this.variantManager.selectVariant();
}
} else if (!this.configurePreset) {
// Presets mode: require a configure preset
void vscode.window.showErrorMessage(
localize('cannot.configure.no.config.preset', 'Cannot configure: No configure preset is active')
);
return { exitCode: -1, resultType: ConfigureResultType.Other };
}Another real example — default build targets
// src/cmakeProject.ts — getDefaultBuildTargets()
if (this.useCMakePresets && (!defaultTarget || defaultTarget === this.targetsInPresetName)) {
targets = this.buildPreset?.targets;
}
if (!this.useCMakePresets && !defaultTarget) {
targets = await this.allTargetName;
}Canonical data access — Presets mode
Merged preset tree
Use PresetsController (in src/presets/presetsController.ts) to access the merged, expanded preset tree. Never re-parse CMakePresets.json or CMakeUserPresets.json directly — the controller handles include chaining, expansion, and file watching.
Active presets on CMakeProject
CMakeProject.configurePreset // ConfigurePreset | null
CMakeProject.buildPreset // BuildPreset | null
CMakeProject.testPreset // TestPreset | null
CMakeProject.packagePreset // PackagePreset | null
CMakeProject.workflowPreset // WorkflowPreset | nullPreset types
All preset interfaces are defined in src/presets/preset.ts. Key types include ConfigurePreset, BuildPreset, TestPreset, PackagePreset, WorkflowPreset.
CMake executable override
In presets mode, the configure preset can override the CMake path:
// src/cmakeProject.ts
const overWriteCMakePathSetting = this.useCMakePresets
? this.configurePreset?.cmakeExecutable
: undefined;Canonical data access — Kits/variants mode
Active kit
CMakeProject.activeKit // Kit | null — from src/kits/kit.tsKit environment
import { effectiveKitEnvironment } from '@cmt/kits/kit';
// Used in src/drivers/cmakeDriver.ts:
this._kitEnvironmentVariables = await effectiveKitEnvironment(kit, this.expansionOptions);This merges compiler paths, VS Developer Environment (on Windows via vcvarsall.bat), and any custom environmentVariables defined on the kit.
SpecialKits — always check before treating a kit as a real compiler
// src/kits/kit.ts
export enum SpecialKits {
ScanForKits = '__scanforkits__',
Unspecified = '__unspec__',
ScanSpecificDir = '__scan_specific_dir__',
}These sentinel values appear in the kit list as UI actions. Before using kit.compilers, kit.toolchainFile, or kit.preferredGenerator, check:
if (kit.name === SpecialKits.Unspecified || kit.name === SpecialKits.ScanForKits) {
// Not a real kit — skip compiler logic
}Kit interface
// src/kits/kit.ts (key fields)
export interface Kit extends KitDetect {
name: string;
description?: string;
preferredGenerator?: CMakeGenerator;
cmakeSettings?: Record<string, string | string[]>;
compilers?: Record<string, string>;
toolchainFile?: string;
environmentVariables?: Record<string, string>;
environmentSetupScript?: string;
visualStudio?: string;
visualStudioArchitecture?: string;
}Variant handling
Variants (src/kits/variant.ts) provide build type and other CMake variable overrides in kits mode. The VariantManager is only initialized when not using presets:
// src/cmakeProject.ts
if (!this.useCMakePresets) {
await this.variantManager.initialize(this.folderName);
await drv.setVariant(this.variantManager.activeVariantOptions, ...);
}Generator handling in both modes
Multi-config vs single-config
Always check the generator before any build-type logic:
import { isMultiConfGeneratorFast } from '@cmt/util';
// src/util.ts
export function isMultiConfGeneratorFast(gen?: string): boolean {
return gen !== undefined
&& (gen.includes('Visual Studio') || gen.includes('Xcode') || gen.includes('Multi-Config'));
}| Generator type | Examples | Build type mechanism |
| Single-config | Ninja, Unix Makefiles | CMAKE_BUILD_TYPE set at configure time |
| Multi-config | Visual Studio, Xcode, Ninja Multi-Config | --config <type> passed at build time |
Exception: cmake.setBuildTypeOnMultiConfig
When this setting is true, CMAKE_BUILD_TYPE is also set at configure time for multi-config generators (used by some CMake scripts that read it). See src/drivers/cmakeDriver.ts.
How it shows up in both modes
- Presets mode: The generator is embedded in
configurePreset.generator. The preset may also setCMAKE_BUILD_TYPEincacheVariablesor useconfigurationin the build preset. - Kits mode: The generator comes from
Kit.preferredGenerator.nameor is auto-detected. Build type comes from the active variant.
Common mistakes
1. Testing only one mode
If you add or change behavior in a shared code path, you must verify it works in both presets mode and kits/variants mode. Many bugs ship because the developer only tested with presets (or only with kits).
2. Assuming single-config generator
Never assume CMAKE_BUILD_TYPE is the way to set the build configuration. Always check isMultiConfGeneratorFast() first.
// ❌ Wrong — breaks with Visual Studio / Ninja Multi-Config
args.push(`-DCMAKE_BUILD_TYPE=${buildType}`);
// ✅ Correct
if (!isMultiConfGeneratorFast(generator)) {
args.push(`-DCMAKE_BUILD_TYPE=${buildType}`);
}3. Reading preset files directly
// ❌ Wrong — bypasses include chaining, expansion, and caching
const presets = JSON.parse(fs.readFileSync('CMakePresets.json', 'utf8'));
// ✅ Correct — use the PresetsController
const configPreset = this.configurePreset;4. Not checking for SpecialKits sentinel values
// ❌ Wrong — crashes when kit is '__unspec__' or '__scanforkits__'
const compiler = kit.compilers?.['C'];
// ✅ Correct
if (kit.name !== SpecialKits.Unspecified && kit.name !== SpecialKits.ScanForKits) {
const compiler = kit.compilers?.['C'];
}5. Forgetting the driver instance guard
In kits mode, no driver is created without a kit:
// src/cmakeProject.ts
if (!this.useCMakePresets && !this.activeKit) {
log.debug(localize('not.starting.no.kits', 'Not starting CMake driver: no kit selected'));
return null;
}Always handle null driver returns in calling code.
Testing checklist
- Verified in presets mode (create a
CMakePresets.jsonwith configure + build presets) - Verified in kits/variants mode (remove preset files or set
cmake.useCMakePresets: "never") - Verified with a single-config generator (Ninja or Unix Makefiles)
- Verified with a multi-config generator (Visual Studio, Ninja Multi-Config, or Xcode)
SpecialKitssentinel values handled (no crash on__unspec__kit)nulldriver /nullpreset /nullkit cases handled gracefully- Windows, macOS, and Linux path differences considered
See also: .github/copilot-instructions.md for project-wide conventions.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

