Issue
Is there a way to call a function in CMake using the name that is stored in a variable (for passing functions to functions, etc)?
cmake_minimum_required(VERSION 3.0)
function(doThing)
endfunction()
set(FuncVar doThing)
${FuncVar}()
Which fails with this error:
Parse error. Expected a command name, got unquoted argument with text "${FuncVar}".
-- Configuring incomplete, errors occurred!
I can't see why this shouldn't work, but then again I am new to CMake so what do I know.
Thank you for any help!
Solution
I have solved this with a workaround using files.
Lets say you have:
function(do what)
...
endfunction()
You want to call different specializations depending on 'what'. You can then do:
function(do what)
include("do-${what}.cmake")
do_dynamic()
endfunction()
And in file do-something.cmake:
function(do_dynamic)
...
endfunction()
You can create as many specialization files as you want...
Answered By - Meros Answer Checked By - Terry (WPSolving Volunteer)