# Inheriting complier flags from multiple config presets.

**URL:** https://discourse.cmake.org/t/inheriting-complier-flags-from-multiple-config-presets/15195
**Category:** Usage
**Created:** [September 24, 2025, 12:48pm UTC](https://discourse.cmake.org/t/inheriting-complier-flags-from-multiple-config-presets/15195 "2025-09-24T12:48:04Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![pmf-honeywell](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/p/b77776/32.png) [@pmf-honeywell](https://discourse.cmake.org/u/pmf-honeywell)
#### Post date: [September 24, 2025, 12:48pm UTC](https://discourse.cmake.org/t/inheriting-complier-flags-from-multiple-config-presets/15195/1 "2025-09-24T12:48:04Z")

</div>

Is it possible to have multiple configuration presets that add compiler options to CMAKE\_CXX\_FLAGS?

For example,

```auto
{
  "name": "common-presets",
  "hidden": true,
  "cacheVariables": {
    "CMAKE_CXX_FLAGS_INIT": "-Dproperty-1"
}

{
  "name": "specific-presets",
  "hidden": true,
  "cacheVariables": {
    "CMAKE_CXX_FLAGS_INIT": "-Dproperty-2"
}

```

```auto
{
  "name": "My-Target",
  "description": "My Release target.",
  "displayName": "My_Release_Target",
  "inherits": ["common-presets", "specific-presets"],
  "cacheVariables": {
    "CMAKE_BUILD_TYPE": "Release",
    "CMAKE_CXX_FLAGS_INIT": "-Dproperty-3"
  }
}
-
I would expect to see -DCMAKE_CXX_FLAGS_INIT:STRING="-Dproperty-1 -Dproperty-2 -Dproperty-3"

But I see 
-DCMAKE_CXX_FLAGS_INIT:STRING="-Dproperty-3"

```

Am I doing something wrong or are my expectations incorrect?

---

<div class="post-metadata">

### Author: ![LegalizeAdulthood](https://discourse.cmake.org/user_avatar/discourse.cmake.org/legalizeadulthood/32/5282_2.png) [@LegalizeAdulthood](https://discourse.cmake.org/u/LegalizeAdulthood)
#### Post date: [September 24, 2025, 4:32pm UTC](https://discourse.cmake.org/t/inheriting-complier-flags-from-multiple-config-presets/15195/2 "2025-09-24T16:32:29Z")

</div>

> [@pmf-honeywell](#):
>
> Is it possible to have multiple configuration presets that add compiler options to CMAKE\_CXX\_FLAGS?

At this point, presets can only set individual cache variables to single values. There’s no way to accumulate values into a cache variable.

A workaround is to have your presets set separate variables specific to your CMakeLists.txt and to accumulate the flags yourself.

---

<div class="post-metadata">

### Author: ![pmf-honeywell](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/p/b77776/32.png) [@pmf-honeywell](https://discourse.cmake.org/u/pmf-honeywell)
#### Post date: [September 24, 2025, 4:35pm UTC](https://discourse.cmake.org/t/inheriting-complier-flags-from-multiple-config-presets/15195/3 "2025-09-24T16:35:13Z")

</div>

Thanks for the reply

---

<div class="post-metadata">

### Author: ![Flumbrix](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/f/aeb1de/32.png) [@Flumbrix](https://discourse.cmake.org/u/Flumbrix)
#### Post date: [October 15, 2025, 7:23pm UTC](https://discourse.cmake.org/t/inheriting-complier-flags-from-multiple-config-presets/15195/4 "2025-10-15T19:23:41Z")

</div>

Another alternative is to set environment variables and combine them at the last preset into the variable. That way CMakeLists.txt doesn’t need to be changed.

With something like the following:

```json
{
  "name": "common-presets",
  "hidden": true,
  "environment": {
    "PRESET_COMMON_CXX_FLAGS": "-Dproperty-1"
  }
},
{
  "name": "specific-presets",
  "hidden": true,
  "environment": {
    "PRESET_SPECIFIC_CXX_FLAGS": "-Dproperty-2"
  }
},
{
  "name": "My-Target",
  "description": "My Release target.",
  "displayName": "My_Release_Target",
  "inherits": ["common-presets", "specific-presets"],
  "cacheVariables": {
    "CMAKE_BUILD_TYPE": "Release",
    "CMAKE_CXX_FLAGS_INIT": "$env{PRESET_COMMON_CXX_FLAGS} $env{PRESET_SPECIFIC_CXX_FLAGS} -Dproperty-3"
  }
}

```
