[CMake] Pass an array type argument to a macro

David Cole david.cole at kitware.com
Tue Jul 19 06:47:20 EDT 2011


On Tue, Jul 19, 2011 at 6:32 AM, Eric Noulard <eric.noulard at gmail.com> wrote:
> 2011/7/19 Laszlo Papp <lpapp at kde.org>:
>> Hi,
>>
>> Is there a way of passing array arguments to a macro with cmake ?
>
> Did you have a look at:
> CMakeParseArguments.cmake
>
> cmake --help-module CMakeParseArguments
>
> This makes it easier to parse KEYWORD arguments.
>
> [...]
>
>> The problem is that when I would like to use the aforementioned macro
>> like this:
>> UNIT_TESTS(
>>    ${CORE_LIBS}# libraries argument
>>    core # modulename argument
>>    objecttest
>> )
>
> Then using the indicated module you may turn your MACRO into
> something like:
>
> UNIT_TESTS(
>                    LIBRARIES ${CORE_LIBS}
>                    MODULENAME core
>                    TEST objecttests)
> [...]
>
>> The workaround can be that I determine an internal variable that can
>> be filled out with the proper content and use that internally inside
>> the macro, but I do not consider that nice solution. The best would be
>> if we can somehow pass array type arguments to the cmake macro. Is
>> that possible ? Does it already somehow work like that ?
>
> Keyword introduced arguments + ParseArgument should work.
>
> --
> Erk
> Membre de l'April - « promouvoir et défendre le logiciel libre » -
> http://www.april.org
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake
>


Or, if you want to keep your original signature, because it's simpler
than "parsing" arguments, simply call it like this:

UNIT_TESTS(
  core # modulename argument
  "${CORE_LIBS}" # libraries argument
  objecttest
)

Putting double quotes around "${CORE_LIBS}" will make the whole
expansion of CORE_LIBS be the value of the "libraries" symbol inside
your macro...

HTH,
David


More information about the CMake mailing list