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

Marcel Loose loose at astron.nl
Fri Mar 6 05:40:15 EST 2009


Hi Dmitriy,

I don't really need this feature, but it would have made some tasks
easier to program in CMake. So, I thought, if it's possible, then how
should I do it. But, as it turns out it's not possible, I'll have to
find a different solution.

Thanks anyway.

Best regards,
Marcel Loose.


On Fri, 2009-03-06 at 12:05 +0200, Dmitriy Ovdienko wrote:
> Marcel,
> 
> I'm sorry. I supposed there is special command "command" to invoke
> code stored to variable.
> 
> I reread manual once more and did not find anything like
> meta-programing for CMake.
> 
> BTW, why do you need this feature?
> 
> Regards,
> Dmitriy
> 
> Friday, March 6, 2009, 10:37:37 AM, you wrote:
> 
> ML> Thanks for your reply Dmitriy,
> 
> ML> but... it does not solve what I wanted to do.
> 
> ML> If I understand the syntax page correctly, it says you can invoke the
> ML> macro/function named command and pass arguments stored in variable Foo
> ML> using the syntax command(${Foo}).
> 
> ML> But that's not what I meant. I was looking for a way to construct, on
> ML> the fly, a "meta-command" that would consist of a sequence of
> ML> macro/function calls. So, for example, suppose my meta-command is named
> ML> Foo, and I have three macros named a, b, and c. Then 'set(Foo a b c)'
> ML> would create my meta-command Foo, which when *executed* -- and the
> ML> question is: is this possible? -- causes the macros/functions a, b, and
> ML> c to be called in succession.
> 
> ML> So, the question remains, whether it's possible to do something I wrote
> ML> in my original post; i.e., invoking the macro do_it, through a variable
> ML> cmd that is holding the value 'do_it'.
> 
> ML> Kind regards,
> ML> Marcel Loose.
> 
> ML> 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