[CMake] Create an XXXConfig.cmake file

Brad King brad.king at kitware.com
Thu Nov 19 11:03:10 EST 2009


Michael Jackson wrote:
> So, there are a few of us quickly port the HDF5 1.8 code to CMake. I'm 
> thinking that we should put in an HDF5Config.cmake file for other 
> projects use.

Yes, it would be good to provide one of these.

> What goes in one of those?

It should compute and set variables named "HDF5_..." that refer to
the locations of everything installed along with the file.

 > Is there a tutorial somewhere?

Yes:

   http://www.cmake.org/Wiki/CMake_2.6_Notes#Packages

 > Where does the file get installed into?

Somewhere that find_package will look for it.  See here:

   http://www.cmake.org/cmake/help/cmake2.6docs.html#command:find_package

Likely it will be something like

   <prefix>/lib/cmake/hdf5-<version>/HDF5Config.cmake

or

   <prefix>/lib/hdf5-<version>/cmake/HDF5Config.cmake

if you already have a "<prefix>/lib/hdf5-<version>" directory in the
install tree for other purposes.

You should also install a HDF5ConfigVersion.cmake file next to it, as
covered in the tutorial.

 > What does the consumer of the file need to put into their cmake files?

find_package(HDF5 NO_MODULE)

The NO_MODULE option bypasses any FindHDF5 module that might otherwise
be used and looks only for HDF5Config.cmake.  Alternatively, the find
module should first try the above line and do its old thing only if the
config file is not found.  Then users can just write

find_package(HDF5)

> And what version of CMake does all that apply to?

CMake 2.6 and above have the best support.

-Brad


More information about the CMake mailing list