[CMake] Custom macro problem with boolean

J.S. van Bethlehem j.s.van.bethlehem at astro.rug.nl
Tue May 3 05:27:43 EDT 2011


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



More information about the CMake mailing list