Skip to content

Commit

Permalink
Finish renaming app to SIUE Fat Segmentation Tool
Browse files Browse the repository at this point in the history
Rename MacDeployScript to MacDeployScript.sh

Ignore MacDeployScript.sh from Git.

Add sample MacDeployScript with indicators like this <INSERT-HERE> to change for custom path.
  • Loading branch information
addisonElliott committed Aug 21, 2017
1 parent 565a14f commit 672951b
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,5 @@ CMakeLists.txt.user
error.log

# Installation Scripts, ignore these since they contain path dependent scripts that will be different from computer to computer
MacDeployScript
WindowsInstaller.iss
MacDeployScript.sh
WindowsInstaller.iss
122 changes: 122 additions & 0 deletions MacDeployScript.sh.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
#!/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=(
"libnifticdf.2.dylib"
"libniftiio.2.dylib"
"libopencv_core.3.2.dylib"
"libopencv_imgproc.3.2.dylib"
"libopencv_highgui.3.2.dylib"
"libopencv_video.3.2.dylib"
"libznz.2.dylib"
"libopencv_videoio.3.2.dylib"
"libopencv_imgcodecs.3.2.dylib"
)

# 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=(
"libznz.2.dylib" "libniftiio.2.dylib"

"libopencv_imgproc.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"*

0 comments on commit 672951b

Please sign in to comment.