[CMake] Can an option enforce a default, even if cache is present?

Eric Noulard eric.noulard at gmail.com
Tue Nov 27 11:13:47 EST 2018


Le mar. 27 nov. 2018 à 14:50, Mario Emmenlauer <mario at emmenlauer.de> a
écrit :

>
> Dear all,
>
> I've just discovered that option() behaves differently than I anticipated.
> After reading the docs and searching with google I'm still confused how to
> achieve my desired behaviour.
>
> What I've just learned is that unspecified options take their cached value
> and do *not* go back to their default value, if a cache exists. I assumed
> that options take their default when not explicitly specified.
>

The behavior of option() gained new behavior in CMake 3.13.
May be it could help in your particular case:
https://cmake.org/cmake/help/v3.13/policy/CMP0077.html#policy:CMP0077

you'll depend on latest CMake though.


>
> Now my problem: I could not find a way to get the behaviour I'd like. Is it
> possible to enforce the default for an option when its not specified by the
> user, even if a cache exists?
>

You mean you did not manage to force the cache value?
You can:
set(VAR "default_value" CACHE FORCE)

or the problem is you cannot know whether if a value has been user-provided?


> I tried to unset() the option from the cache but that does not do what I'd
> like.
>
> All the best,
>
>     Mario Emmenlauer
> --
>
> Powered by www.kitware.com
>
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Kitware offers various services to support the CMake community. For more
> information on each offering, please visit:
>
> CMake Support: http://cmake.org/cmake/help/support.html
> CMake Consulting: http://cmake.org/cmake/help/consulting.html
> CMake Training Courses: http://cmake.org/cmake/help/training.html
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Follow this link to subscribe/unsubscribe:
> https://cmake.org/mailman/listinfo/cmake
>


-- 
Eric
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake/attachments/20181127/bd686940/attachment.html>


More information about the CMake mailing list