[CMake] Problem with if() and booleans

Philip Lowman philip at yhbt.com
Sat Mar 21 23:35:22 EDT 2009


On Sat, Mar 21, 2009 at 10:01 PM, Robert Dailey <rcdailey at gmail.com> wrote:

> On Sat, Mar 21, 2009 at 7:42 PM, Philip Lowman <philip at yhbt.com> wrote:
>
>> On Sat, Mar 21, 2009 at 8:00 PM, Robert Dailey <rcdailey at gmail.com>wrote:
>>
>>> I currently have the following macro:
>>>
>>> macro( get_conf_dependencies var_name project_name debug )
>>>    if( debug )
>>>        message( "Using DEBUG" )
>>>        set( ${var_name} ${${project_name}_DEBUG_DEPENDENCIES} )
>>>    else()
>>>        set( ${var_name} ${${project_name}_RELEASE_DEPENDENCIES} )
>>>    endif()
>>> endmacro()
>>> I then call the macro in two particular ways:
>>> get_conf_dependencies( myVar myProject TRUE )
>>> get_conf_dependencies( myVar myProject FALSE )
>>> In both cases, I *do not* get the message "Using DEBUG". Are my eyes
>>> playing tricks on me, or is CMake not processing trivial boolean logic
>>> properly in its conditionals? I'm using version 2.6.3.
>>>
>>
>> I ran into the same issue a while back.  Use a function() or actual
>> variables in your call to get_conf_dependencies.
>> http://public.kitware.com/Bug/view.php?id=8397
>>
>
> What do you mean by "actual variables"?
>

You could do this:

set(myBool TRUE)
get_conf_dependencies(myVar myProject myBool)
...provided you change "if(debug)" to "if(${debug})" in your macro.

Making it a function() and using PARENT_SCOPE is probably a cleaner option:
set( ${var_name} ${${project_name}_RELEASE_DEPENDENCIES} PARENT_SCOPE)

-- 
Philip Lowman
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20090321/25451484/attachment.htm>


More information about the CMake mailing list