summaryrefslogtreecommitdiffstats
path: root/Tests/RunCMake/install/TARGETS-FILE_RPATH_CHANGE-new_rpath.cmake
blob: cba04b26648647689a34b476471a0c785aa95e84 (plain)
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
cmake_minimum_required(VERSION 3.14)
enable_language(C)

# test matrix
#
# A :=
#                        | no cmake syntax | cmake syntax |
# -----------------------+-----------------+--------------+
# absolute install RPATH |       exe1      |     exe4     |
# relative install RPATH |       exe2      |     exe3     |
#
# all := A * CMP005_OLD + A * CMP0095_WARN + A * CMP0095_NEW

add_library(utils SHARED obj1.c)
set(targets utils)

set(exe1_install_rpath "/foo/bar")
set(exe2_install_rpath "\$ORIGIN/../lib")
set(exe3_install_rpath "\${ORIGIN}/../lib")
set(exe4_install_rpath "/foo/bar/\${PLATFORM}")

macro(A_CMP0095 policy_value)
  cmake_policy(PUSH)
  if(NOT "x${policy_value}x" STREQUAL "xWARNx")
    cmake_policy(SET CMP0095 ${policy_value})
  endif()
  string(TOLOWER "${policy_value}" p)

  # exe1: absolute install RPATH, no cmake syntax
  set(case "exe1")
  set(target "${case}_cmp0095_${p}")
  list(APPEND targets ${target})
  add_executable(${target} main.c)
  target_link_libraries(${target} PRIVATE utils)
  set_target_properties(${target} PROPERTIES
    INSTALL_RPATH "${${case}_install_rpath}")

  # exe2: relative install RPATH, no cmake syntax
  set(case "exe2")
  set(target "${case}_cmp0095_${p}")
  list(APPEND targets ${target})
  add_executable(${target} main.c)
  target_link_libraries(${target} PRIVATE utils)
  set_target_properties(${target} PROPERTIES
    INSTALL_RPATH "${${case}_install_rpath}")

  # exe3: relative install RPATH, cmake syntax
  set(case "exe3")
  set(target "${case}_cmp0095_${p}")
  list(APPEND targets ${target})
  add_executable(${target} main.c)
  target_link_libraries(${target} PRIVATE utils)
  set_target_properties(${target} PROPERTIES
    INSTALL_RPATH "${${case}_install_rpath}")

  # exe4: absolute install RPATH, cmake syntax
  set(case "exe4")
  set(target "${case}_cmp0095_${p}")
  list(APPEND targets ${target})
  add_executable(${target} main.c)
  target_link_libraries(${target} PRIVATE utils)
  set_target_properties(${target} PROPERTIES
    INSTALL_RPATH "${${case}_install_rpath}")

  cmake_policy(POP)
endmacro()

A_CMP0095("OLD")
A_CMP0095("WARN") # exe3 and exe4 are expected to issue an author warning
A_CMP0095("NEW")

install(TARGETS ${targets})