# CMakeUserPresets.json: how to store Cmake options usually passed to the command line with -D ??

**URL:** https://discourse.cmake.org/t/cmakeuserpresets-json-how-to-store-cmake-options-usually-passed-to-the-command-line-with-d/7603
**Category:** Usage
**Tags:** os:windows
**Created:** [March 4, 2023, 6:49am UTC](https://discourse.cmake.org/t/cmakeuserpresets-json-how-to-store-cmake-options-usually-passed-to-the-command-line-with-d/7603 "2023-03-04T06:49:47Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![netcorefan1](https://discourse.cmake.org/user_avatar/discourse.cmake.org/netcorefan1/32/3226_2.png) [@netcorefan1](https://discourse.cmake.org/u/netcorefan1)
#### Post date: [March 4, 2023, 6:49am UTC](https://discourse.cmake.org/t/cmakeuserpresets-json-how-to-store-cmake-options-usually-passed-to-the-command-line-with-d/7603/1 "2023-03-04T06:49:47Z")

</div>

Hello,  
after playing for hours in trying to do what is supposed to be the main purpose of the user presets, I have no other chances than opening a topic here.

I would like to store the options variables in CMakeUserPresets (rather then hardcoding them in scripts or whatever) and get them automatically merged to the main cmake configuration.  
I normally pass the main option through the command line with `-DMAINOPTION=ON` and I have automatically loaded all the dependent options. If I also pass a dependent option with `-DOPTIONOFMAINOPTION=value` it also gets automatically populated.  
How I can obtain the same through user presets?

I tried with `cacheVariables`, but when I click configure I just get such variable in the `ungrouped entries` and related dependent options don’t appear at all.  
Many thanks

---

<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: [March 6, 2023, 3:49pm UTC](https://discourse.cmake.org/t/cmakeuserpresets-json-how-to-store-cmake-options-usually-passed-to-the-command-line-with-d/7603/2 "2023-03-06T15:49:32Z")

</div>

Please post the `CMakeUserPresets.json` that you’re using, the `CMakeLists.txt`, an explanation of what you expect to happen, and what is actually happening. Please strip `CMakeUserPresets.json` and `CMakeLists.txt` down to minimal illustrative examples.

---

<div class="post-metadata">

### Author: ![netcorefan1](https://discourse.cmake.org/user_avatar/discourse.cmake.org/netcorefan1/32/3226_2.png) [@netcorefan1](https://discourse.cmake.org/u/netcorefan1)
#### Post date: [March 7, 2023, 11:40am UTC](https://discourse.cmake.org/t/cmakeuserpresets-json-how-to-store-cmake-options-usually-passed-to-the-command-line-with-d/7603/3 "2023-03-07T11:40:19Z")

</div>

Hello @kyle.edwards,  
I spent the last couple of days in trials and documentation and I finally managed to understand how the whole thing works. Basically I need to know in advance and provide the main options and their dependant options in order to get the expected configuration.  
I don’t want to abuse your time and I prefer to open a new topic when I will encounter some more serious problem. I will mark your response as the solution just because you have been so nice to offer me your help even for such stupid and annoying questions.  
Thanks

---

<div class="post-metadata">

### Author: ![ClausKlein](https://discourse.cmake.org/user_avatar/discourse.cmake.org/clausklein/32/352_2.png) [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)
#### Post date: [August 16, 2023, 1:38pm UTC](https://discourse.cmake.org/t/cmakeuserpresets-json-how-to-store-cmake-options-usually-passed-to-the-command-line-with-d/7603/4 "2023-08-16T13:38:04Z")

</div>

**IMHO** : Your questen should be answered:

This is a **CMakeUserPresets.json** that implicit includes `CMakePresets.json`, so you may extend or overwrite the settings of an exising `ConfigurePreset` i.e.:

```json
{
    "version": 6,
    "cmakeMinimumRequired": {
        "major": 3,
        "minor": 25,
        "patch": 0
    },
    "configurePresets": [
        {
            "name": "user-config",
            "description": "Example for user default settings that apply to all configurations",
            "generator": "Ninja",
            "inherits": "common-config",
            "cacheVariables": {
                "CMAKE_C_COMPILER": "gcc",
                "CMAKE_CXX_COMPILER": "g++"
            },
            "environment": { "VARIANT": "Clang" }
        }
    ]
}

```

**But this doesn’t change the prestes,** refering to or inherits from the original `common-config` preset!
