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}") 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)