[CMake] unset() command
Fernando Cacciola
fernando.cacciola at gmail.com
Mon Aug 25 10:25:20 EDT 2008
Alan W. Irwin wrote:
> On 2008-08-20 14:07-0400 Brad King wrote:
>
>> Alan W. Irwin wrote:
>>> if(FOO)
>>>
>>> still gives different results depending on whether there has ever been a
>>> set command executed for the variable.
>>
>> Really? Can you provide example code demonstrating this?
>
> OOPS. Sorry for that noise.
>
> However, I would like to point out there is still a documentation concern
> here. Here is what is stated about DEFINED
>
> if(DEFINED variable)
>
> True if the given variable is defined. It does not matter if the
> variable is true or false just if it has been set.
>
> So if you interpret the command "set(FOO)" as setting the variable, then
> the
> documentation implies
>
> if(DEFINED FOO)
>
> will be true, but in fact my tests show it is false (both in 2.4.8 and
> 2.6.0) just like you stated. A small addition to this area of the
> documentation concerning the special case of set(variable) (i.e., with no
> value) is warranted. Also, the documentation for the SET command currently
> (2.6.1) says the variable is removed from the parent scope when there is no
> value. Shouldn't you either drop the "parent" adjective (or better yet
> in my
> view) simply say the variable is undefined (as if it had never been set),
> instead?
>
IMO it should be documented even more precisely, because set(var) clears
the "in memory" value of the variable, but it doesn't clear it in the
cache, thus, if the variable happens to be in the cache, any operation
that needs its value will in fact fetch it back from the cache.
This undocumented feature is in fact the way to get variables out of
subdirs:
root/CMakeLists.txt
add_subdirectory(sub)
set(result)
message( STATUS "result=${result}" )
root/sub/CMakeLists.txt
set(result "I'm a subdir result!" cache internal "" force )
HTH
Fernando Cacciola
More information about the CMake
mailing list