[CMake] Easier way to override variables

Alexander Neundorf a.neundorf-work at gmx.net
Wed Jul 25 16:52:46 EDT 2012


On Wednesday 18 July 2012, Yngve Inntjore Levinsen wrote:
> Hi Romain,
> 
> Have a look at the help for the function set:
> $ cmake --help-command set
> 
> If I understand the documentation, this should be what you are looking for:
> set(MY_VAR NEW_VALUE FORCE)

I don't think this does what you want.
It sets MY_VAR to "NEW_VALUE;FORCE".
set() without CACHE always sets/overrides anything set before.

The only time when you may need to enforce overriding is when the variable in 
question is a cache variable.

set(MY_VAR "foo" CACHE STRING "docs...")
set(MY_VAR "bar" CACHE STRING "docs...")

will leave MY_VAR at "foo", since setting a value in the cache only actually 
sets its value if it is not yet in the cache.
To set it anyway, you have to use FORCE:

set(MY_VAR "foo" CACHE STRING "docs...")
set(MY_VAR "bar" CACHE STRING "docs..." FORCE)

Using CACHE and non-CACHE variables with the same name may result in not quite 
obvious behaviour.

Alex
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20120725/97e421c9/attachment.htm>


More information about the CMake mailing list