[CMake] Call a macro through a variable. Possible or not?

Marcel Loose loose at astron.nl
Fri Mar 6 03:37:37 EST 2009


Thanks for your reply Dmitriy,

but... it does not solve what I wanted to do.

If I understand the syntax page correctly, it says you can invoke the
macro/function named command and pass arguments stored in variable Foo
using the syntax command(${Foo}).

But that's not what I meant. I was looking for a way to construct, on
the fly, a "meta-command" that would consist of a sequence of
macro/function calls. So, for example, suppose my meta-command is named
Foo, and I have three macros named a, b, and c. Then 'set(Foo a b c)'
would create my meta-command Foo, which when *executed* -- and the
question is: is this possible? -- causes the macros/functions a, b, and
c to be called in succession.

So, the question remains, whether it's possible to do something I wrote
in my original post; i.e., invoking the macro do_it, through a variable
cmd that is holding the value 'do_it'.

Kind regards,
Marcel Loose.

On Thu, 2009-03-05 at 17:21 +0200, Dmitriy Ovdienko wrote:
> Hello Marcel,
> 
> Quote from http://cmake.org/cmake/help/syntax.html
> 
> 
> CMake supports simple variables that can be either strings or lists of strings.
> Variables are referenced using a ${VAR} syntax. Multiple arguments can be grouped
> together into a list using the set command. All other commands expand the lists as
> if they had been passed into the command with white-space separation. For example,
> 
>   set(Foo a b c)
> 
> will result in setting the variable Foo to a b c, and if Foo is passed into another command
> 
>   command(${Foo})
> 
> 
> Thursday, March 5, 2009, 2:19:34 PM, you wrote:
> 
> ML> Hi,
> 
> ML> I was wondering whether it's possible to invoke a macro through a
> ML> variable. The variable contains a command (or list of commands) to be
> ML> invoked.
> 
> ML> For example:
> 
> ML> macro(do_it)
> ML>   message(STATUS "do_it")
> ML> endmacro(do_it)
> 
> ML> set(cmd do_it)
> ML> ${cmd}()      # <-- This doesn't work, but is there a way to do this?
> 
> ML> Best regards,
> ML> Marcel Loose
> 
> 
> ML> _______________________________________________
> ML> Powered by www.kitware.com
> 
> ML> Visit other Kitware open-source projects at
> ML> http://www.kitware.com/opensource/opensource.html
> 
> ML> Please keep messages on-topic and check the CMake FAQ at:
> ML> http://www.cmake.org/Wiki/CMake_FAQ
> 
> ML> Follow this link to subscribe/unsubscribe:
> ML> http://www.cmake.org/mailman/listinfo/cmake
> 
> 
> 



More information about the CMake mailing list