[CMake] FindXXX, XXXConfig and UseXXX

Fernando Cacciola fernando.cacciola at gmail.com
Mon Feb 18 15:34:05 EST 2008


Hi,

Consider a library XXX that uses cmake as it's build system. Here's what I 
think those three files should do:

XXXConfig.cmake should be generated by the cmake script that configures the 
library and it should contain the settings specific to that configuration 
(such as source and binary folders, detected third party dependencies, 
needed flags, etc)

FindXXX.cmake should search a user's system for an instance of 
XXXConfig.cmake (using XXX_DIR and defaults paths). If it finds it, it 
should load that XXXConfig.cmake.

UseXXX.cmake should set include directories, libraries, compiler and linker 
flags, etc, based on the settings defined in a XXXConfig.cmake that must has 
been processed already.

XXXConfig.cmake should define a XXX_USE_FILE with the full path to the 
UseXXX.cmake file.

XXX users would load XXX in their own programs via:


find_package(XXX)

if ( XXX_FOUND )

  include( ${XXX_USE_FILE} )

endif()


If FindXXX.cmake is found in the paths specified by CMAKE_MODULE_PATH, it is 
loaded by find_package(XXX).
If not, but the user sets XXX_DIR to some binary folder for some 
installation of XXX, the above code works still by loading XXXConfig.cmake 
directly (witout going through FindXXX..cmake)

Is all that correct?

Is so, how should FindXXX and UseXXX distributed?
Ideally they should go to the standard modules folder of cmake since this 
way users don't have to point CMAKE_MODULE_PATH correctly, but do I do that? 
Having the configuration script copy them doesn't work in Vista because of 
the access restrictions to ProgramFiles.
Putting them in the binary folder works, but doesn't seem right (only 
XXXConfig.cmake should go there).
Any other ideas?

Best


-- 
Fernando Cacciola
SciSoft
http://fcacciola.50webs.com
http://groups.google.com/group/cppba






More information about the CMake mailing list