cmake and RPATH
Brad King
brad.king at kitware.com
Thu Feb 16 23:01:00 CET 2006
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.
More information about the Kde-buildsystem
mailing list