I want to override an option, which formely was set to OFF. I am using
SET(USE_OPTION ON CACHE BOOL "Override option" FORCE)
Just for my curiosity: Why do I need 'FORCE' (without it, the set() does not work)
I want to override an option, which formely was set to OFF. I am using
SET(USE_OPTION ON CACHE BOOL "Override option" FORCE)
Just for my curiosity: Why do I need 'FORCE' (without it, the set() does not work)
From the docs:
I assume the previous option was also
CACHE
.So, if you don't specify
FORCE
it doesn't get added to the cache as per above.Options are variables meant to be changeable by the user after the configuration step and before the actual build enviroment generation through tools like the
cmake-gui
,ccmake
or through the-D
command line switch.That's why they are cached in the first place. The choice the user has done has to be persisted. So
is an equivalent to
So to change or force an "user definable value" / cached variable you have to
FORCE
it.Or hide/overwrite it for the current variable scope with a non-cached variable:
Reference