[cmake-developers] Function overrides
Wojciech Knapik
wmknapik at gmail.com
Thu May 30 14:01:16 EDT 2013
On Thu, May 30, 2013 at 11:39:01AM -0400, Brad King wrote:
> On 05/30/2013 11:14 AM, Wojciech Knapik wrote:
>
> > The problem is, that you can't redefine, say, add_executable more than
> > once, as discussed here:
> > http://www.cmake.org/pipermail/cmake/2011-March/043320.html
>
> The command-override feature is meant for local debugging only.
>
> Allowing "recursive" overrides is ill-defined because of the
> way functions are (not) scoped when the same module is included
> in multiple disjoint directories.
When you do:
function(add_executable)
message("A")
_add_executable(${ARGN})
endfunction()
function(add_executable)
message("B")
_add_executable(${ARGN})
endfunction()
you'd think that the "A" version of add_executable(), once parsed, would
be immutable, but defining the "B" version seems to change the meaning
off _add_executable() retroactively, affecting the "A" version.
I hate to say it again, but that is surprising ;-)
> > PS. I know you can achieve this by providing a wrapper for the user to
> > use instead of the standard function, but that's not nearly as nice, is
> > it ?
>
> As someone reading code I like knowing that a command does
> what the CMake documentation says it does and nothing more.
I agree, that you shouldn't do this if you're changing the signature of
the function, or any of the functionality described in the
documentation. But if you're only using the original function as a
"hook" to perform some additional action it seems totally acceptable to
me. It provides a nice way to create "zeroconf" modules. And if things
go sideways, the stack trace will make this case distinguishable from an
error in the original function.
CMake does not provide any meta-programming facility, not even the
simplest "eval" function, so it would be nice if at least this mechanism
worked in a more generally useful way...
WK
More information about the cmake-developers
mailing list