[cmake-developers] Function overrides
David Cole
dlrdave at aol.com
Thu Jun 6 07:53:32 EDT 2013
> Err, I meant eval(some_func()) in the wrapper, not
> eval(include(Module)). Sorry for the top-post, using
> my phone.
> If CMake had at least an eval() function, I could
> append any of my modules included to a list and
> then eval("include Module") for each
> element in the list. But that's not possible.
While CMake does not have an eval function directly, this *is*
effectively possible. The trick, though, is that you have to generate a
script.cmake file (using file(WRITE or configure_file...) and then
include *it*.
So, you could do something like:
# assumes mod1.cmake and mod2.cmake already exist
set(modules mod1.cmake mod2.cmake)
file(WRITE "${CMAKE_BINARY_DIR}/script.cmake" "") # file initially
empty
foreach(mod ${modules})
file(APPEND "${CMAKE_BINARY_DIR}/script.cmake"
"include(\"${mod}\")\n")
endforeach()
include("${CMAKE_BINARY_DIR}/script.cmake")
HTH,
David
More information about the cmake-developers
mailing list