install_apple.sh.in 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. set -e
  7. # STK rawwaves directory
  8. STK_RAWWAVE=$(brew --prefix stk)/share/stk/rawwaves
  9. # Place to create ".app" bundle
  10. APP="@CMAKE_BINARY_DIR@/@PROJECT_NAME_UCASE@.app"
  11. MSG_COLOR='\x1B[1;36m'
  12. COLOR_RESET='\x1B[0m'
  13. echo -e "$MSG_COLOR\n\nCreating App Bundle \"$APP\"...$COLOR_RESET"
  14. qtpath="$(dirname "@QT_QMAKE_EXECUTABLE@")"
  15. export PATH="$PATH:$qtpath"
  16. # Remove any old .app bundles
  17. rm -Rf "$APP"
  18. # Copy/overwrite Info.plist
  19. command cp "@CMAKE_BINARY_DIR@/Info.plist" "@CMAKE_INSTALL_PREFIX@/"
  20. # Create .app bundle containing contents from CMAKE_INSTALL_PREFIX
  21. mkdir -p "$APP/Contents/MacOS"
  22. mkdir -p "$APP/Contents/Frameworks"
  23. mkdir -p "$APP/Contents/Resources"
  24. mkdir -p "$APP/Contents/share/stk/rawwaves"
  25. cd "@CMAKE_INSTALL_PREFIX@"
  26. cp -R ./* "$APP/Contents"
  27. cp "@CMAKE_SOURCE_DIR@/cmake/apple/"*.icns "$APP/Contents/Resources/"
  28. cp "$STK_RAWWAVE"/*.raw "$APP/Contents/share/stk/rawwaves" > /dev/null 2>&1
  29. # Make all libraries writable for macdeployqt
  30. cd "$APP"
  31. find . -type f -print0 | xargs -0 chmod u+w
  32. lmmsbin="MacOS/@CMAKE_PROJECT_NAME@"
  33. zynlib="lib/lmms/libzynaddsubfx.so"
  34. zynfmk="Frameworks/libZynAddSubFxCore.dylib"
  35. zynbin="MacOS/RemoteZynAddSubFx"
  36. # Move lmms binary
  37. mv "$APP/Contents/bin/@CMAKE_PROJECT_NAME@" "$APP/Contents/$lmmsbin"
  38. # Fix zyn linking
  39. mv "$APP/Contents/lib/lmms/RemoteZynAddSubFx" "$APP/Contents/$zynbin"
  40. mv "$APP/Contents/lib/lmms/libZynAddSubFxCore.dylib" "$APP/Contents/$zynfmk"
  41. install_name_tool -change @rpath/libZynAddSubFxCore.dylib \
  42. @loader_path/../$zynfmk \
  43. "$APP/Contents/$zynbin"
  44. install_name_tool -change @rpath/libZynAddSubFxCore.dylib \
  45. @loader_path/../../$zynfmk \
  46. "$APP/Contents/$zynlib"
  47. # Replace @rpath with @loader_path for Carla
  48. # See also plugins/carlabase/CMakeLists.txt
  49. # This MUST be done BEFORE calling macdeployqt
  50. install_name_tool -change @rpath/libcarlabase.dylib \
  51. @loader_path/libcarlabase.dylib \
  52. "$APP/Contents/lib/lmms/libcarlapatchbay.so"
  53. install_name_tool -change @rpath/libcarlabase.dylib \
  54. @loader_path/libcarlabase.dylib \
  55. "$APP/Contents/lib/lmms/libcarlarack.so"
  56. # Link lmms binary
  57. _executables="${_executables} -executable=$APP/Contents/$zynbin"
  58. _executables="${_executables} -executable=$APP/Contents/$zynfmk"
  59. # Build a list of shared objects in target/lib/lmms
  60. for file in "$APP/Contents/lib/lmms/"*.so; do
  61. _thisfile="$APP/Contents/lib/lmms/${file##*/}"
  62. _executables="${_executables} -executable=$_thisfile"
  63. done
  64. # Build a list of shared objects in target/lib/lmms/ladspa
  65. for file in "$APP/Contents/lib/lmms/ladspa/"*.so; do
  66. _thisfile="$APP/Contents/lib/lmms/ladspa/${file##*/}"
  67. _executables="${_executables} -executable=$_thisfile"
  68. done
  69. # Finalize .app
  70. # shellcheck disable=SC2086
  71. macdeployqt "$APP" $_executables
  72. # Carla is a standalone plugin. Remove library, look for it side-by-side LMMS.app
  73. # This MUST be done AFTER calling macdeployqt
  74. #
  75. # For example:
  76. # /Applications/LMMS.app
  77. # /Applications/Carla.app
  78. carlalibs=$(echo "@CARLA_LIBRARIES@"|tr ";" "\n")
  79. # Loop over all libcarlas, fix linking
  80. for file in "$APP/Contents/lib/lmms/"libcarla*; do
  81. _thisfile="$APP/Contents/lib/lmms/${file##*/}"
  82. for lib in $carlalibs; do
  83. _oldpath="../../Frameworks/lib${lib}.dylib"
  84. _newpath="Carla.app/Contents/MacOS/lib${lib}.dylib"
  85. # shellcheck disable=SC2086
  86. install_name_tool -change @loader_path/$_oldpath \
  87. @executable_path/../../../$_newpath \
  88. "$_thisfile"
  89. rm -f "$APP/Contents/Frameworks/lib${lib}.dylib"
  90. done
  91. done
  92. # Cleanup
  93. rm -rf "$APP/Contents/bin"
  94. echo -e "\nFinished.\n\n"