-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMacDeployScript.sh.sample
More file actions
executable file
·133 lines (104 loc) · 4.8 KB
/
MacDeployScript.sh.sample
File metadata and controls
executable file
·133 lines (104 loc) · 4.8 KB
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
#!/bin/bash
# Location of libraries to import into app bundle
LIB_DIR=/usr/local/lib
# Application name
APP_NAME="SIUE Fat Segmentation Tool"
# Version
VERSION=v1.0.2.0
# Release type (Debug|Release)
RELEASE=Debug
# Name for DMG
DMG_NAME=$APP_NAME-$VERSION-$RELEASE-OSX_x64
# Location of the application bundle to include libraries
APP_DIR=<PATH-TO-APP-REMOVE-DEBUG/RELEASE-PREFIX>-$RELEASE/$APP_NAME.app
# Location of DMG directory that contains contents of what the DMG will have in it
DMG_DIR=$APP_DIR/../dmg_folder
# Location of the actual application binary inside app bundle
APP_BIN=Contents/MacOS/$APP_NAME
# Location of macdeployqt file
MACDEPLOYQT=<PATH-TO-MACDEPLOYQT>/macdeployqt
# List of third-party libraries that will be imported to the App bundle
# Do NOT include Qt libraries or system libraries because Qt libraries are handled by macdeployqt and system libraries do not need to be imported
#
# Run otool -L /path/to/app/Contents/MacOS/app to get a list of dependencies for program. Exclude any Qt file or files beginning with /System/* or /usr/lib/*
# The remaining libraries beginning with @rpath or /usr/local/lib will likely need to be imported
#
# For each library, run otool -L LIB_NAME on that library to get a list of dependencies for THAT library. Note which libraries require which dependencies because that
# needs to be changed. Include all of the libraries dependencies in the LIBS list too. (Only if it is new and not already included in list).
# This is recursive. So for each new library, you MUST run otool on it to get dependencies for THAT library then.
LIBS=(
"libopencv_core.3.2.dylib"
"libopencv_imgproc.3.2.dylib"
"libopencv_highgui.3.2.dylib"
"libopencv_video.3.2.dylib"
"libopencv_videoio.3.2.dylib"
"libopencv_imgcodecs.3.2.dylib"
)
if [ $RELEASE == "Debug" ]
then
LIBS+=(
"liblibNIFTI_debug.1.dylib"
"libquazip_debug.1.dylib"
)
else
LIBS+=(
"liblibNIFTI.1.dylib"
"libquazip.1.dylib"
)
fi
# When replacing the old path name to the new one, use these directory prefixes. Should NOT need to be changed. This changes any directories beginning with @rpath or $LIB_DIR
OLD_PATH_DIRS=("" "$LIB_DIR/" "@rpath/")
# Contains a multidimensional array of dependencies between libraries. First value indicates the dependency and the second value is the library that contains the dependency.
#
# As specified above in LIBS documentation, run otool -L LIB_NAME for each library and note the dependencies. If any third-party dependencies are present, include them below
# so they are changed upon running of script.
DEPS=(
"libquazip_debug.1.dylib" "liblibNIFTI_debug.1.dylib"
"libquazip.1.dylib" "liblibNIFTI.1.dylib"
"libopencv_core.3.2.dylib" "libopencv_imgproc.3.2.dylib"
"libopencv_videoio.3.2.dylib" "libopencv_highgui.3.2.dylib"
"libopencv_imgcodecs.3.2.dylib" "libopencv_highgui.3.2.dylib"
"libopencv_imgproc.3.2.dylib" "libopencv_highgui.3.2.dylib"
"libopencv_core.3.2.dylib" "libopencv_highgui.3.2.dylib"
"libopencv_imgproc.3.2.dylib" "libopencv_video.3.2.dylib"
"libopencv_core.3.2.dylib" "libopencv_video.3.2.dylib"
"libopencv_imgcodecs.3.2.dylib" "libopencv_videoio.3.2.dylib"
"libopencv_imgproc.3.2.dylib" "libopencv_videoio.3.2.dylib"
"libopencv_core.3.2.dylib" "libopencv_videoio.3.2.dylib"
"libopencv_imgproc.3.2.dylib" "libopencv_imgcodecs.3.2.dylib"
"libopencv_core.3.2.dylib" "libopencv_imgcodecs.3.2.dylib"
)
# Run macdeployqt to fix Qt library dependencies
$MACDEPLOYQT "$APP_DIR"
# Loop through each library and copy the library to Frameworks dir in app bundle, add ID using install_name and change the library name in main application to use relative path
for i in "${LIBS[@]}"
do
cp $LIB_DIR/$i "$APP_DIR/Contents/Frameworks/$i"
install_name_tool -id @executable_path/../Frameworks/$i "$APP_DIR/Contents/Frameworks/$i"
for j in "${OLD_PATH_DIRS[@]}"
do
install_name_tool -change $j$i @executable_path/../Frameworks/$i "$APP_DIR/$APP_BIN"
done
done
# Loop through each dependency between libraries and change the corresponding name to new relative path in library
ARR_SIZE=${#DEPS[@]}
for i in "${OLD_PATH_DIRS[@]}"
do
for ((j=0; j<$ARR_SIZE; j = j + 2))
do
install_name_tool -change $i${DEPS[$j]} @executable_path/../Frameworks/${DEPS[$j]} "$APP_DIR/Contents/Frameworks/${DEPS[$j+1]}"
done
done
# Create dmg directory
mkdir "$DMG_DIR"
# Remove EVERYTHING from dmg directory.
rm -rf "$DMG_DIR/*"
# Copy app bundle to dmg folder
cp -R "$APP_DIR" "$DMG_DIR/"
# Create symlink of Applications in folder so user can drag application to folder
ln -s /Applications "$DMG_DIR/Applications"
# Create DMG file with contents being the contents of $DMG_DIR
hdiutil create -volname "$APP_NAME" -srcfolder "$DMG_DIR" -ov -format UDZO "$APP_DIR/../$DMG_NAME.dmg"
# Output otool result to see if all dependencies were met
otool -L "$APP_DIR/$APP_BIN"
otool -L "$APP_DIR/Contents/Frameworks/lib"*