Allow separate CMAKE_INSTALL_RPATH for libraries and executables
When a project builds both executables and libraries, the RUNPATH often will be wrong for one or the other.
Assume the following installed layout:
/usr/bin/foo
/usr/bin/foo_bar
/usr/lib64/foo/libfoo_core.so
/usr/lib64/foo/libfoo_extra.so
foo
links to libfoo_core
, foo_bar
to both libs, and libfoo_extra
links to libfoo_core
.
Obviously, the RUNPATH for the executable should be /usr/lib64/foo
, or for a relocatable package, $ORIGIN/../lib64/foo
, while libfoo_extra
needs /usr/lib64/foo
or $ORIGIN
.
As one can see, for a non-relocatable package the RUNPATH fits both, but for a relocatable package the required RUNPATH depends on the location relative to the install prefix (in this case /usr
).
CMake already differentiates between libraries and executables when install
ing files, doing the same for RPATHs would be nice. The same likely applies to libexecdir executables, as a third category.
The RPATH can be set as a target property explicitly, but this becomes quite verbose and repetitive when a project builds many libraries and executables.