[PATCH] D25304: cmake: Set the proper rpath in add_llvm_executable and llvm_add_library
Peter Levine via llvm-commits
llvm-commits at lists.llvm.org
Sun Oct 9 20:41:33 PDT 2016
plevine updated the summary for this revision.
plevine updated this revision to Diff 74092.
https://reviews.llvm.org/D25304
Files:
CMakeLists.txt
cmake/modules/AddLLVM.cmake
Index: cmake/modules/AddLLVM.cmake
===================================================================
--- cmake/modules/AddLLVM.cmake
+++ cmake/modules/AddLLVM.cmake
@@ -312,6 +312,29 @@
"RC_PRODUCT_VERSION=\"${ARG_VERSION_STRING}\"")
endfunction(set_windows_version_resource_properties)
+# Set the proper rpath for shared libraries and executables
+function(set_rpath name)
+ set_target_properties( ${name} PROPERTIES BUILD_WITH_INSTALL_RPATH ON )
+ if (APPLE)
+ set_target_properties( ${name} PROPERTIES INSTALL_NAME_DIR "@rpath" )
+ set_target_properties( ${name} PROPERTIES INSTALL_RPATH "@loader_path/../lib" )
+ else (UNIX)
+ if(NOT DEFINED CMAKE_INSTALL_RPATH)
+ set_target_properties( ${name} PROPERTIES INSTALL_RPATH "\$ORIGIN/../lib${LLVM_LIBDIR_SUFFIX}" )
+ if(${CMAKE_SYSTEM_NAME} MATCHES "(FreeBSD|DragonFly)")
+ set_property(TARGET ${name} APPEND_STRING PROPERTY LINK_FLAGS " -Wl,-z,origin ")
+ endif()
+ endif(NOT DEFINED CMAKE_INSTALL_RPATH)
+ endif()
+
+ if ( NOT "${CMAKE_INSTALL_PREFIX}" STREQUAL "${LLVM_INSTALL_PREFIX}" )
+ set_property(TARGET ${name} APPEND_STRING PROPERTY INSTALL_RPATH ";${LLVM_LIBRARY_DIR}")
+ if (UNIX)
+ set_target_properties( ${name} PROPERTIES BUILD_WITH_INSTALL_RPATH OFF )
+ endif()
+ endif()
+endfunction()
+
# llvm_add_library(name sources...
# SHARED;STATIC
# STATIC by default w/o BUILD_SHARED_LIBS.
@@ -445,6 +468,10 @@
endif()
if(ARG_SHARED)
+ set_rpath( ${name} )
+ endif()
+
+ if(ARG_SHARED)
if(WIN32)
set_target_properties(${name} PROPERTIES
PREFIX ""
@@ -675,6 +702,8 @@
# macros.
set_target_properties( ${name} PROPERTIES DEFINE_SYMBOL "" )
+ set_rpath( ${name} )
+
if (LLVM_EXPORTED_SYMBOL_FILE)
add_llvm_symbol_exports( ${name} ${LLVM_EXPORTED_SYMBOL_FILE} )
endif(LLVM_EXPORTED_SYMBOL_FILE)
Index: CMakeLists.txt
===================================================================
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -674,20 +674,6 @@
set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX} )
set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX} )
-set(CMAKE_BUILD_WITH_INSTALL_RPATH ON)
-if (APPLE)
- set(CMAKE_INSTALL_NAME_DIR "@rpath")
- set(CMAKE_INSTALL_RPATH "@executable_path/../lib")
-else(UNIX)
- if(NOT DEFINED CMAKE_INSTALL_RPATH)
- set(CMAKE_INSTALL_RPATH "\$ORIGIN/../lib${LLVM_LIBDIR_SUFFIX}")
- 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()
-
if(APPLE AND DARWIN_LTO_LIBRARY)
set(CMAKE_EXE_LINKER_FLAGS
"${CMAKE_EXE_LINKER_FLAGS} -Wl,-lto_library -Wl,${DARWIN_LTO_LIBRARY}")
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D25304.74092.patch
Type: text/x-patch
Size: 2900 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161010/d10dee90/attachment.bin>
More information about the llvm-commits
mailing list