[CMake] Possible to dynamically construct macro/function names to invoke?

Micha Hergarden micha.hergarden at gmail.com
Tue Jul 21 13:14:46 EDT 2015


On 07/20/2015 12:52 AM, Eric Wing wrote:
> I would like to dynamically construct a macro or function name to
> invoke. I basically have a core CMake system I want users to be able
> to extend/plug stuff into without knowing about a lot of the core
> CMake implementation. Callback functions would be an easy way for me
> to accomplish this.
>
> As an example,
>
> # In my core code, I have a macro designed to callback other macros
> macro(DO_PACKAGE _TARGET_NAME)
> 	foreach(callback ${DO_PACKAGE_CALLBACK_LIST})
> 		DO_PACKAGE_FOR_${callback}(${_TARGET_NAME})
> 	endforeach()
> endmacro(BLURRR_PACKAGE_EXTRAS)
>
>
> ### Also in my core code, I pick an appropriate time to trigger my
> macro to call user callbacks
> DERIVE_SOME_NAME()
> ADD_EXECUTABLE(${SOME_NAME} ...)
> DO_PACKAGE(${SOME_NAME})
>
>
>
> # So in user modules provided by others, they follow a convention where
> # they define a macro DO_PACKAGE_ appended by their module name.
> macro(DO_PACKAGE_FOR_MYMODULE _TARGET_NAME)
> 	MESSAGE("in mymod callback")
> 	# do stuff
> endmacro()
>
> # And I make them add their module name to a global list so I can call
> it back at the right time
> list(APPEND DO_PACKAGE_CALLBACK_LIST "MYMODULE")
>
>
> So in my attempts to do this, I'm getting errors like:
> Parse error.  Expected a command name, got unquoted argument with text
>
> Is there way to do this (or something similar)?
>
> Thanks,
> Eric
I don't think this functionality is supported (although I haven't
checked if it is possible to redefine a function in cmake). Perhaps you
could create a system where you import a cmake module supplied by the
external developers if it exists? If you can define an interface you
could check if the functions exist in the module?

Regards,
Micha

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: OpenPGP digital signature
URL: <http://public.kitware.com/pipermail/cmake/attachments/20150721/6046a281/attachment.sig>


More information about the CMake mailing list