plevine created this revision.
plevine added a reviewer: chandlerc.
plevine added a subscriber: cfe-commits.
Herald added subscribers: mgorny, beanz.

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.


https://reviews.llvm.org/D25267

Files:
  CMakeLists.txt


Index: CMakeLists.txt
===================================================================
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -77,6 +77,20 @@
     set(LLVM_SHLIB_OUTPUT_INTDIR ${LLVM_LIBRARY_OUTPUT_INTDIR})
   endif()
 
+  set(CMAKE_BUILD_WITH_INSTALL_RPATH OFF)
+  if (APPLE)
+    set(CMAKE_INSTALL_NAME_DIR "@rpath")
+    set(CMAKE_INSTALL_RPATH "@executable_path/../lib:${LLVM_LIBRARY_DIR}")
+  else(UNIX)
+    if(NOT DEFINED CMAKE_INSTALL_RPATH)
+      set(CMAKE_INSTALL_RPATH 
"\$ORIGIN/../lib${LLVM_LIBDIR_SUFFIX}:${LLVM_LIBRARY_DIR}")
+      if(${CMAKE_SYSTEM_NAME} MATCHES "(FreeBSD|DragonFly)")
+        set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-z,origin")
+        set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} 
-Wl,-z,origin")
+      endif()
+    endif(NOT DEFINED CMAKE_INSTALL_RPATH)
+  endif()
+
   option(LLVM_INSTALL_TOOLCHAIN_ONLY
     "Only include toolchain files in the 'install' target." OFF)
 


Index: CMakeLists.txt
===================================================================
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -77,6 +77,20 @@
     set(LLVM_SHLIB_OUTPUT_INTDIR ${LLVM_LIBRARY_OUTPUT_INTDIR})
   endif()
 
+  set(CMAKE_BUILD_WITH_INSTALL_RPATH OFF)
+  if (APPLE)
+    set(CMAKE_INSTALL_NAME_DIR "@rpath")
+    set(CMAKE_INSTALL_RPATH "@executable_path/../lib:${LLVM_LIBRARY_DIR}")
+  else(UNIX)
+    if(NOT DEFINED CMAKE_INSTALL_RPATH)
+      set(CMAKE_INSTALL_RPATH "\$ORIGIN/../lib${LLVM_LIBDIR_SUFFIX}:${LLVM_LIBRARY_DIR}")
+      if(${CMAKE_SYSTEM_NAME} MATCHES "(FreeBSD|DragonFly)")
+        set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-z,origin")
+        set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,origin")
+      endif()
+    endif(NOT DEFINED CMAKE_INSTALL_RPATH)
+  endif()
+
   option(LLVM_INSTALL_TOOLCHAIN_ONLY
     "Only include toolchain files in the 'install' target." OFF)
 
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to