summaryrefslogtreecommitdiff
path: root/Tests/RunCMake/install/file-GET_RUNTIME_DEPENDENCIES-macos.cmake
blob: 6db05b3fff7b97a7a8fad0661761ea73df08dad0 (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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
enable_language(C)

set(testlib_names
  preexcluded
  executable_path
  executable_path_bundle
  executable_path_postexcluded
  loader_path
  loader_path_unresolved
  loader_path_postexcluded
  rpath
  rpath_unresolved
  rpath_postexcluded
  rpath_executable_path
  rpath_executable_path_bundle
  rpath_executable_path_postexcluded
  rpath_loader_path
  rpath_loader_path_unresolved
  rpath_loader_path_postexcluded
  normal
  normal_unresolved
  normal_postexcluded
  conflict
  )

file(REMOVE "${CMAKE_BINARY_DIR}/testlib.c")
add_library(testlib SHARED "${CMAKE_BINARY_DIR}/testlib.c")
foreach(name ${testlib_names})
  if(name STREQUAL "normal")
    file(WRITE "${CMAKE_BINARY_DIR}/normal.c" "extern void rpath(void);\nvoid normal(void)\n{\n  rpath();\n}\n")
  else()
    file(WRITE "${CMAKE_BINARY_DIR}/${name}.c" "void ${name}(void) {}\n")
  endif()
  add_library(${name} SHARED "${CMAKE_BINARY_DIR}/${name}.c")

  file(APPEND "${CMAKE_BINARY_DIR}/testlib.c" "extern void ${name}(void);\n")
endforeach()
file(APPEND "${CMAKE_BINARY_DIR}/testlib.c" "void testlib(void)\n{\n")
foreach(name ${testlib_names})
  file(APPEND "${CMAKE_BINARY_DIR}/testlib.c" "  ${name}();\n")
endforeach()
file(APPEND "${CMAKE_BINARY_DIR}/testlib.c" "}\n")
set_property(TARGET ${testlib_names} PROPERTY BUILD_WITH_INSTALL_NAME_DIR 1)
target_link_libraries(normal PRIVATE rpath)
set_property(TARGET normal PROPERTY INSTALL_RPATH
  "${CMAKE_BINARY_DIR}/root-all/executable/lib/normal/../rpath"
  )

file(WRITE "${CMAKE_BINARY_DIR}/testlib_conflict.c" "extern void conflict(void);\nvoid testlib_conflict(void)\n{\n  conflict();\n}\n")
add_library(testlib_conflict SHARED "${CMAKE_BINARY_DIR}/testlib_conflict.c")
target_link_libraries(testlib_conflict PRIVATE conflict)

set_property(TARGET testlib PROPERTY INSTALL_RPATH
  "${CMAKE_BINARY_DIR}/root-all/executable/lib/rpath"
  "${CMAKE_BINARY_DIR}/root-all/executable/lib/rpath_unresolved"
  "${CMAKE_BINARY_DIR}/root-all/executable/lib/rpath_postexcluded"
  "${CMAKE_BINARY_DIR}/root-all/executable/lib/conflict"
  @executable_path/../lib/rpath_executable_path
  @executable_path/../lib/rpath_executable_path_unresolved
  @executable_path/../lib/rpath_executable_path_postexcluded
  @loader_path/rpath_loader_path
  @loader_path/rpath_loader_path_unresolved
  @loader_path/rpath_loader_path_postexcluded
  )
set_property(TARGET testlib_conflict PROPERTY INSTALL_RPATH
  "${CMAKE_BINARY_DIR}/root-all/executable/lib/conflict2"
  )

foreach(t
  executable_path
  executable_path_postexcluded
  loader_path
  loader_path_postexcluded
  rpath
  rpath_postexcluded
  rpath_executable_path
  rpath_executable_path_postexcluded
  rpath_loader_path
  rpath_loader_path_postexcluded
  conflict
  )
  install(TARGETS ${t} DESTINATION executable/lib/${t})
endforeach()
install(TARGETS conflict DESTINATION executable/lib/conflict2)

foreach(t
  executable_path_bundle
  executable_path_postexcluded
  loader_path_postexcluded
  rpath_postexcluded
  rpath_executable_path_bundle
  rpath_executable_path_postexcluded
  rpath_loader_path_postexcluded
  )
  install(TARGETS ${t} DESTINATION bundle_executable/lib/${t})
endforeach()

foreach(t executable_path executable_path_bundle executable_path_postexcluded)
  set_property(TARGET ${t} PROPERTY INSTALL_NAME_DIR @executable_path/../lib/${t})
endforeach()

foreach(t loader_path loader_path_unresolved loader_path_postexcluded)
  set_property(TARGET ${t} PROPERTY INSTALL_NAME_DIR @loader_path/${t})
endforeach()

foreach(t
  rpath
  rpath_unresolved
  rpath_postexcluded
  rpath_executable_path
  rpath_executable_path_bundle
  rpath_executable_path_postexcluded
  rpath_loader_path
  rpath_loader_path_unresolved
  rpath_loader_path_postexcluded
  conflict
  )
  set_property(TARGET ${t} PROPERTY INSTALL_NAME_DIR @rpath)
endforeach()

foreach(t normal normal_unresolved normal_postexcluded)
  set_property(TARGET ${t} PROPERTY INSTALL_NAME_DIR "${CMAKE_BINARY_DIR}/root-all/executable/lib/${t}")
  if(NOT t STREQUAL "normal_unresolved")
    install(TARGETS ${t} DESTINATION executable/lib/${t})
  endif()
endforeach()

target_link_libraries(testlib PRIVATE ${testlib_names})

add_executable(topexe file-GET_RUNTIME_DEPENDENCIES-macos/topexe.c)
add_library(toplib SHARED file-GET_RUNTIME_DEPENDENCIES-macos/toplib.c)
add_library(topmod MODULE file-GET_RUNTIME_DEPENDENCIES-macos/toplib.c)
target_link_libraries(topexe PRIVATE testlib)
target_link_libraries(toplib PRIVATE testlib)
target_link_libraries(topmod PRIVATE testlib)

set_property(TARGET topexe toplib topmod PROPERTY INSTALL_RPATH "${CMAKE_BINARY_DIR}/root-all/executable/lib")

install(TARGETS topexe toplib topmod testlib testlib_conflict RUNTIME DESTINATION executable/bin LIBRARY DESTINATION executable/lib)
install(TARGETS topexe toplib topmod testlib testlib_conflict RUNTIME DESTINATION bundle_executable/bin LIBRARY DESTINATION bundle_executable/lib)

install(CODE [[
  function(exec_get_runtime_dependencies depsfile udepsfile cdepsfile)
    file(GET_RUNTIME_DEPENDENCIES
      RESOLVED_DEPENDENCIES_VAR deps
      UNRESOLVED_DEPENDENCIES_VAR udeps
      CONFLICTING_DEPENDENCIES_PREFIX cdeps
      PRE_INCLUDE_REGEXES "^.*/lib(testlib|executable_path|executable_path_bundle|executable_path_postexcluded|loader_path|loader_path_unresolved|loader_path_postexcluded|rpath|rpath_unresolved|rpath_postexcluded|rpath_executable_path|rpath_executable_path_bundle|rpath_executable_path_postexcluded|rpath_loader_path|rpath_loader_path_unresolved|rpath_loader_path_postexcluded|normal|normal_unresolved|normal_postexcluded|conflict|System\\.B)\\.dylib$"
      PRE_EXCLUDE_REGEXES ".*"
      POST_INCLUDE_REGEXES "^.*/lib(testlib|executable_path|executable_path_bundle|loader_path|rpath|rpath_executable_path|rpath_executable_path_bundle|rpath_loader_path|normal|conflict|System\\.B)\\.dylib$"
      POST_EXCLUDE_REGEXES ".*"
      ${ARGN}
      )
    list(SORT deps)
    list(SORT udeps)
    list(SORT cdeps_FILENAMES)
    file(WRITE "${CMAKE_INSTALL_PREFIX}/deps/${depsfile}" "${deps}")
    file(WRITE "${CMAKE_INSTALL_PREFIX}/deps/${udepsfile}" "${udeps}")
    file(WRITE "${CMAKE_INSTALL_PREFIX}/deps/${cdepsfile}" "")
    foreach(cdep IN LISTS cdeps_FILENAMES)
      set(cdep_values ${cdeps_${cdep}})
      list(SORT cdep_values)
      file(APPEND "${CMAKE_INSTALL_PREFIX}/deps/${cdepsfile}" "${cdep}:${cdep_values}\n")
    endforeach()
  endfunction()

  exec_get_runtime_dependencies(
    deps1.txt udeps1.txt cdeps1.txt
    EXECUTABLES
      "${CMAKE_INSTALL_PREFIX}/executable/bin/$<TARGET_FILE_NAME:topexe>"
    LIBRARIES
      "${CMAKE_INSTALL_PREFIX}/executable/lib/$<TARGET_FILE_NAME:testlib_conflict>"
    )

  exec_get_runtime_dependencies(
    deps2.txt udeps2.txt cdeps2.txt
    LIBRARIES
      "${CMAKE_INSTALL_PREFIX}/executable/lib/$<TARGET_FILE_NAME:toplib>"
      "${CMAKE_INSTALL_PREFIX}/executable/lib/$<TARGET_FILE_NAME:testlib_conflict>"
    )

  exec_get_runtime_dependencies(
    deps3.txt udeps3.txt cdeps3.txt
    MODULES
      "${CMAKE_INSTALL_PREFIX}/executable/lib/$<TARGET_FILE_NAME:topmod>"
    LIBRARIES
      "${CMAKE_INSTALL_PREFIX}/executable/lib/$<TARGET_FILE_NAME:testlib_conflict>"
    )

  exec_get_runtime_dependencies(
    deps4.txt udeps4.txt cdeps4.txt
    EXECUTABLES
      "${CMAKE_INSTALL_PREFIX}/executable/bin/$<TARGET_FILE_NAME:topexe>"
    LIBRARIES
      "${CMAKE_INSTALL_PREFIX}/executable/lib/$<TARGET_FILE_NAME:testlib_conflict>"
    BUNDLE_EXECUTABLE
      "${CMAKE_INSTALL_PREFIX}/bundle_executable/bin/$<TARGET_FILE_NAME:topexe>"
    )

  exec_get_runtime_dependencies(
    deps5.txt udeps5.txt cdeps5.txt
    LIBRARIES
      "${CMAKE_INSTALL_PREFIX}/executable/lib/$<TARGET_FILE_NAME:toplib>"
      "${CMAKE_INSTALL_PREFIX}/executable/lib/$<TARGET_FILE_NAME:testlib_conflict>"
    BUNDLE_EXECUTABLE "${CMAKE_INSTALL_PREFIX}/bundle_executable/bin/$<TARGET_FILE_NAME:topexe>"
    )

  exec_get_runtime_dependencies(
    deps6.txt udeps6.txt cdeps6.txt
    MODULES
      "${CMAKE_INSTALL_PREFIX}/executable/lib/$<TARGET_FILE_NAME:topmod>"
    LIBRARIES
      "${CMAKE_INSTALL_PREFIX}/executable/lib/$<TARGET_FILE_NAME:testlib_conflict>"
    BUNDLE_EXECUTABLE "${CMAKE_INSTALL_PREFIX}/bundle_executable/bin/$<TARGET_FILE_NAME:topexe>"
    )
  ]])