[CMake] Finding packagaes build with CMake

Alexander Neundorf a.neundorf-work at gmx.net
Mon Mar 9 19:40:39 EDT 2009


On Thursday 05 March 2009, Klaus wrote:
> Hi,
>
> after looking through the documentation of CMake, I am a litte confused,
> how to help CMake to find packages  bulit by CMake.
>
> The "find_package" command supports both xxx-config.cmake and
> FindXXX.cmake. What is the prefered method for an package which was built
> by CMake to be "found"? Should it provide a xxx-config.cmake or a
> FindXXX.cmake file?

It should provide an xxx-config.cmake file, it cannot provide a FindXXX.cmake 
file (since this would exist only if the project is installed, and could only 
be found if cmake already knows where the project is installed, so it's 
purpose would be kind of void).

> Is there any mechanism in CMake wich helps to create xxx-config.cmake
> files? 

Hmm, not really.
Just create a file which contains appropriate set() commands, e.g. 
set(FOO_INCLUDE_DIR <some>/<dir>)
via file(WRITE) or configure_file() and then install that file.

> Should the import/export feature be used within the xxx-config.cmake 
> files, or is this a bad idea?

It can be used in conjunction with it. I would suggest to include the 
export-files in the xxx-config.cmake file.

> And finally, is there a way to get the "real" install destination of the
> "install" command? Depending on wheather the destination is a realtive or
> absulute path, the "install" command either prepends "CMAKE_INSTALL_PREFIX"
> or not. However the complete path (either with or without prefix) is needed
> within the xxx-config.cmake file.

You can use e.g. 
get_filename_component(_myCurrentDir ${CMAKE_CURRENT_LIST_FILE} PATH)
in the toplevel of the xxx-config.cmake file to get the current location of 
it.

Alex


More information about the CMake mailing list