[CMake] Question about sending a macro a list of items

alaterale at elitemail.org alaterale at elitemail.org
Thu Jul 28 14:27:34 EDT 2005


Thanks a lot!
The syntax is a little confusing to look at, but I understand now and it
works.  Is there any chance that this can be added to the public
documentation at www.cmake.org?
Thanks again :)

On Thu, 28 Jul 2005 13:45:55 -0400, "Brad King" <brad.king at kitware.com>
said:
> alaterale at elitemail.org wrote:
> > Hi again,
> > 
> > I have a quick question about the use of MACRO that I need answered.  I
> > want to be able to send a list of names to a MACRO that I made so I can
> > use that list in a FOREACH statement or in other statements.  How do I
> > do this?  It only seems to receive the first item in the list.
> > 
> > SET(ITEMS item1 item2 item3 item4)
> > 
> > MACRO(print itemlist)
> >     MESSAGE("${itemlist}")
> >     FOREACH(item ${itemlist})
> >        MESSAGE("${item}")
> >     ENDFOREACH(item)
> > ENDMACRO(print)
> > print(${ITEMS})
> > 
> > I would expect to see item1;item2;item3... and then a vertical list of
> > the same names.  But I only ever see the first item in the list.  Can
> > anyone help me?  I didn't notice that this was happening until much
> > later than when I wrote the code and I need to be able to do this.
> 
> Since the MACRO you've declared takes only one argument you have to use 
> it to pass the NAME of the variable containing the list.  Then you can 
> expand it inside the macro:
> 
> SET(ITEMS item1 item2 item3 item4)
> 
> MACRO(print itemlist)
>      MESSAGE("${${itemlist}}")
>      FOREACH(item ${${itemlist}})
>         MESSAGE("${item}")
>      ENDFOREACH(item)
> ENDMACRO(print)
> print(ITEMS)
> 
> -Brad


More information about the CMake mailing list