2011/9/7 Firegurafiku <fireguraf...@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
function(f_blah ARG)
  message("Hello I'm function Blah(ARG=${ARG}) !!")
endfunction(f_blah)

function(f_foo ARG)
  message("Hello I'm function Foo(ARG=${ARG}) !!")
endfunction(f_foo)

if (NOT DEF_ONLY)
   list(APPEND nl foo blah)
   set(REALARG "nocall")
   foreach(name IN LISTS nl)
      message("Calling p_${name}()")
      file(WRITE temp_call.cmake "f_${name}(REALARG)")
      include(temp_call.cmake OPTIONAL)   
      file(REMOVE temp_call.cmake)
   endforeach(name)
endif(NOT DEF_ONLY)
_______________________________________________
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

Reply via email to