Automatically setting the RPATH - make use of $ORIGIN ?

Alexander Neundorf neundorf at kde.org
Sat Feb 23 13:17:00 UTC 2013


On Saturday 23 February 2013, Stephen Kelly wrote:
> Alexander Neundorf wrote:
> > Hi,
> > 
> > in kdelibs4 and, when using FindKF5.cmake, we set the RPATH automatically
> > by using the cmake target property INSTALL_RPATH_USE_LINK_PATH, and
> > additionally we add ${LIB_INSTALL_DIR} if it is not a system library
> > directory.
> > 
> > This means we set a bunch of absolute directories as RPATH.
> > RPATH supports $ORIGIN, which seems to refer to the location of the
> > current ELF file.
> > Using $ORIGIN ELF files can be made, at least in this regard,
> > relocatable. When using INSTALL_RPATH_USE_LINK_PATH, cmake sets all
> > paths to already installed libraries. It does not add the path to shared
> > libraries from the current installation, that's why we add
> > LIB_INSTALL_DIR.
> > 
> > So we could use $ORIGIN in shared libraries we install (so they find
> > other shared libs in the same directory), $ORIGIN/../ in plugins and
> > $ORIGIN/../lib/ in executables (not completely correct, but it should
> > show the idea).
> > 
> > But now that we don't have kde4_add_executable(), kde4_add_library() and
> > kde4_add_plugin() anymore, we cannot easily do this.
> > 
> > Should I try to get this into cmake, so it makes use of $ORIGIN when
> > suitable ?
> 
> Can this suitability be determined in cmake, or would it be a user option?

There should probably be a target property like USE_RELATIVE_INSTALL_RPATH or 
USE_RELOCATABLE_INSTALL_RPATH or something similar.
It's two things.
First IMO cmake should also consider the shared libs installed by the project 
itself for using in the INSTALL_RPATH, they are not taken into account 
currently. We'll have to so what to do if a shared lib is installed more than 
once, but that's probably not the common case.
So let's say we add the directory of the in-project shared libs to the install 
rpath.
Then, for each of the directories in the install rpath which matches
<prefix>/lib(64)?/(multiarch/)?, and the target is installed under the same 
<prefix>, use $ORIGIN.


> I think it's at least worth raising on the cmake list.

Yes.

> > Or should we leave it to the developers to set RPATH that way ?
> > Or do we want to keep those macros ?
> > 
> > Alex
> > 
> > (... I guess I know the answer. but won't that make us require new
> > versions of cmake quite often ?)
> 
> Assuming you mean the first option, why would it make us require new
> versions of cmake often?

With the kde4_add_executable() etc. macros we were able to add things there, 
while keeping the required minimum cmake version. Without those macros, either 
the developer has to do it manually, or we have to upstream it into cmake, and 
then require the new version (in cases where it's necessary for producing a 
working result, which is not the case with RPATH here).

Alex


More information about the Kde-buildsystem mailing list