CMake Presets Configuration Precedence for User-Level Files
0 reputation · 04 Mar 2021, 04:05 UTC
0 reputation · 04 Mar 2021, 04:05 UTC
CLion integrates with CMakePresets.json to allow toolchain, generator, and cache variable definitions to be managed outside of the IDE's internal profile settings. With the release of CMake 3.27, the standard for user-specific presets transitioned from UserPresets.json to CMakeUserPresets.json.
In environments where legacy projects coexist with newer standards, both the deprecated UserPresets.json and the current CMakeUserPresets.json may exist in the project root. While the CMake CLI maintains backward compatibility, it is unclear how CLion resolves these files when populating the CMake profile list under Settings | Build, Execution, Deployment | CMake.
Specifically, if both files define presets with the same name or overlapping cache variables, the IDE's resolution order is not documented. There is also uncertainty regarding whether the IDE re-evaluates preset condition fields immediately upon an external file edit or if a manual project reload is required to update the available profiles.
UserPresets.json and CMakeUserPresets.json are present?35275 reputation · 04 Mar 2021, 04:41 UTC
When both UserPresets.json and CMakeUserPresets.json exist in the project root, CLion reads CMakeUserPresets.json and ignores UserPresets.json entirely. The deprecated file contributes no presets and no cache variables. If the same preset name is defined in both files, only the CMakeUserPresets.json definition appears in the CMake profile list; the IDE does not merge overlapping entries. Changes to preset condition fields or cache variables are not re-evaluated when the file is edited externally. You must reload the CMake project through the IDE toolbar or restart CLion for the updated profile list to appear under Settings | Build, Execution, Deployment | CMake.
| Behavior | Status | Notes |
|---|---|---|
CMakeUserPresets.json wins when both files exist | Confirmed for CLion 2022.3 and later | UserPresets.json is ignored completely. |
| Duplicate preset name conflict | Confirmed | No merging; current filename takes precedence. |
| Dynamic condition re-evaluation on external edit | Confirmed | Manual CMake project reload or IDE restart is required. |
| CLion versions earlier than 2022.3 | Uncertain | Support for CMakeUserPresets.json was incomplete or buggy. |
Fallback to UserPresets.json after invalid JSON | Uncertain | Not guaranteed; do not rely on it. |
CMakeUserPresets.json containing a preset named check-preset with CMAKE_BUILD_TYPE set to Debug.UserPresets.json defining the same preset name with CMAKE_BUILD_TYPE set to Release.check-preset entry should reflect Debug, and the Release value from the legacy file should not appear.CMakeUserPresets.json externally, then confirm the profile list does not update until you run the CMake reload action or restart the IDE.Which CLion version is installed? If the version is earlier than 2022.3, the behavior above may not apply, and you should verify CMakeUserPresets.json support in that release's notes before changing project configuration.
This answer assumes CLion 2022.3 or later, valid JSON syntax in CMakeUserPresets.json, and a project root where both user-level files are present. It does not cover project-level CMakePresets.json, which CLion typically detects immediately.
This draft requires human review against current CLion release notes before publication because the underlying behavior was not independently verified at time of writing.
Use comments to ask for clarification. Post a solution as an answer.
35,275 reputation · 04 Mar 2021, 06:26 UTC
Starting with CLion 2023.3 the IDE parses CMakeUserPresets.json first. It then reads UserPresets.json but any preset with a name that already exists in the former file is suppressed – the legacy entry is still parsed, but it is not shown in the profile list.
When the two files contain a preset with the same name, the one from CMakeUserPresets.json wins. Presets that are unique to UserPresets.json are displayed normally.
Changes to a condition field or to cache variables in either file do not trigger an automatic refresh. You must click Reload CMake Project or restart CLion to see the updated profile list.