[CMake] Pass an array type argument to a macro

I. Bue i.buengener at enervision.de
Tue Jul 19 12:05:38 EDT 2011


On 07/19/11 10:57, Laszlo Papp wrote:
> Hi,
>
> Is there a way of passing array arguments to a macro with cmake ?
>

You can simply pass the arguments "by-name" instead of "by-value" and
then double-dereference them inside your macro ( ${${arg}} ).
The design of your macro determines which of its arguments take values
or names of variables.

macro(testmacro simplearg listarg) #both arguments want variables
    message(STATUS "simplearg: ${${simplearg}}")
    #foreach(listitem IN ITEMS ${${listarg}})
    foreach(listitem IN LISTS ${listarg})
        message(STATUS "listitem: ${listitem}")
    endforeach()
endmacro(testmacro)

set(testlist ONE TWO THREE FOUR)
set(testvar testvalue)
testmacro(testvar testlist)




More information about the CMake mailing list