[CMake] Indrect function calls
Eric Noulard
eric.noulard at gmail.com
Wed Sep 7 06:34:35 EDT 2011
2011/9/7 Firegurafiku <firegurafiku at gmail.com>:
> Is there a way to indirectly call a function which name is a variable?
> I want to do something like that:
>
> function(avr_compiler_gcc_cflags CFLAGS) ...
> function(avr_compiler_iar_cflags CGLAGS) ...
>
> set(COMPILER "gcc")
> call("avr_compiler_${COMPILER}_cflags" CFLAGS)
>
> Is there exists function similar to call()?
Not I don't think so.
I think what you were looking for was some kind of recursive evaluation
like TCL 'eval' command (http://wiki.tcl.tk/1017)
With CMake:
1) you can ask CMake for "double" evaluation
using nested dollar ($) var value:
Try:
set(COMP1_CFLAGS "Whatever")
set(COMP2_CFLAGS "OrElse")
set(COMPILER "COMP1")
set(CFLAGS ${${COMPILER}_CFLAGS})
message("CFLAGS=${CFLAGS}")
2) You can "emulate" function call evaluation using include
this is awkward but seems to work, see example attached.
That said adding a eval command to CMake could be fun,
even if I did never cross the urgent need for it.
--
Erk
Membre de l'April - « promouvoir et défendre le logiciel libre » -
http://www.april.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: function_call.cmake
Type: text/x-cmake
Size: 494 bytes
Desc: not available
URL: <http://www.cmake.org/pipermail/cmake/attachments/20110907/8fa3d818/attachment.bin>
More information about the CMake
mailing list