SER Player: AppImage script for Qt project


#1

I want to share the script that I am now using to create AppImages for my Qt C++ project ‘SER Player’. This script was developed with and original recipe and lots of help from Simon.

This script is now working very well, generating a 64-bit or 32-bit AppImage depending on which version of Linux is running. It should be very simple to modify the script for other Qt C++ projects so it could be used as a starting point for others which is one reason that I am posting this.

Another reason for posting is others might be able to suggest fixes and improvements.

The ‘SER Player’ project is here:

To produce an AppImage from the project,the following should be entered at the command line:

$ cd ser-player
$ qmake CONFIG+=release
$ make
$ cd linux_appimage
$ ./make_appimage.sh

This will generate an AppImage in the linux_appimage directory.

This is the current make_appimage.sh script:

#!/bin/bash

copy_libs_for_binary()
{
    echo "Copying libs for binary $1 to $2"

    libs=$(ldd $1)

    lib=()
    mapfile -t lib <<< "$libs"
    for lib in "${lib[@]}"
    do
        #echo "lib: ${lib}"
        a=( $lib )
        count=${#a[@]}
        if ((count > 3)); then
            cp -n ${a[2]} $2
            sub_libs=$(ldd ${a[2]})
            sub_lib=()
            mapfile -t sub_lib <<< "$sub_libs"
            for lib2 in "${sub_lib[@]}"
            do
                #echo "    lib2: ${lib2}"
                a2=( $lib2 )
                count2=${#a2[@]}
                if ((count2 > 3)); then
                    cp -n ${a2[2]} $2
                fi
            done
        fi
    done
}


# Run the get_qt_details.sh script to set details of the Qt installation and the architecture
# This script is generated by qmake and sets the $QT_INSTALL_DIR and $SYS_ARCH variables.
this_dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
source $this_dir/get_qt_details.sh

# Create temp directory to work in when creating the AppImage
rm -rf temp
mkdir temp
cd temp

# Checkout and build AppImageKit
git clone https://github.com/probonopd/AppImageKit.git
./AppImageKit/build.sh

# Get the AppImage script functions file
wget -q https://github.com/probonopd/AppImages/raw/master/functions.sh -O ./functions.sh
. ./functions.sh

# Create the AppImage directory structure
mkdir -p ser-player.AppDir/usr/bin
#mkdir -p ser-player.AppDir/usr/lib/ser-player/libs
mkdir -p ser-player.AppDir/usr/lib/ser-player/platforms
mkdir -p ser-player.AppDir/usr/lib/ser-player/plugins/imageformats
mkdir -p ser-player.AppDir/usr/share/applications
mkdir -p ser-player.AppDir/usr/share/icons/hicolor/128x128/apps
mkdir -p ser-player.AppDir/usr/share/mime/packages

# Copy ser-player executable file into place and strip it
cp ../../bin/ser-player ser-player.AppDir/usr/lib/ser-player/
strip -s ser-player.AppDir/usr/lib/ser-player/ser-player
chmod 0755 ser-player.AppDir/usr/lib/ser-player/ser-player
chrpath -d ser-player.AppDir/usr/lib/ser-player/ser-player

# Copy shell script and wrapper files
cp ../files/ser-player ser-player.AppDir/usr/bin/
cp ../files/ser-player.wrapper ser-player.AppDir/usr/bin/

# Copy files in share directories
cp ../files/share/ser-player.desktop ser-player.AppDir/usr/share/applications/
cp ../files/ser-player.png ser-player.AppDir/usr/share/icons/hicolor/128x128/apps/
cp ../files/share/ser-player.xml ser-player.AppDir/usr/share/mime/packages/

# Copy file into top level of AppDir
cp ./AppImageKit/AppRun ser-player.AppDir/
cp ../files/ser-player.desktop ser-player.AppDir/
cp ../files/ser-player.png ser-player.AppDir/

# Copy Qt platform plugin to AppDir
cp ${QT_INSTALL_DIR}/plugins/platforms/libqxcb.* ser-player.AppDir/usr/lib/ser-player/platforms/

# Copy other Qt plugins to AppDir
cp ${QT_INSTALL_DIR}/plugins/imageformats/libqjpeg.* ser-player.AppDir/usr/lib/ser-player/plugins/imageformats/
cp ${QT_INSTALL_DIR}/plugins/imageformats/libqtiff.* ser-player.AppDir/usr/lib/ser-player/plugins/imageformats/

# Copy all required libs to AppDir
copy_libs_for_binary ../../bin/ser-player ser-player.AppDir/usr/lib/
copy_libs_for_binary ${QT_INSTALL_DIR}/plugins/platforms/libqxcb.so ser-player.AppDir/usr/lib/
copy_libs_for_binary ${QT_INSTALL_DIR}/plugins/imageformats/libqjpeg.so ser-player.AppDir/usr/lib/
copy_libs_for_binary ${QT_INSTALL_DIR}/plugins/imageformats/libqtiff.so ser-player.AppDir/usr/lib/

# Remove excluded libraries
cd ser-player.AppDir/usr/lib/
delete_blacklisted
cd ../../..

# Strip all libs and change permissions
strip -s ser-player.AppDir/usr/lib/lib*
chmod 0644 ser-player.AppDir/usr/lib/lib*

# Get the glibc version required using the glibc_need() function from the AppImageKit functions.sh 
cd ser-player.AppDir
GLIBC_NEEDED=$(glibc_needed)
cd ..

#wget -c "https://github.com/probonopd/AppImageKit/releases/download/5/AppImageAssistant" # (64-bit)


./AppImageKit/AppImageAssistant ./ser-player.AppDir/ ../ser-player-x.x.x-glibc${GLIBC_NEEDED}-${SYS_ARCH}.AppImage

cd ..

Cheers,
Chris


#2

thanks @cgarry!
i was searching for something something similar


#3

Thank you Chris.
Hoping someone will do the same with gtk :wink:


#4

Thanks Chris.

Some Qt-based app projects on GitHub use Travis CI for continuous builds (for testing), and I have written a script that allows them to bundle and upload the build artefacts as an AppImage on each build: Here.


#5

Simon,

I wish I had spotted those scripts before I wrote mine, they are a much better starting point than the .deb conversion script I used! Still, I think it has been a good learning experience for me to work through everything from scratch as it were.

A couple of things I noticed about these scripts when I quickly looked at them, at least the two I looked at:

  • These scripts seems to have the Qt plugins version and path hard coded.
  • They seem to be 64-bit only.

But thanks for pointing them out, I plan to update my script based on these scripts in order to tidy it up and make it look more presentable.

Cheers,
Chris


#6

Hi Chris,

thanks for having a go at improving these scripts - possibly we can make a generic version together that can be used by 3rd party projects to easily generate AppImages from Qt based Travis CI builds they are already doing. I have noticed that especially Qt based app projects seem to be interested in AppImage, as often they are interested in building one app for all 3 major operating systems.

So, i’m very interested in what you can make from these – especially the Qt version and plugins is something I wanted to do in a more generic way but didn’t figure out yet.

Best,
Simon


#7

Yes, I think a generic script for Qt projects would be of great interest to Qt users who choose Qt so they could support Linux, Windows and OS X.

I have just released v1.6.0 of SER Player with AppImages provided for the Linux versions. I am pleased that Linux support is no longer restricted to Debian based distributions.

Cheers,
Chris


#8

Hi Chris, on the SER Player homepage it still says “SER Player is an open source application with pre-built versions available for Windows, OS X and Debian Linux (Download links below).” I think the “Debian” can be removed now :slight_smile:


#9

Good catch thanks, page updated!


#10

I m using linuxdeployqt now :