# \`CMakeUserPresets.json\` being read before \`CMakePresets.json\`

**URL:** https://discourse.cmake.org/t/cmakeuserpresets-json-being-read-before-cmakepresets-json/9958
**Category:** Development
**Created:** [January 29, 2024, 3:36pm UTC](https://discourse.cmake.org/t/cmakeuserpresets-json-being-read-before-cmakepresets-json/9958 "2024-01-29T15:36:02Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Lecris](https://discourse.cmake.org/user_avatar/discourse.cmake.org/lecris/32/3193_2.png) [@Lecris](https://discourse.cmake.org/u/Lecris)
#### Post date: [January 29, 2024, 3:36pm UTC](https://discourse.cmake.org/t/cmakeuserpresets-json-being-read-before-cmakepresets-json/9958/1 "2024-01-29T15:36:02Z")

</div>

This is a continuation of the comment in: [https://gitlab.kitware.com/cmake/cmake/-/merge\_requests/9110#note\_1474956](https://gitlab.kitware.com/cmake/cmake/-/merge_requests/9110#note_1474956)

Basically it is weird how the `CMakeUserPresets.json` is being read before `CMakePresets.json`, normally you would expect the inverse. From what @kyle.edwards says it’s because it implicitly uses the `include` directive on the `CMakePresets.json`.

---

<div class="post-metadata">

### Author: ![kyle.edwards](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/k/65b543/32.png) [@kyle.edwards](https://discourse.cmake.org/u/kyle.edwards)
#### Post date: [January 29, 2024, 3:47pm UTC](https://discourse.cmake.org/t/cmakeuserpresets-json-being-read-before-cmakepresets-json/9958/2 "2024-01-29T15:47:44Z")

</div>

If one file `include`s another, the `include`ing file has to be read first to know that another file has to be `include`d. That’s why the read order is the way it is. We simply made `CMakeUserPresets.json` implicitly `include` `CMakePresets.json` in order to take advantage of the existing code.

In principle, the order in which the files are read shouldn’t matter for the purposes of resolving the preset graph. All of the files should be read first, and _then_ the graph should be resolved.

---

<div class="post-metadata">

### Author: ![Lecris](https://discourse.cmake.org/user_avatar/discourse.cmake.org/lecris/32/3193_2.png) [@Lecris](https://discourse.cmake.org/u/Lecris)
#### Post date: [January 29, 2024, 4:22pm UTC](https://discourse.cmake.org/t/cmakeuserpresets-json-being-read-before-cmakepresets-json/9958/3 "2024-01-29T16:22:32Z")

</div>

I think the thing that confused me when I tried to reverse the order in the `override` branch was that the `include` directives are execute after all of the `configurePresets`, etc. objects? There was something strange happening when I tried to move the snippet:

```cpp

  if (rootType == RootType::User && readReason == ReadReason::Root) {
    auto cmakePresetsFilename = GetFilename(this->SourceDir);
    if (cmSystemTools::FileExists(cmakePresetsFilename)) {
      if ((result = includeFile(cmakePresetsFilename, RootType::Project,
                                ReadReason::Root, errMsg)) != true) {
        return result;
      }
    }

```

near the top so that the order of preset definition is from the bottom most `include` to the top.

---

<div class="post-metadata">

### Author: ![Lecris](https://discourse.cmake.org/user_avatar/discourse.cmake.org/lecris/32/3193_2.png) [@Lecris](https://discourse.cmake.org/u/Lecris)
#### Post date: [April 2, 2024, 11:37am UTC](https://discourse.cmake.org/t/cmakeuserpresets-json-being-read-before-cmakepresets-json/9958/4 "2024-04-02T11:37:32Z")

</div>

@kyle.edwards I think I am encountering some issues with this parsing in [https://gitlab.kitware.com/cmake/cmake/-/merge\_requests/9110#note\_1503756](https://gitlab.kitware.com/cmake/cmake/-/merge_requests/9110#note_1503756). I haven’t debugged this issue to see how and where it fails, but I could use some fresh pair of eyes. That is the last part of the MR that needs to be resolved
