From 89d9b333b0759fc32a35dd595ea9fa5d39d2ae7e Mon Sep 17 00:00:00 2001 From: Jonathan Peyton Date: Tue, 9 Feb 2016 22:15:30 +0000 Subject: [PATCH] Have Mac builds use @rpath when supported in CMake The -install_name linker flag will use "@rpath/" when supported in CMake which is the recommended usage for dynamic libraries on Mac OSX. llvm-svn: 260300 --- openmp/runtime/CMakeLists.txt | 8 ++++++++ openmp/runtime/tools/check-depends.pl | 2 ++ 2 files changed, 10 insertions(+) diff --git a/openmp/runtime/CMakeLists.txt b/openmp/runtime/CMakeLists.txt index c4875f4cfdf8..641b8f4631b1 100644 --- a/openmp/runtime/CMakeLists.txt +++ b/openmp/runtime/CMakeLists.txt @@ -112,6 +112,14 @@ set(LIBOMP_OSX_ARCHITECTURES "${CMAKE_OSX_ARCHITECTURES}" CACHE STRING "For Mac builds, semicolon separated list of architectures to build for universal fat binary.") set(CMAKE_OSX_ARCHITECTURES ${LIBOMP_OSX_ARCHITECTURES}) +# Should @rpath be used for dynamic libraries on Mac? +# The if(NOT DEFINED) is there to guard a cached value of the variable if one +# exists so there is no interference with what the user wants. Also, no cache entry +# is created so there are no inadvertant effects on other parts of LLVM. +if(NOT DEFINED CMAKE_MACOSX_RPATH) + set(CMAKE_MACOSX_RPATH TRUE) +endif() + # User specified flags. These are appended to the configured flags. set(LIBOMP_CFLAGS "" CACHE STRING "Appended user specified C compiler flags.") diff --git a/openmp/runtime/tools/check-depends.pl b/openmp/runtime/tools/check-depends.pl index 48e312aa0105..47e7e5a3d356 100755 --- a/openmp/runtime/tools/check-depends.pl +++ b/openmp/runtime/tools/check-depends.pl @@ -185,6 +185,8 @@ sub get_deps_otool($) { or parse_error( $tool, @bulk, $i ); ++ $i; if ( $name =~ m{\.dylib\z} ) { + # Added "@rpath/" enables dynamic load of the library designated at link time. + $name = '@rpath/' . $name; # In case of dynamic library otool print the library itself as a dependent library. ( $i < @bulk and $bulk[ $i ] =~ m{^\s+\Q$name\E\s+\(compatibility version.*\)$} ) or parse_error( $tool, @bulk, $i );