After building with CMake on Linux (but before installing), all the linked libraries are added to the final executable's RPATH.
However, I would like to prepend $ORIGIN/../lib: to this RPATH.
So far, I've only been able to replace the RPATH, and that's not what I want: I want ld.so to first look in ../lib. This is what I currently do:
set_target_properties(foo PROPERTIES
BUILD_WITH_INSTALL_RPATH TRUE
INSTALL_RPATH "\$ORIGIN/../lib:...")
While this works, it's missing some additional third-party libraries that are not part of my build tree, and who are not located in system directories.
Doing chrpath -l foo gives me the exact same INSTALL_RPATH above. If I don't set those properties, I get the long list of DSO locations, e.g. RPATH=/bar/baz/:/quux/ etc. (the one I'd like to prepend to).
I've tried using get_property(_existing_rpath foo INSTALL_RPATH), but that gives me an empty string
I've read the hints at https://cmake.org/Wiki/CMake_RPATH_handling and noticed under "CMake Bugs" that
At least on CMake 2.6.4 RHEL5, man cmakecommands for INSTALL_RPATH_USE_LINK_PATH pretends that this setting will append the link path to any CMAKE_INSTALL_RPATH content one specified. However, on this version, enabling INSTALL_RPATH_USE_LINK_PATH will replace it.
Well, not so sure about this any more: just verified this on CMake 2.8.0, and now on both versions it does list correct changes in cmake_install.cmake. This bug may have occurred due to previously not doing per-target install(), or perhaps due to some other changes in CMake RPATH-related variables.
By the way, I'm only interested in getting a working RPATH for the built files, as in before having run install. I haven't configured the installation properly (added install targets and so on). Do I need to look into that part for this to work?
If you can't find answers on Google, it's often the case that the answer is obvious. This seems to work just fine:
set_target_properties(foo PROPERTIES
BUILD_WITH_INSTALL_RPATH TRUE
INSTALL_RPATH_USE_LINK_PATH TRUE
INSTALL_RPATH "\$ORIGIN/../lib:${INSTALL_RPATH}")
On my system (and CMake 3.6.1), it seems INSTALL_RPATH begins with a colon, but I wouldn't count on it. Also, since I'm obviously setting the global INSTALL_RPATH here, it may be overspecified (I haven't checked).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With