[CMake] Recursively calling a macro: Is this possible in CMake?
James Bigler
jamesbigler at gmail.com
Sat Jan 17 15:25:28 EST 2009
This is a classic graph traversing problem. Each target is a node in
the graph. What you need to do is make sure you only recurse on nodes
you haven't visited yet. You can probably do this with a list of
visited targets and use the list(FIND_ITEM) (double check the command
in the docs) to determine if you should recurse. Make sure to add the
new node to the visited list before you recurse.
James
On Jan 16, 2009, at 7:57 PM, "Robert Dailey" <rcdailey at gmail.com> wrote:
>
> 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/20090117/01211859/attachment.htm>
More information about the CMake
mailing list