[cmake-developers] Making Config.cmake files easier to write

Alexander Neundorf neundorf at kde.org
Tue Feb 14 14:54:56 EST 2012


On Tuesday 14 February 2012, Brad King wrote:
> On 2/14/2012 1:26 PM, Alexander Neundorf wrote:
> > Well, CMakeConfigHelpers.cmake would be shipped with cmake, so as long as
> > the Config.cmake file says
> > cmake_minimum_required(VERSION 2.8.8)
> > it would be fine.
> 
> ...and we have to maintain compatibility in the module no matter what.
> It is much easier if the config files are standalone.

Yes, that's a good point.
Another option would be to install the included file along the Config.cmake 
file.

> >> (2) The content of a relocatable BarConfig.cmake should not depend on
> >> where it happened to be installed when the package was built.
> > 
> > I don't see a real problem with this.
> > Actually it is a good thing if the Config.cmake file can detect whether
> > it is in the location where it should be according to
> > CMAKE_INSTALL_PREFIX, e.g. to ensure that the libraries are installed in
> > the right location (so the builtin RPATHs point to the right location).
> 
> Leaving remnants of the original build/install location is a no-no for
> packagers.

I don't know, we could ask them.
Actually I don't think it would be a problem for a Linux distro packager, 
since in this case the original install destination will be also the final 
actual install location.
I mean, they build the package for a place where it should be installed, and 
if you install the package via the normal package managers, this is where they 
will end up.

Also, this wouldn't leave anything of the original build location in the file, 
only the intended install location.
And this is what we do anyway since kdelibs 4.0. Right now we have code like 
this in KDE's installed files:

...
if (NOT KDE4_INSTALL_DIR)
   set(KDE4_INSTALL_DIR         "/home/alex/installs/kdelibs")
endif (NOT KDE4_INSTALL_DIR)

set(KDE4_LIB_INSTALL_DIR     "/home/alex/installs/kdelibs/lib")
set(KDE4_LIBEXEC_INSTALL_DIR "/home/alex/installs/kdelibs/lib/kde4/libexec")
set(KDE4_INCLUDE_INSTALL_DIR "/home/alex/installs/kdelibs/include")
...

and no packager ever complained that this would be a problem. 

> > How would that work if INCLUDE_INSTALL_DIR is an absolute path ?
> > set(BAR_INCLUDE_DIRS "@INCLUDE_INSTALL_DIR@")
> > 
> > Would the case that DATA_INSTALL_DIR and LIB_INSTALL_DIR point to
> > completely different locations be handled ?
> 
> See my discussion with Yuri in this thread.

I saw and replied, and can't really understand how I should write the 
BarConfig.cmake.in to make it work.

Alternatively, Yuri suggested this in a thread on kde-buildsystem, there could 
be a macro which completely generates the Config.cmake file.
This would get rid of a bunch of problems, like having to write complicated 
code in the Config.cmake file, but OTOH it would have to take quite a lot of 
parameters, e.g. how it should set up the LIBRARY variables from the exported 
targets, in which namespace they have been exported, etc.

This would be a quite big macro.

Alex



More information about the cmake-developers mailing list