Making writing Config.cmake files easier - updated example

Yury G. Kudryashov urkud.urkud at gmail.com
Sun Jan 15 20:07:47 UTC 2012


15 January 2012 20:06:51 Alexander Neundorf written:
> Hi,
> 
> I create a new branch ImprovedConfigDotCMakeFile in the kdeexamples
> repository, used by the buildsystem/HowToInstallALibrary/ example:
> http://quickgit.kde.org/?p=kdeexamples.git&a=tree&h=9c8e84b16079b35f15c50ea0
> 27bbc95bd387bf90&hb=6caa67be56231d3017859a26db2097b8c8826f4e&f=buildsystem/H
> owToInstallALibrary
> 
> It adds two new macros, currently called determine_installed_location() and
> set_absolute() which should help with that.
> Once polished, they should go into cmake (2.8.8), so everybody can use them.
The only comment: there are 4 possible combinations of
cmake -DLIB_INSTALL_DIR=relative_or_absolute -
DINCLUDE_INSTALL_DIR=relative_or_absolute
It seems that your library will not be relocatable if INCLUDE_INSTALL_DIR is 
set to an absolute path.
> 
> With these two new macros, the developer does not have to calculate the
> relative and absolute paths himself anymore, but can rely on their logic.
> Also the CMakeLists.txt becomes a bit simpler, by removing the IMO most
> obscure part (the calculation of the relative install dir).
> 
> Comments ?
I'm working on another way to solve the same problem. I'll commit results to 
kdeexamples tonight or tomorrow.

Basically, my goal is a macro that writes and installs *Config.cmake files in 
"simple" cases and makes library available to find_package() both from another 
subdirectory of the same project and after installation. What do you think 
about this approach?

The proposed syntax is:

install_cmake_config_files(Package
LIBRARY_TARGETS (target|NAME=target)+ [EXECUTABLE_TARGETS (NAME=target)+]
[VERSION version=PACKAGE_VERSION] [VERSION_STRING <var|value>]
[EXPORT_NAME name=Package] [EXPORT_NAMESPACE ns="" or Package?]
[DESTINATION destination=platform-specific default]
[INSTALLED_INCLUDES dirs=${INCLUDE_INSTALL_DIR} or 
${CMAKE_INSTALL_INCLUDEDIR}]
[BUILD_INCLUDES dirs=${CMAKE_CURRENT_SOURCE_DIR}]
[EXTRA_VARS (name|name=value)*] [EXTRA_CONFIG_FILE file])

The macros will:
0. Set all unspecified parameters to sane defaults, so in many cases you'll 
just have to set package name, LIBRARY_TARGETS, EXPORT_NAME and 
EXPORT_NAMESPACE. BTW, is it possible to query which EXPORT does the given 
target belongs to? Or the other way around, the 
1. Write PackageConfig-external.cmake and install it to 
DESTINATION/PackageConfig.cmake.
2. Write PackageConfig.cmake and call export(PACKAGE Package).
3. Call install(EXPORT).

The PackageConfig-external.cmake will contain (pseudo-cmake.in, @ONLY):
set(@PACKAGE at _VERSION @PACKAGE_VERSION@)
set(@PACKAGE at _VERSION_STRING @PACKAGE_VERSION_STRING@) // if present

get_filename_component(ICCF_CWD ${CMAKE_CURRENT_LIST_FILE} PATH)
set(@PACKAGE at _INCLUDE_DIRS ${ICCF_CWD}/@RELATIVE_PATH_TO_INSTALLED_INCLUDES@)
include(@EXPROT_NAME at .cmake) // Export file
// Next line for each NAME=target in EXECUTABLE_TARGETS
set(@PACKAGE at _@NAME at _EXECUTABLE @EXPORT_NAMESPACE@@target@)
// Next line for each NAME=target in LIBRARY_TARGETS
set(PACKAGE_ at NAME@_LIBRARY @EXPORT_NAMESPACE@@target@)
set(PACKAGE_LIBRARIES @EXPORT_NAMESPACE@@ALL_LIBRARIES_IN_LIBRARY_TARGETS@)

// Next line for each NAME=value in EXTRA_VARS
set(@NAME@ @value@)
// Next line for each 'var' in EXTRA_VARS
set(@var@ @${var}@)

@EXTRA_CONFIG_FILE_CONFIGURED@

The PackageConfig.cmake will contain the same information adjusted for 
"internal" usage.
-- 
Yury G. Kudryashov,
mailto: urkud at mccme.ru
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 230 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.kde.org/pipermail/kde-buildsystem/attachments/20120116/eb1c8f25/attachment.sig>


More information about the Kde-buildsystem mailing list