Skip to content

Commit

Permalink
AppImage: Don't set LD_LIBRARY_PATH (LMMS#7686)
Browse files Browse the repository at this point in the history
Don't set LD_LIBRARY_PATH
Move launch_lmms.sh to dedicated apprun-hooks
  • Loading branch information
tresf authored Feb 5, 2025
1 parent 516b8db commit 6a0a4cd
Show file tree
Hide file tree
Showing 10 changed files with 99 additions and 33 deletions.
3 changes: 3 additions & 0 deletions cmake/apple/MacDeployQt.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ set(APP "${CPACK_TEMPORARY_INSTALL_DIRECTORY}/${CPACK_PROJECT_NAME_UCASE}.app")

# Toggle command echoing & verbosity
# 0 = no output, 1 = error/warning, 2 = normal, 3 = debug
if(DEFINED ENV{CPACK_DEBUG})
set(CPACK_DEBUG "$ENV{CPACK_DEBUG}")
endif()
if(NOT CPACK_DEBUG)
set(VERBOSITY 1)
set(COMMAND_ECHO NONE)
Expand Down
2 changes: 0 additions & 2 deletions cmake/linux/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ if(WANT_CPACK_TARBALL)
return()
endif()

install(FILES launch_lmms.sh DESTINATION bin)

# Standard CPack options
set(CPACK_GENERATOR "External" PARENT_SCOPE)
set(CPACK_EXTERNAL_ENABLE_STAGING true PARENT_SCOPE)
Expand Down
8 changes: 7 additions & 1 deletion cmake/linux/LinuxDeploy.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ endif()

# Toggle command echoing & verbosity
# 0 = no output, 1 = error/warning, 2 = normal, 3 = debug
if(DEFINED ENV{CPACK_DEBUG})
set(CPACK_DEBUG "$ENV{CPACK_DEBUG}")
endif()
if(NOT CPACK_DEBUG)
set(VERBOSITY 1)
set(APPIMAGETOOL_VERBOSITY "")
Expand Down Expand Up @@ -120,6 +123,10 @@ set(ENV{DISABLE_COPYRIGHT_FILES_DEPLOYMENT} 1)
# Patch desktop file
file(APPEND "${DESKTOP_FILE}" "X-AppImage-Version=${CPACK_PROJECT_VERSION}\n")

# Custom scripts to run immediately before lmms is executed
file(COPY "${CPACK_SOURCE_DIR}/cmake/linux/apprun-hooks" DESTINATION "${APP}")
file(REMOVE "${APP}/apprun-hooks/README.md")

