summaryrefslogtreecommitdiffstats
path: root/llvm/cmake/modules
diff options
context:
space:
mode:
authorChris Bieneman <beanz@apple.com>2016-11-01 17:44:58 +0000
committerChris Bieneman <beanz@apple.com>2016-11-01 17:44:58 +0000
commit61e900b4057dff9c9a5d7e8b0a2cffd2e861414b (patch)
tree8b6de4f7c9090c346fd7f97947764efec36a2726 /llvm/cmake/modules
parent700193ae052850d4a3ef77e17b12854305405764 (diff)
downloadbcm5719-llvm-61e900b4057dff9c9a5d7e8b0a2cffd2e861414b.tar.gz
bcm5719-llvm-61e900b4057dff9c9a5d7e8b0a2cffd2e861414b.zip
[CMake] Fix rpath construction for out-of-tree builds
This patch was produced in conjunction with Michał Górny. It should resolve the issues that were trying to be solved by D25304. This moves rpath handling into `llvm_add_library` and `add_llvm_executable` so that it is available to all projects using AddLLVM whether built in-tree or out-of-tree. llvm-svn: 285714
Diffstat (limited to 'llvm/cmake/modules')
-rw-r--r--llvm/cmake/modules/AddLLVM.cmake37
1 files changed, 37 insertions, 0 deletions
diff --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake
index b3105e09fbc..db2f31c5654 100644
--- a/llvm/cmake/modules/AddLLVM.cmake
+++ b/llvm/cmake/modules/AddLLVM.cmake
@@ -415,6 +415,9 @@ function(llvm_add_library name)
elseif(ARG_SHARED)
add_windows_version_resource_file(ALL_FILES ${ALL_FILES})
add_library(${name} SHARED ${ALL_FILES})
+
+ llvm_setup_rpath(${name})
+
else()
add_library(${name} STATIC ${ALL_FILES})
endif()
@@ -659,6 +662,8 @@ macro(add_llvm_executable name)
add_executable(${name} ${ALL_FILES})
endif()
+ llvm_setup_rpath(${name})
+
if(DEFINED windows_resource_file)
set_windows_version_resource_properties(${name} ${windows_resource_file})
endif()
@@ -1317,3 +1322,35 @@ function(llvm_externalize_debuginfo name)
message(FATAL_ERROR "LLVM_EXTERNALIZE_DEBUGINFO isn't implemented for non-darwin platforms!")
endif()
endfunction()
+
+function(llvm_setup_rpath name)
+ if(LLVM_INSTALL_PREFIX AND NOT (LLVM_INSTALL_PREFIX STREQUAL CMAKE_INSTALL_PREFIX))
+ set(extra_libdir ${LLVM_LIBRARY_DIR})
+ elseif(LLVM_BUILD_LIBRARY_DIR)
+ set(extra_libdir ${LLVM_LIBRARY_DIR})
+ endif()
+
+ if (APPLE)
+ set(_install_name_dir INSTALL_NAME_DIR "@rpath")
+ set(_install_rpath "@loader_path/../lib" ${extra_libdir})
+ elseif(UNIX)
+ if(NOT DEFINED CMAKE_INSTALL_RPATH)
+ set(_install_rpath "\$ORIGIN/../lib${LLVM_LIBDIR_SUFFIX}" ${extra_libdir})
+ if(${CMAKE_SYSTEM_NAME} MATCHES "(FreeBSD|DragonFly)")
+ set_property(TARGET ${name} APPEND_STRING PROPERTY
+ LINK_FLAGS " -Wl,-z,origin ")
+ elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Linux" AND NOT LLVM_LINKER_IS_GOLD)
+ # $ORIGIN is not interpreted at link time by ld.bfd
+ set_property(TARGET ${name} APPEND_STRING PROPERTY
+ LINK_FLAGS " -Wl,-rpath-link,${LLVM_LIBRARY_OUTPUT_INTDIR} ")
+ endif()
+ endif()
+ else()
+ return()
+ endif()
+
+ set_target_properties(${name} PROPERTIES
+ BUILD_WITH_INSTALL_RPATH On
+ INSTALL_RPATH "${_install_rpath}"
+ ${_install_name_dir})
+endfunction()
OpenPOWER on IntegriCloud