[CMake] unset() command
Fernando Cacciola
fernando.cacciola at gmail.com
Mon Aug 25 10:31:26 EDT 2008
Brad King wrote:
> Philip Lowman wrote:
>> On Wed, Aug 20, 2008 at 10:54 AM, Brad King <brad.king at kitware.com
>> <mailto:brad.king at kitware.com>> wrote:
>>
>> The "set" command already supports unsetting:
>>
>> set(FOO xyz)
>> set(FOO) # unsets
>> if(DEFINED FOO)
>> message("This message does not appear.")
>> endif(DEFINED FOO)
>>
>> I think it should just be fixed for CACHE and ENV variables.
>>
>>
>> I knew that set() supported unsetting local variables but wasn't sure it
>> would be safe to extend it to CACHE and ENV variables as a bugfix.
>> Regardless of whether this is appropriate to do or not adding an unset()
>> command also seemed to make the language simpler to understand because:
>> set(FOO)
>> as someone else pointed out, is somewhat confusing. Without referencing
>> the documentation many programmers might think this defines a variable
>> called FOO and sets it to empty but what it really is doing is
>> *undefining* the variable FOO entirely if it exists.
>
> Okay, I agree. It will be easier and more readable to add the unset
> command than to extend the "set" command to "unset" things :)
>
> However, this:
>
> unset(MY_CACHE_VARIABLE)
>
> should not remove the cache entry. It should only unset the CMake
> variable. In order to remove the cache entry, we should require
>
> unset(MY_CACHE_VARIABLE CACHE)
>
> Otherwise there is no way to remove the variable without removing the
> cache entry.
>
Makes sense.
And while you are it.. I currently use: set(var) to read the value
back from the cache (very usefull somtimes), but this is undocumented
and extremely none-obvous, so, can we have a "fetch(var)" as well?
Should I formally suggest that via a bug report?
TIA
Fernando Cacciola
More information about the CMake
mailing list