[CMake] functions as first class objects

Michael Wild themiwi at gmail.com
Wed Nov 18 01:48:45 EST 2009


On 18. Nov, 2009, at 7:25 , David Manura wrote:

> On Fri, Nov 13, 2009 at 3:58 AM, Michael Wild wrote:
>> Something like this just came up recently:
>> http://www.cmake.org/pipermail/cmake/2009-October/032725.html
>
> That would be better than nothing, though it does have a limitation in
> that you cannot wrap a function more than once.

Well, that shouldn't be necessary. If you need to do different things  
for different sub-projects, you can stuff it all in the same wrapping  
and use an external variable to determine which behavior is used.  
Along these lines:


function(install)
   if(CUSTOM_INSTALL_SWITCH STREQUAL A)
     # some code for case A
   elseif(CUSTOM_INSTALL_SWITCH STREQUAL B)
     # some code for case B
   endif()
   _install(${ARGN}
endfunction()

set(CUSTOM_INSTALL_SWITCH A)
add_subdirectory(projectA)

set(CUSTOM_INSTALL_SWITCH B)
add_subdirectory(projectB)


More information about the CMake mailing list