1#!/bin/bash 2# Creates Apple ".app" bundle for @PROJECT_NAME_UCASE@ 3# Note: 4# Examine linkings using `otool -L somelib.so` 5# Debug the loading of dynamic libraries using `export DYLD_PRINT_LIBRARIES=1` 6 7# STK rawwaves directory 8STK_RAWWAVE=$HOME/stk-*/rawwaves 9 10if [ ! -d "$STK_RAWWAVE" ]; then 11 STK_RAWWAVE=$(brew --prefix stk)/share/stk/rawwaves 12fi 13 14# Place to create ".app" bundle 15APP="@CMAKE_BINARY_DIR@/@PROJECT_NAME_UCASE@.app" 16 17MSG_COLOR='\x1B[1;36m' 18COLOR_RESET='\x1B[0m' 19echo -e "$MSG_COLOR\n\nCreating App Bundle \"$APP\"...$COLOR_RESET" 20 21# Locate macdeployqt, assume homebrew & Qt5 22which macdeployqt > /dev/null 2>&1 23if [ $? -ne 0 ]; then 24 export PATH=$PATH:$(brew --prefix qt)/bin 25fi 26 27# Remove any old .app bundles 28rm -Rf "$APP" 29 30# Copy/overwrite Info.plist 31\cp "@CMAKE_BINARY_DIR@/Info.plist" "@CMAKE_INSTALL_PREFIX@/" 32 33# Create .app bundle containing contents from CMAKE_INSTALL_PREFIX 34mkdir -p "$APP/Contents/MacOS" 35mkdir -p "$APP/Contents/Frameworks" 36mkdir -p "$APP/Contents/Resources" 37mkdir -p "$APP/Contents/share/stk/rawwaves" 38cd "@CMAKE_INSTALL_PREFIX@" 39cp -R * "$APP/Contents" 40cp "@CMAKE_SOURCE_DIR@/cmake/apple/"*.icns "$APP/Contents/Resources/" 41cp $STK_RAWWAVE/*.raw "$APP/Contents/share/stk/rawwaves" > /dev/null 2>&1 42 43# Make all libraries writable for macdeployqt 44cd "$APP" 45find . -type f -print0 | xargs -0 chmod u+w 46 47lmmsbin="MacOS/@CMAKE_PROJECT_NAME@" 48zynlib="lib/lmms/libzynaddsubfx.so" 49zynfmk="Frameworks/libZynAddSubFxCore.dylib" 50zynbin="MacOS/RemoteZynAddSubFx" 51 52# Move lmms binary 53mv "$APP/Contents/bin/@CMAKE_PROJECT_NAME@" "$APP/Contents/$lmmsbin" 54 55# Fix zyn linking 56mv "$APP/Contents/lib/lmms/RemoteZynAddSubFx" "$APP/Contents/$zynbin" 57mv "$APP/Contents/lib/lmms/libZynAddSubFxCore.dylib" "$APP/Contents/$zynfmk" 58 59install_name_tool -change @rpath/libZynAddSubFxCore.dylib \ 60 @loader_path/../$zynfmk \ 61 "$APP/Contents/$zynbin" 62 63install_name_tool -change @rpath/libZynAddSubFxCore.dylib \ 64 @loader_path/../../$zynfmk \ 65 "$APP/Contents/$zynlib" 66 67# Replace @rpath with @loader_path for Carla 68# See also plugins/carlabase/CMakeLists.txt 69# This MUST be done BEFORE calling macdeployqt 70install_name_tool -change @rpath/libcarlabase.dylib \ 71 @loader_path/libcarlabase.dylib \ 72 "$APP/Contents/lib/lmms/libcarlapatchbay.so" 73 74install_name_tool -change @rpath/libcarlabase.dylib \ 75 @loader_path/libcarlabase.dylib \ 76 "$APP/Contents/lib/lmms/libcarlarack.so" 77 78# Link lmms binary 79_executables="${_executables} -executable=$APP/Contents/$zynbin" 80_executables="${_executables} -executable=$APP/Contents/$zynfmk" 81 82# Build a list of shared objects in target/lib/lmms 83for file in "$APP/Contents/lib/lmms/"*.so; do 84 _thisfile="$APP/Contents/lib/lmms/${file##*/}" 85 _executables="${_executables} -executable=$_thisfile" 86done 87 88# Build a list of shared objects in target/lib/lmms/ladspa 89for file in "$APP/Contents/lib/lmms/ladspa/"*.so; do 90 _thisfile="$APP/Contents/lib/lmms/ladspa/${file##*/}" 91 _executables="${_executables} -executable=$_thisfile" 92done 93 94# Finalize .app 95macdeployqt "$APP" $_executables 96 97# Carla is a standalone plugin. Remove library, look for it side-by-side LMMS.app 98# This MUST be done AFTER calling macdeployqt 99# 100# For example: 101# /Applications/LMMS.app 102# /Applications/Carla.app 103carlalibs=$(echo "@CARLA_LIBRARIES@"|tr ";" "\n") 104 105# Loop over all libcarlas, fix linking 106for file in "$APP/Contents/lib/lmms/"libcarla*; do 107 _thisfile="$APP/Contents/lib/lmms/${file##*/}" 108 for lib in $carlalibs; do 109 _oldpath="../../Frameworks/lib${lib}.dylib" 110 _newpath="Carla.app/Contents/MacOS/lib${lib}.dylib" 111 install_name_tool -change @loader_path/$_oldpath \ 112 @executable_path/../../../$_newpath \ 113 "$_thisfile" 114 rm -f "$APP/Contents/Frameworks/lib${lib}.dylib" 115 done 116done 117 118# Cleanup 119rm -rf "$APP/Contents/bin" 120echo -e "\nFinished.\n\n" 121