cmake and RPATH

Alexander Neundorf neundorf at kde.org
Wed Mar 1 19:34:30 CET 2006


Hi,

On Thursday 16 February 2006 23:01, Brad King wrote:
> Brad King wrote:
> > FYI, I've been working on an implementation in CMake to relink targets
> > with an install-tree RPATH before installing.  This is needed even if
> > you don't want any RPATH in the install tree to remove the RPATH that
> > points to the build tree.
>
> Okay, I've committed support for RPATH configuration in CVS CMake.  It
> is no longer possible for an installed target to have an RPATH pointing
> at the build tree (unless the programmer specifically lists the build
> tree in the new INSTALL_RPATH target property).
>
> The support isn't yet well-tested because I just finished the
> implementation.  KDE will be a good non-trivial test case to try it out.
>   See the documentation of the SET_TARGET_PROPERTIES command (relevant
> portion included below).
>
> There seem to be two use cases KDE needs to meet for which a different
> RPATH configuration is needed:
>
> 1.) Users will want to build and install KDE without any relinking.  In
> this case we can set CMAKE_BUILD_WITH_INSTALL_RPATH so that the targets
> get built directly with their final install-tree RPATH.  The executables
> will not be able to safely run from the build tree in this case.
>
> 2.) Developers may want to build KDE and run an application from the
> build tree for testing or debugging.  In this case the default CMake
> behavior will cause targets in the build tree to have an RPATH pointing
> to their whole link path.  Executables will then run from the build tree
> without any problem finding their libraries.  If the developer does
> install the targets will be relinked in a separate location with the
> install-tree RPATH and then be installed.
>
> It will be up to the CMake code in KDE to determine which of the above
> cases to use in a particular build tree.  One simple solution is
>
> option(KDE4_BUILD_FOR_DEVELOPER "Enable running from build tree." OFF)
> if(NOT KDE4_BUILD_FOR_DEVELOPER)
>    set(CMAKE_BUILD_WITH_INSTALL_RPATH 1)
> endif(NOT KDE4_BUILD_FOR_DEVELOPER)
>
> -Brad
>
>
> SET_TARGET_PROPERTIES
>    Targets can have properties that affect how they are built.
>
>      SET_TARGET_PROPERTIES(target1 target2 ...
>                            PROPERTIES prop1 value1
>                            prop2 value2 ...)
> [snip]
>    There are a few properties used to specify RPATH rules.  INSTALL_RPATH
>    is a semicolon-separated list specifying the rpath to use in installed
>    targets (for platforms that support it).  SKIP_BUILD_RPATH is a
>    boolean specifying whether to skip automatic generation of an rpath
>    allowing the target to run from the build tree.
>    BUILD_WITH_INSTALL_RPATH is a boolean specifying whether to link the
>    target in the build tree with the INSTALL_RPATH.  This takes
>    precedence over SKIP_BUILD_RPATH and avoids the need for relinking
>    before installation.  When the target is created the values of the
>    variables CMAKE_INSTALL_RPATH, CMAKE_SKIP_BUILD_RPATH, and
>    CMAKE_BUILD_WITH_INSTALL_RPATH are used to initialize these
>    properties.


Ok, how about these options for KDE:

1) Build without RPATH at all:

set(CMAKE_SKIP_RPATH ON)

2) Build with RPATH to the builddir:

# nothing required, no relinking will happen

3) Build with RPATH only to the install dir:

set(CMAKE_BUILD_WITH_INSTALL_RPATH ON)

With this option executables will not run if the libs have not yet been 
installed.


4) Build with RPATH to both install and build dir

set_target_properties( kde-config PROPERTIES INSTALL_RPATH 
"${LIBRARY_OUTPUT_DIR};${LIBRARY_INSTALL_PATH}" )

Is this possible ?
If yes, will this have the effect that the linker will first look in the 
builddir and after that in the install dir ? If so, is this the desired 
order ?


For 1) and 3): The executables will not run without the libs already 
installed. For this case simple shell scripts could be created which set 
(DY)LD_LIBRARY_PATH accordingly, so that these executables can be run by 
running the small wrapper shell scripts.

Do we need all these four options ? Or is our preferred option actually still 
missing ? Personally I'd like to have option 1) available.

So, what do you think ?

Bye
Alex
-- 
Work: alexander.neundorf AT jenoptik.com - http://www.jenoptik-los.de
Home: neundorf AT kde.org                - http://www.kde.org
      alex AT neundorf.net               - http://www.neundorf.net


More information about the Kde-buildsystem mailing list