# CMake presets: \`inherit\` makes it hard to include toolchain file

**URL:** https://discourse.cmake.org/t/cmake-presets-inherit-makes-it-hard-to-include-toolchain-file/7784
**Category:** Code
**Created:** [March 28, 2023, 6:43am UTC](https://discourse.cmake.org/t/cmake-presets-inherit-makes-it-hard-to-include-toolchain-file/7784 "2023-03-28T06:43:53Z")
**Posts on this page:** 1
**Showing post:** 6

<div class="post-metadata">

### Author: ![Chardrazle](https://discourse.cmake.org/user_avatar/discourse.cmake.org/chardrazle/32/4362_2.png) [@Chardrazle](https://discourse.cmake.org/u/Chardrazle)
#### Post date: [August 8, 2025, 11:16am UTC](https://discourse.cmake.org/t/cmake-presets-inherit-makes-it-hard-to-include-toolchain-file/7784/6 "2025-08-08T11:16:02Z")

</div>

We just ran into this issue. We “solved” it by using an environment variable _that is under control of the presets_.  
For example, in the “BasePresets.json”:

```auto
{
  "version": 8,
  "configurePresets": [
    {
      "name": "default",
      "hidden": true,
      "binaryDir": "$env{BASE_ROOT}/.build/${sourceDirName}",
      "toolchainFile": "$env{BASE_ROOT}/where_we_keep_common_stuff/toolchain.cmake",
      "environment": {
        "BASE_ROOT": "${fileDir}"
      }
    }
  ]
}

```

Then in the project-specific presets we specify “where” the root is from _this_ file by overriding the env-var.  
So if it is located one subdirectory away:

```auto
{
  "version": 8,
  "include": ["../BasePresets.json"],
  "configurePresets": [
    {
      "name": "default-inherited",
      "inherits": ["default"],
      "hidden": true,
      "environment": {
        "BASE_ROOT": "${fileDir}/.."
      }
    },
    {
      "name": "an-actual-preset-for-the-project",
      "inherits": ["default-inherited"]
    }
  ]
}

```

---

_[View the full topic](https://discourse.cmake.org/t/cmake-presets-inherit-makes-it-hard-to-include-toolchain-file/7784)._
