CLion 2024.2 Help

CMake presets

CMake Presets are a way to configure and share CMake options using two files:

  • CMakePresets.json for project-wise builds. This file can be shared via VCS.

  • CMakeUserPresets.json for developers' own local builds. This file should not be checked into VCS.

Both CMakePresets.json and CMakeUserPresets.json have the same format and should be located in the project's root directory.

CMake Profiles have many settings in common with CMake Presets and are also shareable via VCS. The major difference is that profiles reference CLion toolchains, which contain information that is not present and not needed in CMake presets (like the debugger or environment settings).

Presets import

On project opening, CLion detects all build and configure presets in CMakePresets.json and CMakeUserPresets.json files under the project root. By default, all of them are loaded automatically into CMake profiles in read-only mode.

To view the loaded presets, go to Settings | Build, Execution, Deployment | CMake or use the View link in the notification dialog:

Presets loaded notification
  • All new presets are disabled by default, unless you have already loaded and enabled them before (CLion matches them by name).

  • All previously loaded presets are removed if they are not present in the CMakePresets.json or CMakeUserPresets.json files.

Presets profiles initial state

Load Presets manually

You can also load presets for an already opened project.

  1. Call Help | Find Action (Ctrl+Shift+A) and search for Load CMake Presets.

  2. CLion will show a popup with a list of the existing build presets:

    Load CMake Presets popup
  3. Select the preset and press Enter.

    You can select several entries by holding Ctrl or Shift. CLion will load all the selected presets.

  4. Similarly to the case of opening a project, the presets you load manually are imported into CMake profiles in read-only mode. You can find them in Settings | Build, Execution, Deployment | CMake.

Enable a Presets profile

  1. Go to Settings | Build, Execution, Deployment | CMake.

  2. Select the desired profile and set the Enable profile checkbox:

    Enabling a presets profile

Editing Presets

There are two options you can use to edit the imported presets:

Edit a copy of a presets-based CMake profile

  1. Go to Settings | Build, Execution, Deployment | CMake.

  2. Select the desired profile and click or press Ctrl/⌘ + D:

    Copying a presets-based profile
  3. Adjust the settings in the copied profile:

    Editing a copied presets-based profile

Modify the corresponding JSON files in the editor

  • Open and start editing the corresponding json file. CLion will track changes as you type and notify you about any errors in the Problems view:

    CMake presets error reporting
  • When you change a preset file in the editor or modify it externally, you will get a notification suggesting to reload the changes:

    Editing a CMake preset JSOn file
  • Click Enable Auto-Reload if you prefer CLion to reload the changes silently. This sets the corresponding checkbox in the profiles settings:

    CMake profiles auto-reload

Changing the toolchain

By default, the loaded preset is linked to the default CLion toolchain.

To set one of the already configured toolchains, modify the vendor-specific field of the configure preset.

For example, use the following code to switch to a toolchain called Clang10:

"vendor": { "jetbrains.com/clion": { "toolchain": "Clang10" } }

As a result, the Clang10 toolchain will be assigned to the loaded preset:

A loaded CMake preset

On Windows, if you are working with the MSVC toolchain, the architecture and toolset properties from the configure preset will be fetched to CMake options as well:

CMake Presets MSVC options

Condition support

CLion supports the condition field in the CMakePresets.json and CMakeUserPresets.json files to filter presets. Note that only the equals and notEquals types are supported.

Here is an example of how to filter a preset by platform:

{ "name": "windows-only", "inherits": "default", "displayName": "Windows-only configuration", "description": "This build is only available on Windows", "condition": { "type": "equals", "lhs": "${hostSystemName}", "rhs": "Windows" } }

After you configure filtering by platform, the corresponding preset will only appear in your preset profile list on the platform for which it is enabled.

Learn more about the condition field options in the CMake documentation.

Last modified: 03 October 2024