Changes do not apply when changing an option variable

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, 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

How are you changing them? If it is:

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

Thanks for answering.

Yes, I’m basically changing where you specify.

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)?

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