-
Notifications
You must be signed in to change notification settings - Fork 47
/
relpath.cmake
53 lines (51 loc) · 1.49 KB
/
relpath.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#
# Copyright (C) 2023 LAAS-CNRS
#
# Author: Guilhem Saurel
#
# .rst: .. ifmode:: user
#
# .. command:: REL_INSTALL_PATH(FILE VARIABLE)
#
# Compute the relative path from the installation prefix to FILE. Works for
# relative and absolute FILE, except for absolute paths outside of
# CMAKE_INSTALL_PREFIX.
#
macro(REL_INSTALL_PATH FILE VARIABLE)
if(IS_ABSOLUTE ${FILE})
file(RELATIVE_PATH _VARIABLE "${FILE}" ${CMAKE_INSTALL_PREFIX})
string(REGEX REPLACE "/$" "" ${VARIABLE} "${_VARIABLE}")
else()
string(REGEX REPLACE "[^/]+" ".." ${VARIABLE} "${FILE}")
endif()
endmacro()
# .rst: .. ifmode:: user
#
# .. command:: GET_RELATIVE_RPATH(TARGET_INSTALL_DIR VARIABLE)
#
# Provide INSTALL_RPATH from TARGET_INSTALL_DIR to CMAKE_INSTALL_LIBDIR as
# relative to $ORIGIN / @loader_path. Works for relative and absolute
# TARGET_INSTALL_DIR and CMAKE_INSTALL_LIBDIR, except for absolute paths outside
# of CMAKE_INSTALL_PREFIX. Only on UNIX systems (including APPLE).
#
macro(GET_RELATIVE_RPATH TARGET_INSTALL_DIR VARIABLE)
if(UNIX)
if(APPLE)
set(ORIGIN "@loader_path")
else()
set(ORIGIN "\$ORIGIN")
endif()
REL_INSTALL_PATH("${TARGET_INSTALL_DIR}" _TGT_INV_REL)
if(IS_ABSOLUTE ${CMAKE_INSTALL_LIBDIR})
file(
RELATIVE_PATH
_LIB_REL
"${CMAKE_INSTALL_PREFIX}"
${CMAKE_INSTALL_LIBDIR}
)
else()
set(_LIB_REL ${CMAKE_INSTALL_LIBDIR})
endif()
set(${VARIABLE} "${ORIGIN}/${_TGT_INV_REL}/${_LIB_REL}")
endif()
endmacro()