# Changes do not apply when changing an option variable

**URL:** https://discourse.cmake.org/t/changes-do-not-apply-when-changing-an-option-variable/9871
**Category:** Usage
**Created:** [January 17, 2024, 5:31pm UTC](https://discourse.cmake.org/t/changes-do-not-apply-when-changing-an-option-variable/9871 "2024-01-17T17:31:28Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![asimplecoder](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/f17d59/32.png) [@asimplecoder](https://discourse.cmake.org/u/asimplecoder)
#### Post date: [January 17, 2024, 5:31pm UTC](https://discourse.cmake.org/t/changes-do-not-apply-when-changing-an-option-variable/9871/1 "2024-01-17T17:31:28Z")

</div>

Hi everyone,

I noticed that when I change the value `ON\OFF` of some `option` variables, re-running `cmake -S -B [...]` without the `--fresh` flag does not apply the changes to those option variables.

From the [option CMake documentation](https://cmake.org/cmake/help/latest/command/option.html), I see:

> In CMake project mode, a boolean cache variable is created with the option value. In CMake script mode, a boolean variable is set with the option value.

So, being in project mode, generates a cache variable. Does this mean that every time I want to update them, even though changing them in `CMakeLists.txt`, I need to run a `--fresh` generation?

Thanks

---

<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: [January 17, 2024, 6:31pm UTC](https://discourse.cmake.org/t/changes-do-not-apply-when-changing-an-option-variable/9871/2 "2024-01-17T18:31:45Z")

</div>

How are you changing them? If it is:

```cmake
option(varname "docs" ON)
# ^^ here

```

This is the _default_ for the option. If the cache variable already exists, it is not updated. CMake has no mechanism to know “user set it to `OFF`” versus “the old default was `OFF`” when seeing this code.

See this post: [Project variants? - #5 by ben.boeckel](https://discourse.cmake.org/t/project-variants/205/5)

---

<div class="post-metadata">

### Author: ![asimplecoder](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/f17d59/32.png) [@asimplecoder](https://discourse.cmake.org/u/asimplecoder)
#### Post date: [January 17, 2024, 6:56pm UTC](https://discourse.cmake.org/t/changes-do-not-apply-when-changing-an-option-variable/9871/3 "2024-01-17T18:56:13Z")

</div>

Thanks for answering.

Yes, I’m basically changing where you specify.

> [@ben.boeckel](#):
>
> This is the _default_ for the option. If the cache variable already exists, it is not updated.

I get it. That’s why switching from `OFF` to `ON` was not producing any effect, and needed `--fresh` to regenerate the cache.

Is there a way of disabling caching? I guess it involves `set()`. But what if the user does pass a desired value though the command line. Does it avoid `set()` to override the value?

EDIT: to phrase the question better: what’s your best recommendation in such situations (default vs. user-defined)?

---

<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: [January 17, 2024, 7:50pm UTC](https://discourse.cmake.org/t/changes-do-not-apply-when-changing-an-option-variable/9871/4 "2024-01-17T19:50:54Z")

</div>

> [@asimplecoder](#):
>
> to phrase the question better: what’s your best recommendation in such situations (default vs. user-defined)?

See the link at the end of my previous post. The `<DEFAULT>` mechanism is the best available today that I know of.
