[CMake] PARENT_SCOPE for unset()?

David Cole david.cole at kitware.com
Fri Feb 10 10:16:23 EST 2012


On Fri, Feb 10, 2012 at 10:00 AM, Robert Dailey <rcdailey at gmail.com> wrote:

> Also I wonder what happens if you do this:
>
> set( var PARENT_SCOPE PARENT_SCOPE PARENT_SCOPE )
>

That sets var to "PARENT_SCOPE;PARENT_SCOPE" in the parent scope.



>
> ---------
> Robert Dailey
>
>
>
> On Fri, Feb 10, 2012 at 8:59 AM, Robert Dailey <rcdailey at gmail.com> wrote:
>
>> I actually found that using the following worked the exact same for me:
>>
>> set( var "" PARENT_SCOPE )
>>
>
>> It passed the "NOT" test in my if condition:
>>
>> if( NOT var )
>> ...
>> endif()
>>
>>
set(var)
  and
set(var "")

do two different things.

The first, set(var), unsets the variable such that it is not even DEFINED
as a variable.

The second, set(var ""), sets the variable such that is is DEFINED and has
the value of the empty string.

Similarly, with PARENT_SCOPE:
set(var PARENT_SCOPE)
  and
set(var "" PARENT_SCOPE)

The "if(NOT var)" test works the same for variables that are not defined or
are defined and empty.

The "if(NOT DEFINED var)" test does not.


"set(var)" was the way we did unset before the unset command existed.



> It might make more sense to require 2 parameters for set() (the variable
>> name and its value). If setting to nothing, use a blank string. That way
>> there is no ambiguity between PARENT_SCOPE and parameter 2.
>>
>> If people really want to unset the variable, I don't believe set() is the
>> way... that's why unset() exists. Just my opinion. Only problem is, if you
>> make this change, it isn't backward compatible and will probably break a
>> lot of scripts. Looks like CMake is kind of boned here. Herb Sutter made a
>> great point during GoingNative 2012 about how it's better to "not have a
>> feature" than to misdesign it and be stuck supporting it forever. I think
>> the latter part of the statement applies here :)
>>
>> This isn't a big deal though, just one of those "if we could change it,
>> this would make more sense" kind of things.
>>
>> Big thanks for your help David, as usual.
>>
>
Agreed. We all agree with this. But we *are* sticking with "set(var)" being
equivalent, ironically enough, to "unset(var)" for backwards compatibility,
because there are many CMakeLists files which depend on this behavior.


You're welcome.

Thanks for the discussion,
David



>
>> ---------
>> Robert Dailey
>>
>>
>>
>> On Thu, Feb 9, 2012 at 6:19 PM, David Cole <david.cole at kitware.com>wrote:
>>
>>> Yes, PARENT_SCOPE must occur as the last argument. Each command has its
>>> own code for processing its argument list. See Source/cmSetCommand.cxx for
>>> details on this one.
>>>
>>> Interesting (not quite the right adjective?) side effect: it's difficult
>>> to set a variable to the value "PARENT_SCOPE" because you have to do it
>>> indirectly...
>>>
>>>
>>> On Thu, Feb 9, 2012 at 7:12 PM, Robert Dailey <rcdailey at gmail.com>wrote:
>>>
>>>> That worked, thanks David.
>>>>
>>>> I guess CMake goes right-to-left for function parameters? I don't see
>>>> how else it doesn't think PARENT_SCOPE is a value instead of an option.
>>>>
>>>>  ---------
>>>> Robert Dailey
>>>>
>>>>
>>>>
>>>> On Thu, Feb 9, 2012 at 1:45 PM, David Cole <david.cole at kitware.com>wrote:
>>>>
>>>>> On Thu, Feb 9, 2012 at 2:41 PM, Robert Dailey <rcdailey at gmail.com>wrote:
>>>>>
>>>>>> I didn't try that because I thought it would actually treat
>>>>>> PARENT_SCOPE as a string and add it to the variable. I did this instead:
>>>>>>
>>>>>> set( var "" PARENT_SCOPE )
>>>>>>
>>>>>
>>>>> That leaves it set, with a value of the empty string, in the parent
>>>>> scope. Give the one I sent a try.
>>>>>
>>>>>
>>>>>
>>>>>>
>>>>>> ---------
>>>>>> Robert Dailey
>>>>>>
>>>>>>
>>>>>>
>>>>>> On Thu, Feb 9, 2012 at 1:26 PM, David Cole <david.cole at kitware.com>wrote:
>>>>>>
>>>>>>> On Thu, Feb 9, 2012 at 2:22 PM, Alexander Neundorf <
>>>>>>> a.neundorf-work at gmx.net> wrote:
>>>>>>>
>>>>>>>> On Thursday 09 February 2012, Robert Dailey wrote:
>>>>>>>> > It would seem useful to have a PARENT_SCOPE option for the
>>>>>>>> unset() command,
>>>>>>>> > just like its set() counterpart. Is there a particular reason why
>>>>>>>> it does
>>>>>>>> > not have it now?
>>>>>>>>
>>>>>>>> No, I think there is not particular reason.
>>>>>>>>
>>>>>>>> Alex
>>>>>>>> --
>>>>>>>>
>>>>>>>> Powered by www.kitware.com
>>>>>>>>
>>>>>>>> Visit other Kitware open-source projects at
>>>>>>>> http://www.kitware.com/opensource/opensource.html
>>>>>>>>
>>>>>>>> Please keep messages on-topic and check the CMake FAQ at:
>>>>>>>> http://www.cmake.org/Wiki/CMake_FAQ
>>>>>>>>
>>>>>>>> Follow this link to subscribe/unsubscribe:
>>>>>>>> http://www.cmake.org/mailman/listinfo/cmake
>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> Does:
>>>>>>>
>>>>>>>   set(var PARENT_SCOPE)
>>>>>>>
>>>>>>> have the intended effect?
>>>>>>>
>>>>>>> (If so, you could use that until such time as PARENT_SCOPE is added
>>>>>>> to unset.)
>>>>>>>
>>>>>>>
>>>>>>> --
>>>>>>>
>>>>>>> Powered by www.kitware.com
>>>>>>>
>>>>>>> Visit other Kitware open-source projects at
>>>>>>> http://www.kitware.com/opensource/opensource.html
>>>>>>>
>>>>>>> Please keep messages on-topic and check the CMake FAQ at:
>>>>>>> http://www.cmake.org/Wiki/CMake_FAQ
>>>>>>>
>>>>>>> Follow this link to subscribe/unsubscribe:
>>>>>>> http://www.cmake.org/mailman/listinfo/cmake
>>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>
>>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20120210/52965523/attachment-0001.htm>


More information about the CMake mailing list