Quantcast

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

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

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

Sergey Zakharchenko
Hello list,

I've been using CMake for quite some time and have only now found out
this disturbing difference between SET(X) and SET(X ""). It happens in
cmake -P mode when you try to unset variables which are defined on the
command line, e.g.

cmake -DX=Y -P x.cmake

This x.cmake gives "X=Y":

SET(X)
MESSAGE("X=${X}")

This, too, gives "X=Y":

UNSET(X)
MESSAGE("X=${X}")

This one finally gives "X=" (which I would have expected in the first place):

SET(X "")
MESSAGE("X=${X}")

Is this OK? Is this documented anywhere?

Best regards,

--
DoubleF
--

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:
http://public.kitware.com/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: cmake -DX=Y -P : problem unsetting variables defined on command line

Nils Gladitz-2
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
--

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:
http://public.kitware.com/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: cmake -DX=Y -P : problem unsetting variables defined on command line

Sergey Zakharchenko
Hello Nils,

>> cmake -DX=Y -P x.cmake
>
>
> The above sets the *cache* variable X.

OK, I didn't think that really applied as the script is executed
standalone, so there's no cache in the regular sense of the word.
Thanks for the explanation.

Best regards,

--
DoubleF
--

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:
http://public.kitware.com/mailman/listinfo/cmake
Loading...