CMake is a cross-platform, open-source build description system that generates native build files — Makefiles, Ninja build files, or Visual Studio project files — from a high-levelDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/MicrosoftDocs/cpp-docs/llms.txt
Use this file to discover all available pages before exploring further.
CMakeLists.txt description. Visual Studio 2019 and later provide first-class CMake support: you open a folder containing a CMakeLists.txt, and Visual Studio reads CMake directly for IntelliSense, browsing, configuration, and debugging without ever generating a .vcxproj. This makes it straightforward to share the same CMake project between Windows developers using Visual Studio, Linux developers using the command line, and CI pipelines running on any platform.
Installation
CMake support is included in the Desktop development with C++ workload. When installing via the Visual Studio Installer, make sure C++ CMake tools for Windows is checked. For cross-platform (Linux/WSL) development, also install the Linux Development with C++ workload, which adds C++ CMake tools for Linux.CMake version 3.14 or later is recommended. CMake 3.20 or later is required when invoking CMake with
--preset from the command line.Opening a CMake Project
When you choose File → Open → Folder and select a directory that contains aCMakeLists.txt, Visual Studio:
- Adds a CMake menu to the main menu bar.
- Displays the folder structure in Solution Explorer.
- Runs the CMake configure step and generates
CMakeCache.txtfor the default configuration. - Indexes source files in the background for IntelliSense, Go To Definition, and Find All References.
Minimal CMakeLists.txt
A minimal project that builds a console executable from a single source file:Configuring CMake Projects
Visual Studio drives CMake configuration through a CMake configuration file. Two formats are supported:- CMakePresets.json (Recommended)
- CMakeSettings.json (Legacy)
CMakePresets.json is the recommended format for Visual Studio 2019 16.10 and later. It is also understood by VS Code, the command line, and CI systems, making it the most portable choice.Enable it in Tools → Options → CMake → General → Always use CMakePresets.json.Basic CMakePresets.json structure:microsoft.com/VisualStudioSettings/CMake/1.0) controls IDE-specific behaviour like hostOS (which presets appear in the dropdown) and intelliSenseMode. These settings do not affect the CMake command line.Triggering Configuration
Visual Studio automatically re-runs the configure step when you editCMakeLists.txt or the configuration file. To trigger it manually:
- Project → Configure Cache from the main menu, or
- Run
cmake --preset <configurePreset>from the Developer Command Prompt.
Building CMake Projects
Select a Configure Preset
Use the Configure Preset dropdown in the toolbar to choose a preset (e.g.,
windows-debug). Visual Studio automatically invokes the configure step if the cache is out of date.Select a Build Preset
The Build Preset dropdown controls build-specific options. If no build presets are defined, Visual Studio uses the default (equivalent to
cmake --build with no extra arguments).Debugging CMake Projects
All executable CMake targets appear in the Startup Item dropdown in the toolbar. Select a target and press F5 or Debug → Start Debugging. Customize a debugging session by creating alaunch.vs.json file:
Edit and Continue
Add the following to yourCMakeLists.txt to enable Edit and Continue when building with MSVC on Windows:
vcpkg Integration
CMake projects opened in Visual Studio integrate with vcpkg after you runvcpkg integrate install. When CMakeSettings.json is the active configuration file, Visual Studio automatically passes the vcpkg toolchain file to CMake. For CMakePresets.json, set the toolchain file explicitly using the VCPKG_ROOT environment variable:
IntelliSense and Language Services
Visual Studio uses the compiler and target architecture defined in the active Configure Preset to power IntelliSense. WithCMakePresets.json, you can override this using intelliSenseMode in the Visual Studio Settings vendor map:
Troubleshooting
CMake cache errors
CMake cache errors
Open the Project menu (or right-click
CMakeLists.txt in Solution Explorer) and choose:- View CMakeCache.txt — inspect the current cache values.
- Delete Cache and Reconfigure — wipe the build directory and start fresh.
- Configure Cache — force a re-run of the configure step.
IntelliSense not updating
IntelliSense not updating
Save
CMakeLists.txt to trigger a re-configure. If the issue persists, select Project → Configure Cache to manually regenerate the CMake cache.CMake partial activation (Visual Studio 2022 17.1+)
CMake partial activation (Visual Studio 2022 17.1+)
If your root folder does not contain a
CMakeLists.txt, Visual Studio prompts whether to enable CMake integration. Accept and edit CMakeWorkspaceSettings.json (in the .vs directory) to specify which sub-folders contain CMake roots:Running CMake from CI
WithCMakePresets.json, your local workflow maps directly to CI: