Skip to content

Commit

Permalink
[CMake] Import latest AddInstallRPATHSupport from YCM
Browse files Browse the repository at this point in the history
  • Loading branch information
drdanz committed Oct 23, 2015
1 parent 296aa06 commit 01cfe39
Showing 1 changed file with 27 additions and 21 deletions.
48 changes: 27 additions & 21 deletions conf/AddInstallRPATHSupport.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
# hardcode in the binary itself the additional search directories
# to be passed to the dynamic linker. This works great in conjunction
# with relative paths.
# This macro will enable support to RPATH to your project.
# This command will enable support to RPATH to your project.
# It will enable the following things:
#
# - If the project builds shared libraries it will generate a run-path
Expand All @@ -49,17 +49,18 @@
# - In all cases (building executables and/or shared libraries)
# dependent shared libraries with RPATH support will be properly
#
# The macro has the following parameters:
# The command has the following parameters:
#
# Options:
# - ``USE_LINK_PATH``: if passed the macro will automatically adds to
# - ``USE_LINK_PATH``: if passed the command will automatically adds to
# the RPATH the path to all the dependent libraries.
#
# Arguments:
# - ``BIN_DIRS`` list of directories when the targets (bins or shared
# libraries) will be installed.
# - ``BIN_DIRS`` list of directories when the targets (executable and
# plugins) will be installed.
# - ``LIB_DIRS`` list of directories to be added to the RPATH. These
# directories will be added "relative" w.r.t. the ``BIN_DIRS``.
# directories will be added "relative" w.r.t. the ``BIN_DIRS`` and
# ``LIB_DIRS``.
# - ``DEPENDS`` list of conditions that should be TRUE to enable
# RPATH, for example ``FOO; NOT BAR``.

Expand All @@ -81,7 +82,12 @@
include(CMakeParseArguments)


macro(ADD_INSTALL_RPATH_SUPPORT)
function(ADD_INSTALL_RPATH_SUPPORT)

# If RPATH is disabled in CMake, it is useless to proceed.
if(CMAKE_SKIP_RPATH OR (CMAKE_SKIP_INSTALL_RPATH AND CMAKE_SKIP_BUILD_RPATH))
return()
endif()

set(_options USE_LINK_PATH)
set(_oneValueArgs )
Expand All @@ -94,10 +100,8 @@ macro(ADD_INSTALL_RPATH_SUPPORT)
"${_multiValueArgs}"
"${ARGN}")

if(NOT DEFINED _ARS_DEPENDS)
set(_rpath_available 0)
else()
set(_rpath_available 1)
set(_rpath_available 1)
if(DEFINED _ARS_DEPENDS)
foreach(_dep ${_ARS_DEPENDS})
string(REGEX REPLACE " +" ";" _dep "${_dep}")
if(NOT (${_dep}))
Expand All @@ -113,7 +117,13 @@ macro(ADD_INSTALL_RPATH_SUPPORT)
endif()

# Enable RPATH on OSX. This also suppress warnings on CMake >= 3.0
set(CMAKE_MACOSX_RPATH TRUE)
set(CMAKE_MACOSX_RPATH TRUE PARENT_SCOPE)

# If install RPATH is disabled in CMake, it is useless to evaluate and set
# CMAKE_INSTALL_RPATH and CMAKE_INSTALL_RPATH_USE_LINK_PATH
if(CMAKE_SKIP_INSTALL_RPATH)
return()
endif()

# Find system implicit lib directories
set(_system_lib_dirs ${CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES})
Expand All @@ -127,7 +137,7 @@ macro(ADD_INSTALL_RPATH_SUPPORT)
foreach(lib_dir ${_ARS_LIB_DIRS})
list(FIND _system_lib_dirs "${lib_dir}" isSystemDir)
if("${isSystemDir}" STREQUAL "-1")
foreach(bin_dir ${_ARS_BIN_DIRS})
foreach(bin_dir ${_ARS_LIB_DIRS} ${_ARS_BIN_DIRS})
file(RELATIVE_PATH _rel_path ${bin_dir} ${lib_dir})
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
list(APPEND CMAKE_INSTALL_RPATH "@loader_path/${_rel_path}")
Expand All @@ -138,16 +148,12 @@ macro(ADD_INSTALL_RPATH_SUPPORT)
endif("${isSystemDir}" STREQUAL "-1")
endforeach()
list(REMOVE_DUPLICATES CMAKE_INSTALL_RPATH)

unset(_rel_path)
unset(_system_lib_dirs)
set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_RPATH} PARENT_SCOPE)

# add the automatically determined parts of the RPATH
# which point to directories outside the build tree to the install RPATH
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH ${_ARS_USE_LINK_PATH})
endif()
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH ${_ARS_USE_LINK_PATH} PARENT_SCOPE)

unset(_rpath_available)
unset(_dep)
endif()

endmacro()
endfunction()

0 comments on commit 01cfe39

Please sign in to comment.