[CMake] cmake -DX=Y -P : problem unsetting variables defined on command line

Nils Gladitz nilsgladitz at gmail.com
Thu Feb 9 10:26:05 EST 2017


On 02/09/2017 04:10 PM, Sergey Zakharchenko wrote:

> cmake -DX=Y -P x.cmake

The above sets the *cache* variable X.

> This x.cmake gives "X=Y":
>
> SET(X)
> MESSAGE("X=${X}")

The above unsets the *regular* variable X (leaving the cache variable X 
intact).

> This, too, gives "X=Y":
>
> UNSET(X)
> MESSAGE("X=${X}")

This also unsets the *regular* variable X.
To unset the cache variable unset(X CACHE) would have worked.

> This one finally gives "X=" (which I would have expected in the first place):
>
> SET(X "")
> MESSAGE("X=${X}")

Now you've got both a regular and cache variable named X.
When expanded the regular variable takes precedence.

> Is this OK? Is this documented anywhere?

https://cmake.org/cmake/help/v3.7/manual/cmake-language.7.html#variables

Nils


More information about the CMake mailing list