[CMake] Create an XXXConfig.cmake file

Clinton Stimpson clinton at elemtech.com
Thu Nov 19 11:14:38 EST 2009


I think its basically setting variable to include paths, defines and 
libraries, that the calling CMakeLists.txt can use.  I make my 
*Config.cmake files look relative to their location and use an exports 
file from CMake for the libraries.


======= FooConfig.cmake ===
SET(FOO_EXPORT_FILE "${Foo_DIR}/FooExport.cmake")
SET(FOO_INCLUDE_DIRS "${Foo_DIR}/../include")
INCLUDE(${FOO_EXPORT_FILE})
SET(FOO_LIBRARY foo)

# build config stuff for Foo (requires configure_file)
SET(FOO_USE_BAR @FOO_USE_BAR@)
=======

Then in the CMakeLists.txt of Foo, I put a configure_file(... @ONLY) for 
the *Config.cmake file and add an
install(EXPORT Foo FILE FooConfig.cmake DESTINATION lib COMPONENT 
Development)

And for the install(EXPORT ...) to work, I use the EXPORT flag in 
install(TARGETS ...)
install(TARGETS foo EXPORT Foo ....)

To use
find_package(Foo)
include_directories(${FOO_INCLUDE_DIRS})
...
target_link_libraries(baz ${FOO_LIBRARY})

There may be a more official way, but that's kind of how I do them and 
it works nicely.

Clint

On 11/19/2009 08: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?
>
> Thanks
> _________________________________________________________
> Mike Jackson                  mike.jackson at bluequartz.net
> BlueQuartz Software                    www.bluequartz.net
> Principal Software Engineer                  Dayton, Ohio
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at 
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the CMake FAQ at: 
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake



More information about the CMake mailing list