# Config preset in CMakeUserPresets.json doesn't inherit cacheVariables from parent in CMakePresets.json

**URL:** https://discourse.cmake.org/t/config-preset-in-cmakeuserpresets-json-doesnt-inherit-cachevariables-from-parent-in-cmakepresets-json/7497
**Category:** Usage
**Created:** [February 20, 2023, 5:43am UTC](https://discourse.cmake.org/t/config-preset-in-cmakeuserpresets-json-doesnt-inherit-cachevariables-from-parent-in-cmakepresets-json/7497 "2023-02-20T05:43:51Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![wulfgarpro](https://discourse.cmake.org/user_avatar/discourse.cmake.org/wulfgarpro/32/3186_2.png) [@wulfgarpro](https://discourse.cmake.org/u/wulfgarpro)
#### Post date: [February 20, 2023, 5:43am UTC](https://discourse.cmake.org/t/config-preset-in-cmakeuserpresets-json-doesnt-inherit-cachevariables-from-parent-in-cmakepresets-json/7497/1 "2023-02-20T05:43:51Z")

</div>

My `CMakePresets.json`:

```json
{
    "version": 3,
    "configurePresets": [
        {
            "name": "base",
            "hidden": true,
            "generator": "Ninja",
            "cacheVariables": {
                "CMAKE_C_COMPILER": "clang-cl",
                "CMAKE_CXX_COMPILER": "clang-cl",
                "CMAKE_C_FLAGS": "-fuse-ld=lld /EHsc",
                "CMAKE_CXX_FLAGS": "-fuse-ld=lld /EHsc"
            },
            "condition": {
                "type":"inList",
                "string": "${hostSystemName}",
                "list": ["Linux", "Windows"]
            }
        },
        {
            "name": "x64-debug",
            "displayName": "x64 Debug",
            "inherits": "base",
            "binaryDir": "${sourceDir}/build/x64/Debug",
            "architecture": {
                "value": "x64",
                "strategy": "external"
            },
            "cacheVariables": {
                "CMAKE_BUILD_TYPE": "Debug"
            }
        }
    ],
    "buildPresets": [
        {
            "name": "x64-debug",
            "configurePreset": "x64-debug"
        }
    ]
}

```

My `CMakeUserPresets.json`:

```json
{
    "version": 3,
    "configurePresets": [
        {
            "name": "x64-debug-special",
            "inherits": "x64-debug",
            "cacheVariables": {
                "CMAKE_C_FLAGS": "/winsdkdir /path",
                "CMAKE_CXX_FLAGS": "/winsdkdir /path"
            }
        }
    ],
    "buildPresets": [
        {
            "name": "x64-debug-special",
            "configurePreset": "x64-debug-special"
        }
    ]
}

```

When I run `cmake --debug-output --preset x64-debug-special`, the `CMAKE_C_FLAGS` and `CMAKE_CXX_FLAGS` aren’t the combined flags from `base` and `x64-debug-special` as I expect following from the documentation:

> Cache variables are inherited through the `inherits` field, and the preset’s variables will be the union of its own `cacheVariables` and the `cacheVariables` from all its parents. If multiple presets in this union define the same variable, the standard rules of `inherits` are applied. Setting a variable to `null` causes it to not be set, even if a value was inherited from another preset.

```auto
$ cmake --debug-output --preset x64-debug-special
Running with debug output on.
Preset CMake variables:

  CMAKE_BUILD_TYPE="Debug"
  CMAKE_CXX_COMPILER="clang-cl"
  CMAKE_CXX_FLAGS="/winsdkdir /path"
  CMAKE_C_COMPILER="clang-cl"
  CMAKE_C_FLAGS="/winsdkdir /path"

```

If I remove `cacheVariables` from the `x64-debug-special` preset, I can see that the `x64-debug` config preset’s `cacheVariables` are inherited.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [February 20, 2023, 2:15pm UTC](https://discourse.cmake.org/t/config-preset-in-cmakeuserpresets-json-doesnt-inherit-cachevariables-from-parent-in-cmakepresets-json/7497/2 "2023-02-20T14:15:56Z")

</div>

Cc: @kyle.edwards

---

<div class="post-metadata">

### Author: ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)
#### Post date: [February 20, 2023, 8:57pm UTC](https://discourse.cmake.org/t/config-preset-in-cmakeuserpresets-json-doesnt-inherit-cachevariables-from-parent-in-cmakepresets-json/7497/3 "2023-02-20T20:57:24Z")

</div>

The part of the docs you quoted does not mean that values for the _same_ cache variable are merged, only that the _set_ of cache variables will be merged. If a preset sets a cache variable that one of the presets it inherits from also sets, the value from the inherited preset is _not_ used.

To make it more concrete, `CMAKE_C_FLAGS` and `CMAKE_CXX_FLAGS` from `x64-debug-special` will prevent the ones from `base` being used. You do not get both concatenated. The “merging” in this context is that you _do_ get `CMAKE_C_COMPILER` and `CMAKE_CXX_COMPILER` from `base`, along with `CMAKE_C_FLAGS` and `CMAKE_CXX_FLAGS` from `x64-debug-special`, and `CMAKE_BUILD_TYPE` from `x64-debug`.
