[CMake] unset() command

Alan W. Irwin irwin at beluga.phys.uvic.ca
Wed Aug 20 11:54:16 EDT 2008


On 2008-08-20 10:54-0400 Brad King wrote:

> Philip Lowman wrote:
>> So I submitted a patch to add a new unset() command to CMake.  The
>> command will unset normal or cache variables (causing them to become
>> undefined).  The command also supports unsetting environment variables,
>> in case anyone has to do that.
>>
>> The primary use case that drove me to implement this was this:
>>
>> find_library(FOO_LIBRARY foo)
>> if(MSVC OR SEARCH_FOO_DEBUG)
>>     find_library(FOO_LIBRARY_DEBUG food)
>> else()
>>     unset(FOO_LIBRARY_DEBUG)
>>     set(FOO_LIBRARY_DEBUG ${FOO_LIBRARY})
>> endif()
>>
>> http://public.kitware.com/Bug/view.php?id=7507
>
> Okay, I see Bill wanted the discussion to be here, so ignore my other
> message.
>
> 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.

if(FOO)

still gives different results depending on whether there has ever been a set
command executed for the variable.  So unset would be useful in this case as
well to return the variable to the condition exactly as if set had never
been executed.  That's what you need to properly eliminate scope.  I don't
have a specific use case, but I think the whole idea of unset is a good one
from the point of view of eliminating scope of variables where you want to
assure yourself there will be no side effects.  This method of eliminating
scope would complement others that already exist for CMake.

Alan
__________________________
Alan W. Irwin

Astronomical research affiliation with Department of Physics and Astronomy,
University of Victoria (astrowww.phys.uvic.ca).

Programming affiliations with the FreeEOS equation-of-state implementation
for stellar interiors (freeeos.sf.net); PLplot scientific plotting software
package (plplot.org); the libLASi project (unifont.org/lasi); the Loads of
Linux Links project (loll.sf.net); and the Linux Brochure Project
(lbproject.sf.net).
__________________________

Linux-powered Science
__________________________


More information about the CMake mailing list