Making writing Config.cmake files easier - updated example

Yury G. Kudryashov urkud.urkud at gmail.com
Tue Jan 17 19:34:50 UTC 2012


Alexander Neundorf wrote:

> On Tuesday 17 January 2012, Yury G. Kudryashov wrote:
>> so we need to ensure (or document?) that the
>> same directory used while writing MyLibConfig.cmake and installing it.
> 
> Hmm, I don't understand exactly what you mean, can you please explain a
> bit more ?
Look at the following code:

set(CMAKECONFIG_INSTALL_DIR lib/cmake/MyLib)
#MyLibConfig hardcodes $prefix/lib/cmake/MyLib
configure_file(MyLibConfig.cmake.in MyLibConfig.cmake)
#but is actually installed to a different directory
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/MyLibConig.cmake DESTINATION 
lib/cmake)

My points are:
1. The contents of MyLibConfigVersion.cmake does not depend on the 
DESTINATION argument that will be passed to install(FILES).
2. MyLibConfig.cmake content does.
3. Writing MyLibConfig.cmake to ${CMAKE_CURRENT_BINARY_DIR} is an 
implementation detail, not a part of "public" API. We can hide this file by 
placing it to CMakeFiles subdirectory.

So, the macro should be called 'install_basic_config_file()'.

P.S.: There is another "and" that I'll remove. The current version writes an 
"external" (installed) *and* internal (for use from another subdirectory) 
versions of MyLibConfig.cmake.
-- 
Yury G. Kudryashov,
mailto: urkud at mccme.ru



More information about the Kde-buildsystem mailing list