diff --git a/.gitignore b/.gitignore index ead2528..9a3f1a4 100644 --- a/.gitignore +++ b/.gitignore @@ -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 \ No newline at end of file +MacDeployScript.sh +WindowsInstaller.iss diff --git a/MacDeployScript.sh.sample b/MacDeployScript.sh.sample new file mode 100755 index 0000000..84b26ec --- /dev/null +++ b/MacDeployScript.sh.sample @@ -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=-$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=/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"*