[CMake] Custom macro problem with boolean

Michael Wild themiwi at gmail.com
Tue May 3 05:34:25 EDT 2011


On 05/03/2011 11:27 AM, J.S. van Bethlehem wrote:
> Miguel Bernabeu wrote:
>> Hi there,
>>
>> I have a problem recently in a project I'm trying to port to CMake. My
>> installed CMake version is 2.8.4 from Debian testing. I require
>> version 2.6.2 as a minimum and CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS is
>> set to TRUE.
>>
>> This is my macro:
>>
>> MACRO(ENGINE_LIST engine enginestring)
>>     if(${engine})
>>         set(ENABLED_ENGINES "${ ENABLED_ENGINES}${enginestring}\n")
>>     elseif(NOT ${engine})
>>         set(NOT ENABLED_ENGINES "${
>> NOTENABLED_ENGINES}${enginestring}\n")
>>     endif()
>> ENDMACRO(ENGINE_LIST)
>>
>> This macro takes boolean parameter, selected or not in the
>> configuraction menu, and a string. If it is true, the string is added
>> to a list of enabled engines, if not, to a list of not enabled engines.
>>
>> Example:
>>
>> set(SCUMMVM_ENGINE_AGI FALSE CACHE BOOL "Build the AGI Engine")
>> engine_list(SCUMMVM_ENGINE_AGI "Build the AGI Engine")
>>
>> message(STATUS "Enabled:"\n\n)
>> message(STATUS "${ENABLED_ENGINES}\n")
>> message(STATUS "Not Enabled:"\n\n)
>> message(STATUS "${NOTENABLED_ENGINES}\n")
>>
>> The problem is that no matter if SCUMMVM_ENGINE_AGI is true or false,
>> it is always caught in the ELSE clause. I've tried everything I could
>> think of but I find myself lost. Could anyone point me to the flaw I'm
>> unable to see?
>>
>> Thank you,
>> Miguel
> Given what seems to be your goal with this template, my first guess
> would be that you need to call the macro as:
> engine_list(${SCUMMVM_ENGINE_AGI} "Build the AGI Engine")
> 
> Jakob

No, that would result in an error message. This is because of the way
that macros work. They are literally text-replacement-engines, and the
arguments aren't really variables. The semantics are a bit confusing,
and usually it is better to use functions instead.

Michael



More information about the CMake mailing list