[CMake] how to deal with custom cmake modules ?

Brad King brad.king at kitware.com
Wed Feb 8 09:27:35 EST 2006


Alexander Neundorf wrote:
> I'm not sure how to handle the following: 
> in kdelibs/ I have a bunch of custom cmake modules, located in 
> kdelibs/cmake/modules/. When compiling kdelibs/ I just set 
> CMAKE_MODULE_PATH to ${CMAKE_SOURCE_DIR}/cmake/modules/ and it works. 
> Then kdelibs/ has to be installed. 
>  
> After that, when compiling something which depends on kdelibs/, e.g. 
> kdebase/, I'd like to reuse the cmake modules from kdelibs/. 
[snip]
> What do you suggest ? 

Make kdelibs a CMake Package for use with FIND_PACKAGE.  Section 6.7 of 
Mastering CMake describes this approach.  See here for some examples:

http://www.vtk.org/cgi-bin/viewcvs.cgi/Utilities/LastConfigureStep/CMakeLists.txt?view=markup
http://www.vtk.org/cgi-bin/viewcvs.cgi/vtkGenerateVTKConfig.cmake?view=markup
http://www.vtk.org/cgi-bin/viewcvs.cgi/VTKConfig.cmake.in?view=markup

http://cvs.sourceforge.net/viewcvs.py/vxl/vxl/config/cmake/export/CMakeLists.txt?view=markup
http://cvs.sourceforge.net/viewcvs.py/vxl/vxl/config/cmake/Modules/VXLConfig.cmake.in?view=markup

Basically there would be a KDELibsConfig.cmake file installed somewhere 
in the KDE install tree (and another in the build tree).  This file 
would contain a bunch of variable settings that tell projects where to 
find everything else such as your custom modules, the include path, and 
the library path.  Then calling FIND_PACKAGE(KDELibs) would NOT find a 
FindKDELibs.cmake and instead create a KDELibs_DIR cache entry that 
points at a directory containing KDELibsConfig.cmake.  This would be the 
only cache entry in the user project that is related to finding KDELibs, 
which makes it easy for users to switch which version of KDELibs to use 
if multiple are available.

The advantage of this approach is that all the find logic is built into 
CMake so no special search logic needs to be copied into every project 
that wants to find KDELibs.  Also if it is not found automatically the 
user need set at most one cache entry.

-Brad


More information about the CMake mailing list