[PATCH] D25267: cmake: Set CMAKE_INSTALL_RPATH in Clang when building separately from LLVM

2016-10-04 Thread Peter Levine via cfe-commits
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


[PATCH] D25267: cmake: Set CMAKE_INSTALL_RPATH in Clang when building separately from LLVM

2016-10-05 Thread Peter Levine via cfe-commits
plevine added a comment.

In https://reviews.llvm.org/D25267#561955, @mgorny wrote:

> 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.


https://reviews.llvm.org/D25267



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D25267: cmake: Set CMAKE_INSTALL_RPATH in Clang when building separately from LLVM

2016-10-06 Thread Peter Levine via cfe-commits
plevine added a comment.

In https://reviews.llvm.org/D25267#562941, @beanz wrote:

> 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 



https://reviews.llvm.org/D25267



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits