AppImage: Don't set LD_LIBRARY_PATH (#7686)

Don't set LD_LIBRARY_PATH
Move launch_lmms.sh to dedicated apprun-hooks
This commit is contained in:
Tres Finocchiaro
2025-02-05 12:22:08 -05:00
committed by GitHub
parent 516b8dbca8
commit 6a0a4cd2b2
10 changed files with 99 additions and 33 deletions

View File

@@ -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)

View File

@@ -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)

View File

@@ -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 "")
@@ -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}")
@@ -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}

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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/"

View File

@@ -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

View File

@@ -1,30 +0,0 @@
#!/usr/bin/env bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
export PATH="$PATH:/sbin"
if command -v carla > /dev/null 2>&1; then
CARLAPATH="$(command -v carla)"
CARLAPREFIX="${CARLAPATH%/bin*}"
echo "Carla appears to be installed on this system at $CARLAPREFIX/lib[64]/carla so we'll use it." >&2
export LD_LIBRARY_PATH=$CARLAPREFIX/lib/carla:$CARLAPREFIX/lib64/carla:$LD_LIBRARY_PATH
else
echo "Carla does not appear to be installed. That's OK, please ignore any related library errors." >&2
fi
export LD_LIBRARY_PATH=$DIR/usr/lib/:$DIR/usr/lib/lmms:$LD_LIBRARY_PATH
# Prevent segfault on VirualBox
if lsmod |grep vboxguest > /dev/null 2>&1; then
echo "VirtualBox detected. Forcing libgl software rendering." >&2
export LIBGL_ALWAYS_SOFTWARE=1;
fi
if ldconfig -p | grep libjack.so.0 > /dev/null 2>&1; then
echo "Jack appears to be installed on this system, so we'll use it." >&2
else
echo "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
# FIXME: Remove when linuxdeploy supports subfolders https://github.com/linuxdeploy/linuxdeploy/issues/305
export LMMS_PLUGIN_DIR="$DIR/usr/lib/"
export LADSPA_PATH="$DIR/usr/lib/"
export SUIL_MODULE_DIR="$DIR/usr/lib/"
QT_X11_NO_NATIVE_MENUBAR=1 "$DIR"/usr/bin/lmms "$@"