cmake invoking dynamic macro name -


i have 2 macro names, example:

macro(my_macro1) # stuff use in macro endmacro()  macro(my_macro2) # stuff use in macro endmacro() 

i'd dynamic call macros based variable name, example:

if (...) set (ver 1) else () set (ver 2) endif () my_macro${ver} # idea 

any help?

as @tsyvarev has commented cmake doesn't support dynamic function names. here alternatives:

simple approach

macro(my_macro ver)     if(${ver} equal 1)         my_macro1()     elseif(${ver} equal 2)         my_macro2()     else()         message(fatal_error "unsupported macro")     endif() endmacro()  set(ver 1) my_macro(ver) set(ver 2) my_macro(ver) 

a call() function implementation

building on @fraser work here more generic call() function implementation:

function(call _id)     if (not command ${_id})         message(fatal_error "unsupported function/macro \"${_id}\"")     else()         set(_helper "${cmake_binary_dir}/helpers/macro_helper_${_id}.cmake")         if (not exists "${_helper}")             file(write "${_helper}" "${_id}(\$\{argn\})\n")         endif()         include("${_helper}")     endif() endfunction()  set(ver 1) call(my_macro${ver}) set(ver 2) call(my_macro${ver}) 

Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -