[CMake] Recursively calling a macro: Is this possible in CMake?

Robert Dailey rcdailey at gmail.com
Fri Jan 16 21:57:50 EST 2009


On Fri, Jan 16, 2009 at 6:23 PM, James Bigler <jamesbigler at gmail.com> wrote:

> This code seems to produce the correct output with either a macro or a
> function prototype.
>
> macro( foo )
>   list( APPEND my_list "+" )
>   list( LENGTH my_list length )
>   if( length LESS ${somevar} )
>     foo()
>   endif()
>   # Add this line in for functions
>   set( my_list ${my_list} PARENT_SCOPE )
> endmacro()
>
> set(somevar 100)
> set(my_list "")
> foo()
> message("my_list = ${my_list}")
>
>
> My guess is that the code isn't necessarily inlined, but interpreted on the
> fly with special rules about variable scope.
>
> James


Well my real code is slightly more complex. When I run it I get infinite
recursion of some sort and I have to forcefully close CMake in order to stop
it. Recursion in CMake isn't entirely intuitive so if someone could breeze
over this code and give me some pointers I'd really appreciate that.


macro( add_includes_impl target_name )
    get_target_property( target_dependencies ${target_name}
LINK_INTERFACE_LIBRARIES )
    foreach( dep ${target_dependencies} )
        if( IS_TARGET ${dep} )
            message( "${dep}" )
            list( APPEND flattened_includes ${dep_includes} )
            add_includes_impl( ${dep} )
        endif()
    endforeach()
endmacro()

macro( add_includes target_name )
    set( flattened_includes )
    add_includes_impl( target_name )
endmacro()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20090116/9eb05c48/attachment.htm>


More information about the CMake mailing list