[CMake] Create an XXXConfig.cmake file

James C. Sutherland James.Sutherland at utah.edu
Thu Nov 19 11:10:20 EST 2009


On Nov 19, 2009, at 8:24 AM, 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. Simple question:
> 
>  What goes in one of those? Is there a tutorial somewhere? Where does the file get installed into? What does the consumer of the file need to put into their cmake files?
> 
>  And what version of CMake does all that apply to?
> 

Mike,

I applaud this effort!  Now we just need a fully functional C++ interface for HDF5...

While I am somewhat of a novice at this, my experience is that the XXXConfig.cmake file basically replaces the FindXXX.cmake file and defines many of the same variables.

I suggest, however, that you use the "EXPORT" feature to generate a HDF5.cmake file that you include in your Config file.

For example, put something like the following in your CMakeLists.txt file:

#------- <snip> -------
# assume that "hdf5" is the library built...
install( TARGETS hdf5 EXPORT HDF5 DESTINATION lib/hdf5 )
install( EXPORT HDF5 DESTINATION lib/hdf5 )

configure_file(
  ${PROJECT_SOURCE_DIR}/HDF5Config.cmake.in
  ${PROJECT_BINARY_DIR}/config/HDF5Config.cmake
  @ONLY
  )
#------- </snip> -------


In your HDF5Configure.cmake.in file you might have something like:

#------- <snip> -------
set( HDF5_INCLUDE_DIR @HDF5_INCLUDE@ @TPL_INCLUDE_DIRS@ )
include( @CMAKE_INSTALL_PREFIX@/lib/hdf5/HDF5.cmake )
#------- </snip> -------

I have seen some packages install the Configure file in /share rather than /lib as well.

I just saw Brad's email come through.  He is actually the source of my understanding of the EXPORT approach...

HTH,

James


More information about the CMake mailing list