# TODO : verify if this is still OK for installed targets

SET(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
SET(CMAKE_INSTALL_RPATH "${RADIUM_SUBMODULES_INSTALL_DIRECTORY}/lib;${RADIUM_SUBMODULES_INSTALL_DIRECTORY}/bin;${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")

message("INFO Radium is built with INSTALL_RPATH_USE_LINK_PATH=${CMAKE_INSTALL_RPATH_USE_LINK_PATH}, BUILD_WITH_INSTALL_RPATH=${CMAKE_BUILD_WITH_INSTALL_RPATH} and INSTALL_RPATH=${CMAKE_INSTALL_RPATH}")



## This script comes from https://cmake.org/Wiki/CMake_RPATH_handling#Always_full_RPATH
#
# It is designed 'to make sure that the required libraries are always found
# independent from LD_LIBRARY_PATH and the install location'
#
# Note: this version does not handle the installation case, which is currently
# untested and not used

# use, i.e. don't skip the full RPATH for the build tree
#SET(CMAKE_SKIP_BUILD_RPATH  FALSE)

# when building, don't use the install RPATH already
# (but later on when installing)
#SET(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)

# SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")

# 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 TRUE)


# the RPATH to be used when installing, but only if it's not a system directory
# LIST(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/lib" isSystemDir)
# IF("${isSystemDir}" STREQUAL "-1")
#    SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
# ENDIF("${isSystemDir}" STREQUAL "-1")
