[cmake-developers] Function overrides

Wojciech Knapik wmknapik at gmail.com
Thu Jun 6 05:23:52 EDT 2013


On Mon, Jun 03, 2013 at 09:11:07AM -0400, Brad King wrote:
> On 05/30/2013 04:16 PM, Wojciech Knapik wrote:
> > A few months pass, a few more modules get written and it all turns out
> > to work quite nicely, so I decide to publish them as open source, for
> > everyone's benefit. How do I distribute these modules and allow people
> > to use any combination of them ? Do I create a separate wrapper for
> > every combination ?
> 
> We've done this with many projects.  We just create a project-specific
> wrapper in the projects's own CMakeLists.txt files and then teach it
> to invoke all the third-party helpers we want.
> 
> include(FancyMod1)
> include(FancyMod2)
> function(myproj_add_executable)
>   add_executable(${ARGN})
>   fm1_help_exe(${ARGN})
>   fm2_help_exe(${ARGN})
> endfunction()

This is fine in the specific case, where I know which set of modules is
going to be used in the project. But I'd like to distribute a number of
modules, that only require "include(Module)" from the user. At the most,
there could be another module that does the function overrides. But the
key thing is, I don't know which subset of modules a user will choose,
so I can't blindly construct the overrides.

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.

I don't want to make the user do complex things, like creating overrides
for 4 functions - I know what needs to be done and I don't want to
require any explicit configuration from the user. Wouldn't it be nice if
you could just include a handful of modules and get support for
everything you need in your project ? That's what I'm trying to do here.

WK



More information about the cmake-developers mailing list