-
Notifications
You must be signed in to change notification settings - Fork 460
/
SlicerCPackBundleFixup.cmake.in
273 lines (232 loc) · 9.7 KB
/
SlicerCPackBundleFixup.cmake.in
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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
#
# Make sure this CMake has BundleUtilities.cmake:
#
if(NOT EXISTS "${CMAKE_ROOT}/Modules/BundleUtilities.cmake")
message(FATAL_ERROR "error: BundleUtilities.cmake not found. Use CMake 2.8.3 or later.")
endif()
include(BundleUtilities)
#
# Avoid following symlinks encountered during FILE GLOB_RECURSE calls:
#
if(COMMAND CMAKE_POLICY)
cmake_policy(SET CMP0009 NEW)
if(POLICY CMP0011)
cmake_policy(SET CMP0011 NEW)
endif()
endif()
#-----------------------------------------------------------------------------
# gp_log_message - Convenient function allowing to both display and log a message.
# Log file: $ENV{DESTDIR}/../complete-bundles-log.txt
#-----------------------------------------------------------------------------
function(gp_log_message text)
message(${text})
file(APPEND "@Slicer_BINARY_DIR@/complete-bundles-log.txt" "${text}
")
endfunction()
#-----------------------------------------------------------------------------
# gp_clear_log - Clear the log file
#-----------------------------------------------------------------------------
function(gp_clear_log)
file(WRITE "@Slicer_BINARY_DIR@/complete-bundles-log.txt" "")
gp_log_message("Log file: @Slicer_BINARY_DIR@/complete-bundles-log.txt")
endfunction()
#-----------------------------------------------------------------------------
# gp_resolved_file_type_override resolved_file type_var
#-----------------------------------------------------------------------------
function(gp_resolved_file_type_override resolved_file type_var)
if(resolved_file MATCHES "^/usr/.*/lib")
set(${type_var} system PARENT_SCOPE)
endif()
#gp_log_message("resolving ${file} as ${${type_var}}")
endfunction()
#-----------------------------------------------------------------------------
# gp_item_default_embedded_path_override item default_embedded_path_var
#-----------------------------------------------------------------------------
# Return the path that others should refer to the item by when the item
# is embedded inside a bundle.
#
# This is a project-specific override of BundleUtilities.cmake's
# gp_item_default_embedded_path
#
function(gp_item_default_embedded_path_override item default_embedded_path_var)
# By default, embed items as set by gp_item_default_embedded_path:
set(path "${${default_embedded_path_var}}")
if(item MATCHES "\\.dylib$")
set(path "@executable_path@/../@Slicer_LIB_DIR@")
endif()
set(Slicer_USE_PYTHONQT "@Slicer_USE_PYTHONQT@")
if(Slicer_USE_PYTHONQT)
if(item MATCHES "libpython[^/]+\\.dylib$")
set(path "@executable_path@/../lib/Python/lib")
endif()
if(item MATCHES "@Slicer_LIB_DIR@/[^/]+Python\\.so$")
set(path "@executable_path@/../@Slicer_LIB_DIR@")
endif()
endif()
set(Slicer_USE_PYTHONQT_WITH_TCL "@Slicer_USE_PYTHONQT_WITH_TCL@")
if(Slicer_USE_PYTHONQT_WITH_TCL)
if(item MATCHES "tcl-build/lib/lib[^/]+\\.dylib$")
set(path "@executable_path@/../lib/TclTk/lib")
endif()
endif()
if(item MATCHES "@Slicer_LIB_DIR@/[^/]+\\.dylib$")
set(path "@executable_path@/../@Slicer_LIB_DIR@")
endif()
if(item MATCHES "@Slicer_ITKFACTORIES_DIR@/[^/]+Plugin\\.(so|dylib)$")
set(path "@executable_path@/../@Slicer_ITKFACTORIES_DIR@")
endif()
if(item MATCHES "@Slicer_QtPlugins_DIR@/designer/[^/]+\\.(so|dylib)$")
set(path "@executable_path@/../@Slicer_QtPlugins_DIR@/designer")
endif()
if(item MATCHES "@Slicer_QtPlugins_DIR@/iconengines/[^/]+\\.(so|dylib)$")
set(path "@executable_path@/../@Slicer_QtPlugins_DIR@/iconengines")
endif()
if(item MATCHES "@Slicer_QtPlugins_DIR@/imageformats/[^/]+\\.(so|dylib)$")
set(path "@executable_path@/../@Slicer_QtPlugins_DIR@/imageformats")
endif()
if(item MATCHES "@Slicer_QtPlugins_DIR@/sqldrivers/[^/]+\\.(so|dylib)$")
set(path "@executable_path@/../@Slicer_QtPlugins_DIR@/sqldrivers")
endif()
set(Slicer_BUILD_CLI_SUPPORT "@Slicer_BUILD_CLI_SUPPORT@")
set(Slicer_BUILD_CLI "@Slicer_BUILD_CLI@")
if(Slicer_BUILD_CLI_SUPPORT AND Slicer_BUILD_CLI)
if(item MATCHES "@Slicer_CLIMODULES_LIB_DIR@/[^/]+\\.dylib$")
set(path "@executable_path@/../@Slicer_CLIMODULES_LIB_DIR@")
endif()
endif()
set(Slicer_BUILD_QTLOADABLEMODULES "@Slicer_BUILD_QTLOADABLEMODULES@")
if(Slicer_BUILD_QTLOADABLEMODULES)
if(item MATCHES "@Slicer_QTLOADABLEMODULES_LIB_DIR@/[^/]+\\.(so|dylib)$")
set(path "@executable_path@/../@Slicer_QTLOADABLEMODULES_LIB_DIR@")
endif()
endif()
math(EXPR lib_current $ENV{FIXUP_LIB_CURRENT}+1)
set(ENV{FIXUP_LIB_CURRENT} ${lib_current})
gp_log_message("${lib_current}/$ENV{FIXUP_LIBS_COUNT} - fixing item ${item} with ${path}")
set(${default_embedded_path_var} "${path}" PARENT_SCOPE)
endfunction()
#-----------------------------------------------------------------------------
# Fixup the .app bundles in the install tree:
#-----------------------------------------------------------------------------
function(fixup_bundle_with_plugins app)
set(app_dir "$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/${app}")
set(suffix "@CMAKE_SHARED_LIBRARY_SUFFIX@")
set(candiates_pattern
"${app_dir}/Contents/@Slicer_ITKFACTORIES_DIR@/*${suffix}"
"${app_dir}/Contents/@Slicer_ITKFACTORIES_DIR@/*Plugin.so"
"${app_dir}/Contents/@Slicer_QtPlugins_DIR@/designer/*Plugins.so"
"${app_dir}/Contents/@Slicer_QtPlugins_DIR@/iconengines/*Plugin.so"
"${app_dir}/Contents/@Slicer_QtPlugins_DIR@/imageformats/*${suffix}"
"${app_dir}/Contents/@Slicer_QtPlugins_DIR@/sqldrivers/*${suffix}"
)
set(Slicer_BUILD_CLI_SUPPORT "@Slicer_BUILD_CLI_SUPPORT@")
set(Slicer_BUILD_CLI "@Slicer_BUILD_CLI@")
if(Slicer_BUILD_CLI_SUPPORT AND Slicer_BUILD_CLI)
list(APPEND candiates_pattern
"${app_dir}/Contents/@Slicer_CLIMODULES_LIB_DIR@/*${suffix}"
)
endif()
set(Slicer_USE_PYTHONQT "@Slicer_USE_PYTHONQT@")
set(Slicer_BUILD_QTLOADABLEMODULES "@Slicer_BUILD_QTLOADABLEMODULES@")
if(Slicer_BUILD_QTLOADABLEMODULES)
list(APPEND candiates_pattern
"${app_dir}/Contents/@Slicer_QTLOADABLEMODULES_LIB_DIR@/libq*Module${suffix}"
"${app_dir}/Contents/@Slicer_QTLOADABLEMODULES_LIB_DIR@/*Python.so"
)
if(Slicer_USE_PYTHONQT)
list(APPEND candiates_pattern
"${app_dir}/Contents/@Slicer_QTLOADABLEMODULES_LIB_DIR@/qSlicer*PythonQt.so"
)
endif()
endif()
if(Slicer_USE_PYTHONQT)
list(APPEND candiates_pattern
"${app_dir}/Contents/@Slicer_LIB_DIR@/*Python.so"
"${app_dir}/Contents/@Slicer_LIB_DIR@/*PythonQt.so"
"${app_dir}/Contents/lib/Python/lib/python2.6/site-packages/*.so"
)
endif()
set(Slicer_USE_PYTHONQT_WITH_TCL "@Slicer_USE_PYTHONQT_WITH_TCL@")
if(Slicer_USE_PYTHONQT_WITH_TCL)
list(APPEND candiates_pattern
"${app_dir}/Contents/lib/TclTk/lib/lib*${suffix}"
)
endif()
set(libs "")
file(GLOB_RECURSE candidates ${candiates_pattern})
foreach(lib ${candidates})
if(NOT lib MATCHES "(_debug|d[0-9])${suffix}$")
set(libs ${libs} "${lib}")
endif()
endforeach()
list(REMOVE_DUPLICATES libs)
# Additional libs may be found in:
set(libs_path "@CMAKE_RUNTIME_OUTPUT_DIRECTORY@")
list(APPEND libs_path "@VTK_LIBRARY_DIRS@")
list(APPEND libs_path "@ITK_LIBRARY_DIRS@")
list(APPEND libs_path "@Teem_LIBRARY_DIRS@")
list(APPEND libs_path "@CTK_LIBRARY_DIRS@")
if(Slicer_BUILD_CLI_SUPPORT)
list(APPEND libs_path "@SlicerExecutionModel_LIBRARY_DIRS@")
endif()
set(Slicer_BUILD_EXTENSIONMANAGER_SUPPORT "@Slicer_BUILD_EXTENSIONMANAGER_SUPPORT@")
if(Slicer_BUILD_EXTENSIONMANAGER_SUPPORT)
list(APPEND libs_path "@LibArchive_DIR@/lib")
endif()
set(Slicer_USE_BatchMake "@Slicer_USE_BatchMake@")
if(Slicer_USE_BatchMake)
list(APPEND libs_path "@BatchMake_LIBRARY_DIRS@")
endif()
set(Slicer_USE_OpenIGTLink "@Slicer_USE_OpenIGTLink@")
if(Slicer_USE_OpenIGTLink)
list(APPEND libs_path "@OpenIGTLink_LIBRARY_DIRS@")
endif()
if(Slicer_USE_PYTHONQT)
list(APPEND libs_path "@SLICER_PYTHON_LIB_DIR@")
endif()
if(Slicer_USE_PYTHONQT_WITH_TCL)
list(APPEND libs_path "@Slicer_TCL_DIR@/lib/")
endif()
list(APPEND libs_path "@Slicer_BINARY_DIR@/@Slicer_LIB_DIR@")
if(Slicer_BUILD_QTLOADABLEMODULES)
list(APPEND libs_path "@Slicer_BINARY_DIR@/@Slicer_QTLOADABLEMODULES_LIB_DIR@")
endif()
if(Slicer_BUILD_CLI_SUPPORT AND Slicer_BUILD_CLI)
list(APPEND libs_path "@Slicer_BINARY_DIR@/@Slicer_CLIMODULES_LIB_DIR@")
endif()
list(APPEND libs_path "@Slicer_BINARY_DIR@/@Slicer_QtPlugins_DIR@")
list(REMOVE_DUPLICATES libs_path)
set(Slicer_BUILD_DIR "@Slicer_BINARY_DIR@")
set(Slicer_SUPERBUILD_DIR "@Slicer_SUPERBUILD_DIR@")
gp_clear_log()
gp_log_message("Calling fixup_bundle with")
gp_log_message("app=${app_dir}")
gp_log_message("<Slicer_SUPERBUILD_DIR>=${Slicer_SUPERBUILD_DIR}")
gp_log_message("libs=")
foreach(lib ${libs})
file(RELATIVE_PATH relative_lib ${Slicer_SUPERBUILD_DIR} ${lib})
if(NOT "${relative_lib}" STREQUAL "${lib}")
set(lib "<Slicer_SUPERBUILD_DIR>/${relative_lib}")
endif()
gp_log_message(" ${lib}")
endforeach()
gp_log_message("libs_path=")
foreach(path ${libs_path})
file(RELATIVE_PATH relative_path ${Slicer_SUPERBUILD_DIR} ${path})
if(NOT "${relative_path}" STREQUAL "${path}")
set(path "<Slicer_SUPERBUILD_DIR>/${relative_path}")
endif()
gp_log_message(" ${path}")
endforeach()
# Keep track of libs count and current lib being fixed
list(LENGTH libs libs_count)
set(ENV{FIXUP_LIBS_COUNT} ${libs_count})
set(ENV{FIXUP_LIB_CURRENT} 0)
fixup_bundle(
"${app_dir}"
"${libs}"
"${libs_path}"
)
endfunction()
fixup_bundle_with_plugins("@Slicer_MAIN_PROJECT_APPLICATION_NAME@.app")
#verify_app("/Users/partyd/Kitware/Slicer4-trunk/build/Slicer-build/_CPack_Packages/Darwin/DragNDrop/Slicer-4.0.gamma-2011-05-10-Darwin/@Slicer_MAIN_PROJECT_APPLICATION_NAME@.app")