This is an archive of the discontinued LLVM Phabricator instance.

cmake: Set CMAKE_INSTALL_RPATH in Clang when building separately from LLVM
AbandonedPublic

Authored by plevine on Oct 4 2016, 11:14 PM.

Details

Reviewers
chandlerc
Summary

LLVM sets CMAKE_INSTALL_RPATH in its top-level CMakeLists.txt to "\$ORIGIN/../lib${LLVM_LIBDIR_SUFFIX}". When Clang is built with LLVM, this propagates to Clang as well and ensures that even if CMAKE_INSTALL_PREFIX is set, installed binaries always find their dependent libraries.

When compiling clang as a separately build, no such rpath is set. If CMAKE_INSTALL_PREFIX is not set and libraries are installed to standard locations, this is not a problem. But when defining CMAKE_INSTALL_PREFIX, even if the same as that of LLVM, and installing and then executing binaries like clang, it results in

error while loading shared libraries: libLLVMBPFCodeGen.so.4.0: cannot open shared object file: No such file or directory

In the case of using a separate CMAKE_INSTALL_PREFIX from LLVM's, eg., "/usr/lib/clang-4.0.0", the build needs rpaths for both its own libraries and that of LLVM. The build should set "\$ORIGIN/../lib${LLVM_LIBDIR_SUFFIX}:${LLVM_LIBRARY_DIR}" as the rpath in the general case. The rpath section was taken and modified from the top-level LLVM CMakeLists.txt.

Diff Detail

Event Timeline

plevine updated this revision to Diff 73593.Oct 4 2016, 11:14 PM
plevine retitled this revision from to cmake: Set CMAKE_INSTALL_RPATH in Clang when building separately from LLVM.
plevine updated this object.
plevine added a reviewer: chandlerc.
plevine added a subscriber: cfe-commits.

I presume you copied it out of LLVM. If that's the case, please add an comment above stating where it's been copied from.

I presume you copied it out of LLVM. If that's the case, please add an comment above stating where it's been copied from.

Yes. I copied it from LLVM's top-level CMakeLists.txt and added ${LLVM_LIBRARY_DIR} to the rpath.

plevine updated this object.Oct 5 2016, 1:13 AM
beanz added a comment.Oct 5 2016, 5:02 PM

This is actually not the right fix here. We should actually fix this in LLVM to setup the rpath correctly on the targets during llvm_add_executable, then we can remove this hack from LLVM instead of copying it to Clang. It might also let us fix the RPATH goop in other tools too.

This is actually not the right fix here. We should actually fix this in LLVM to setup the rpath correctly on the targets during llvm_add_executable, then we can remove this hack from LLVM instead of copying it to Clang. It might also let us fix the RPATH goop in other tools too.

Submitted for review: https://reviews.llvm.org/D25304

plevine abandoned this revision.Feb 6 2017, 10:26 AM

Fixed with rL285714.