# Prefer a hard-copy of .DirIcon over appimagetool's symlinking
# 256x256 default for Cinnamon Desktop https://forums.linuxmint.com/viewtopic.php?p=2585952
file(COPY "${APP}/usr/share/icons/hicolor/256x256/apps/${lmms}.png" DESTINATION "${APP}")
Expand Down Expand Up @@ -158,7 +165,6 @@ message(STATUS "Calling ${LINUXDEPLOY_BIN} --appdir \"${APP}\" ... [... librarie
execute_process(COMMAND "${LINUXDEPLOY_BIN}"
--appdir "${APP}"
--desktop-file "${DESKTOP_FILE}"
--custom-apprun "${CPACK_SOURCE_DIR}/cmake/linux/launch_lmms.sh"
--plugin qt
${LIBRARIES}
--verbosity ${VERBOSITY}
Expand Down
11 changes: 11 additions & 0 deletions cmake/linux/apprun-hooks/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# AppRun Hooks

Scripts placed in this directory will automatically be bundled into AppImages
(e.g. `LMMS.AppDir/apprun-hooks`) and executed immediately before lmms.

Quoting:

> "Sometimes it's important to perform actions before running the actual app. Some plugins might have to set e.g.,
> environment variables to work properly."
See also: https://github.com/linuxdeploy/linuxdeploy/wiki/Plugin-system#apprun-hooks
44 changes: 44 additions & 0 deletions cmake/linux/apprun-hooks/carla-hook.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env bash

# Workaround nuances with carla being an optional-yet-hard-linked plugin
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )"
ME="$( basename "${BASH_SOURCE[0]}")"
CARLA_LIB_NAME="libcarla_native-plugin.so"
KNOWN_LOCATIONS=("lib" "lib64")
unset CARLA_LIB_FILE

# Check for carla at "known" locations
if command -v carla > /dev/null 2>&1; then
CARLA_PATH="$(command -v carla)"
CARLA_PREFIX="${CARLA_PATH%/bin*}"

# Look for libcarla_native-plugin.so in adjacent lib directory
for lib in "${KNOWN_LOCATIONS[@]}"; do
if [ -e "$CARLA_PREFIX/$lib/carla/$CARLA_LIB_NAME" ]; then
# Add directory to LD_LIBRARY_PATH so libcarlabase.so can find it
CARLA_LIB_FILE="$CARLA_PREFIX/$lib/carla/$CARLA_LIB_NAME"
export LD_LIBRARY_PATH="$CARLA_PREFIX/$lib/carla/:$LD_LIBRARY_PATH"
echo "[$ME] Carla appears to be installed on this system at $CARLA_PREFIX/$lib/carla so we'll use it." >&2
break
fi
done
else
echo "[$ME] Carla does not appear to be installed. That's OK, please ignore any related library errors." >&2
fi

# Additional workarounds for library conflicts
# libgobject has been versioned "2.0" for over 20 years, but the ABI is constantly changing
KNOWN_CONFLICTS=("libgobject-2.0.so.0")
if [ -n "$CARLA_LIB_FILE" ]; then
for conflict in "${KNOWN_CONFLICTS[@]}"; do
# Only prepend LD_PRELOAD if we bundle the same version
if [ -e "$DIR/usr/lib/$conflict" ]; then
conflict_sys="$(ldd "$CARLA_LIB_FILE" | grep "$conflict" | awk '{print $3}')"
if [ -e "$conflict_sys" ]; then
# Add library to LD_PRELOAD so lmms can find it over its bundled version
echo "[$ME] Preferring the system's \"$conflict\" over the version bundled." >&2
export LD_PRELOAD="$conflict_sys:$LD_PRELOAD"
fi
fi
done
fi
11 changes: 11 additions & 0 deletions cmake/linux/apprun-hooks/jack-hook.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash

# Workaround crash when jack is missing by providing a dummy version
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )"
ME="$( basename "${BASH_SOURCE[0]}")"
if ldconfig -p | grep libjack.so.0 > /dev/null 2>&1; then
echo "[$ME] Jack appears to be installed on this system, so we'll use it." >&2
else
echo "[$ME] Jack does not appear to be installed. That's OK, we'll use a dummy version instead." >&2
export LD_LIBRARY_PATH=$DIR/usr/lib/lmms/optional:$LD_LIBRARY_PATH
fi
8 changes: 8 additions & 0 deletions cmake/linux/apprun-hooks/unity-hook.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

# Workaround Unity desktop menubar integration
# - Unity's menubar relocation breaks Qt's MDI window handling in Linux
# - Unity was default in Ubuntu 11.04 - 18.04
if [ "$XDG_CURRENT_DESKTOP" = "Unity" ]; then
export QT_X11_NO_NATIVE_MENUBAR=1
fi
8 changes: 8 additions & 0 deletions cmake/linux/apprun-hooks/usr-lib-hooks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

# Workaround libraries being incorrectly placed in usr/lib (e.g. instead of usr/lib/lmms, etc)
# FIXME: Remove when linuxdeploy supports subfolders https://github.com/linuxdeploy/linuxdeploy/issues/305
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )"
export LMMS_PLUGIN_DIR="$DIR/usr/lib/"
export LADSPA_PATH="$DIR/usr/lib/"
export SUIL_MODULE_DIR="$DIR/usr/lib/"
7 changes: 7 additions & 0 deletions cmake/linux/apprun-hooks/vbox-hook.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash
ME="$( basename "${BASH_SOURCE[0]}")"
# Workaround crash in VirtualBox when hardware rendering is enabled
if lsmod |grep vboxguest > /dev/null 2>&1; then
echo "[$ME] VirtualBox detected. Forcing libgl software rendering." >&2
export LIBGL_ALWAYS_SOFTWARE=1;
fi
30 changes: 0 additions & 30 deletions cmake/linux/launch_lmms.sh

This file was deleted.

0 comments on commit 6a0a4cd

Please sign in to comment.