[cmake-developers] Remove RPATH on install

Brad King brad.king at kitware.com
Wed Sep 28 16:34:21 EDT 2016


On 09/28/2016 04:09 PM, Ruslan Baratov via cmake-developers wrote:
> `<libname> -Wl,-rpath,<libdir>` to CMAKE_EXE_LINKER_FLAGS.

That adds it in a way that hides its presence from CMake.  CMake has its
own way to specify RPATH entries in the build tree.  It will replace the
build-tree-only entries with install-tree-only entries (if any) during
installation.  Any entries it doesn't know about are assumed to be added
by the toolchain and are thus preserved.

If one uses target_link_libraries to link each executable explicitly
to the shared library via absolute path to the library file then IIRC
CMake will put the RPATH in the build tree for that and remove it on
installation.

> adding new one, like CMAKE_INSTALL_DELETE_RPATH?

We don't actually define any kind of first-class RPATH-update operation.
It is only an implementation detail that we edit the RPATH on installation.
In principle the design is that there is a build tree RPATH and an install
tree RPATH.  On non-ELF platforms we actually need to re-run the linker
to produce the install tree version.  Therefore CMAKE_INSTALL_DELETE_RPATH
would not fit within our model.

Instead one could add a BUILD_RPATH target property with CMAKE_BUILD_RPATH
variable that specifies additional entries to put in the build tree RPATH.
This would be the build-tree equivalent to the INSTALL_PATH target property.

-Brad


More information about the cmake-developers mailing list