diff --git a/.qmake.conf b/.qmake.conf new file mode 100644 index 0000000..ae52f0b --- /dev/null +++ b/.qmake.conf @@ -0,0 +1,5 @@ +load(qt_build_config) + +CONFIG += warning_clean exceptions + +MODULE_VERSION = 0.5.0 diff --git a/BUILDING.md b/BUILDING.md index b66838c..dc025b2 100644 --- a/BUILDING.md +++ b/BUILDING.md @@ -1,8 +1,8 @@ # Building from source -If you just would like to bundle your application, it is normally not necessary that you build `linuxdeployqt` yourself. Instead, download __linuxdeployqt-x86_64.AppImage__ from the [Releases](https://github.com/probonopd/linuxdeployqt/releases) page and `chmod a+x` it. This bundle, by the way, has been generated using `linuxdeployqt` itself as part of our Travis CI continuous build pipeline. +If you just would like to bundle your application for x86_64 platforms, it is normally not necessary that you build `linuxdeployqt` yourself. Instead, download __linuxdeployqt-x86_64.AppImage__ from the [Releases](https://github.com/probonopd/linuxdeployqt/releases) page and `chmod a+x` it. This bundle, by the way, has been generated using `linuxdeployqt` itself as part of our Travis CI continuous build pipeline. -So, if you still think you would like to compile from source, here are the steps: +So, if you are on another platform (e.g. i686, ARM) or would like to compile from source, here are the steps: * Get and build linuxdeployqt e.g., using Qt 5.7.0 (you could use this [Qt Creator AppImage](https://bintray.com/probono/AppImages/QtCreator#files) for this) @@ -12,10 +12,16 @@ git clone https://github.com/probonopd/linuxdeployqt.git # Then build in Qt Creator, or use export PATH=$(readlink -f /tmp/.mount_QtCreator-*-x86_64/*/gcc_64/bin/):$PATH cd linuxdeployqt -qmake linuxdeployqt.pro +qmake make ``` +* Optional if you want to install `linuxdeployqt` into your Qt installation, and make it a part of your Qt just like any other tool (qmake, etc.) + +``` +sudo make install +``` + * Build and install [patchelf](https://nixos.org/patchelf.html) (a small utility to modify the dynamic linker and RPATH of ELF executables; similar to `install_name_tool` on macOS). To learn more about this, see http://blog.qt.io/blog/2011/10/28/rpath-and-runpath/ ``` diff --git a/README.md b/README.md index 55db285..22f6d16 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# linuxdeployqt [![Build Status](https://travis-ci.org/probonopd/linuxdeployqt.svg?branch=master)](https://travis-ci.org/probonopd/linuxdeployqt) [![discourse](https://img.shields.io/badge/forum-discourse-orange.svg)](http://discourse.appimage.org/t/linuxdeployqt-new-linux-deployment-tool-for-qt/57) [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/probonopd/AppImageKit?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) [![irc](https://img.shields.io/badge/IRC-%23AppImage%20on%20freenode-blue.svg)](https://webchat.freenode.net/?channels=AppImage) +# linuxdeployqt [![Build Status](https://travis-ci.org/probonopd/linuxdeployqt.svg?branch=master)](https://travis-ci.org/probonopd/linuxdeployqt) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/93b4a359057e412b8a7673b4b61d7cb7)](https://www.codacy.com/app/probonopd/linuxdeployqt?utm_source=github.com&utm_medium=referral&utm_content=probonopd/linuxdeployqt&utm_campaign=Badge_Grade) [![discourse](https://img.shields.io/badge/forum-discourse-orange.svg)](http://discourse.appimage.org/t/linuxdeployqt-new-linux-deployment-tool-for-qt/57) [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/probonopd/AppImageKit?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) [![irc](https://img.shields.io/badge/IRC-%23AppImage%20on%20freenode-blue.svg)](https://webchat.freenode.net/?channels=AppImage) This Linux Deployment Tool for Qt, `linuxdeployqt`, takes an application as input and makes it self-contained by copying in the Qt libraries and plugins that the application uses into a bundle. This can optionally be put into an [AppImage](http://appimage.org/), and, using [fpm](https://github.com/probonopd/linuxdeployqt/issues/9), into cross-distro deb and rpm packages. @@ -18,8 +18,43 @@ Please download __linuxdeployqt-x86_64.AppImage__ from the [Releases](https://gi ## Usage +``` +Usage: linuxdeployqt app-binary [options] + +Options: + -verbose=<0-3> : 0 = no output, 1 = error/warning (default), 2 = normal, 3 = debug + -no-plugins : Skip plugin deployment + -appimage : Create an AppImage + -no-strip : Don't run 'strip' on the binaries + -bundle-non-qt-libs : Also bundle non-core, non-Qt libraries + -executable= : Let the given executable use the deployed libraries too + -qmldir= : Scan for QML imports to bundle from the given directory, determined by Qt's qmlimportscanner + -always-overwrite : Copy files even if the target file exists + -qmake= : The qmake executable to use + -no-translations : Skip deployment of translations + +linuxdeployqt takes an application as input and makes it +self-contained by copying in the Qt libraries and plugins that +the application uses. +``` + +#### Simplest example + +Given that a desktop file should be provided with an AppImage, `linuxdeployqt` can use that to determine the parameters of the build. + +`linuxdeployqt ./path/to/appdir/usr/share/application_name.desktop` + +Where the _desktop_ file specifies the executable to be run (with `EXEC=`), the name of the applications and an icon. +See [desktop file specification](https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html). + +For a more detailed example, see "Using linuxdeployqt with Travis CI" below. + +#### Checking library inclusion + Open in Qt Creator and build your application. Run it from the command line and inspect it with `ldd` to make sure the correct libraries from the correct locations are getting loaded, as `linuxdeployqt` will use `ldd` internally to determine from where to copy libraries into the bundle. +#### QMake configuration + __Important:__ By default, `linuxdeployqt` deploys the Qt instance that qmake on the $PATH points to, so make sure that it is the correct one. Verify that qmake finds the correct Qt instance like this before running the `linuxdeployqt` tool: ``` @@ -28,9 +63,13 @@ qmake -v QMake version 3.0 Using Qt version 5.7.0 in /tmp/.mount_QtCreator-5.7.0-x86_64/5.7/gcc_64/lib ``` + If this does not show the correct path to your Qt instance that you want to be bundled, then adjust your `$PATH` to find the correct `qmake`. + Alternatively, use the `-qmake` command line option to point the tool directly to the qmake executable to be used. +#### Remove unecessary files + Before running linuxdeployqt it may be wise to delete unneeded files that you do not wish to distribute from the build directory. These may be autogenerated during the build. You can delete them like so: ``` @@ -39,25 +78,6 @@ find $HOME/build-*-*_Qt_* \( -name "moc_*" -or -name "*.o" -or -name "qrc_*" -or Alternatively, you could use `$DESTDIR`. -``` -Usage: linuxdeployqt app-binary [options] - -Options: - -verbose=<0-3> : 0 = no output, 1 = error/warning (default), 2 = normal, 3 = debug - -no-plugins : Skip plugin deployment - -appimage : Create an AppImage - -no-strip : Don't run 'strip' on the binaries - -bundle-non-qt-libs : Also bundle non-core, non-Qt libraries - -executable= : Let the given executable use the deployed libraries too - -qmldir= : Scan for QML imports in the given path - -always-overwrite : Copy files even if the target file exists - -no-translations : Skip deployment of translations - -linuxdeployqt takes an application as input and makes it -self-contained by copying in the Qt libraries and plugins that -the application uses. -``` - ## Using linuxdeployqt with Travis CI A common use case for `linuxdeployqt` is to use it on Travis CI after the `make` command. The following example illustrates how to use `linuxdeployqt` with Travis CI. Create a `.travis.yml` file similar to this one (be sure to customize it, e.g., change `APPNAME` to the name of your application as it is spelled in the `Name=` entry of the `.desktop` file): @@ -69,24 +89,24 @@ sudo: require dist: trusty before_install: - - sudo add-apt-repository ppa:beineri/opt-qt58-trusty -y + - sudo add-apt-repository ppa:beineri/opt-qt59-trusty -y - sudo apt-get update -qq install: - - sudo apt-get -y install qt58base + - sudo apt-get -y install qt59base - source /opt/qt*/bin/qt*-env.sh script: - qmake PREFIX=/usr - make -j$(nproc) - make INSTALL_ROOT=appdir install ; find appdir/ - -after_success: - wget -c "https://github.com/probonopd/linuxdeployqt/releases/download/continuous/linuxdeployqt-continuous-x86_64.AppImage" - chmod a+x linuxdeployqt*.AppImage - unset QTDIR; unset QT_PLUGIN_PATH ; unset LD_LIBRARY_PATH - ./linuxdeployqt*.AppImage ./appdir/usr/share/applications/*.desktop -bundle-non-qt-libs - ./linuxdeployqt*.AppImage ./appdir/usr/share/applications/*.desktop -appimage + +after_success: - find ./appdir -executable -type f -exec ldd {} \; | grep " => /usr" | cut -d " " -f 2-3 | sort | uniq - curl --upload-file ./APPNAME*.AppImage https://transfer.sh/APPNAME-git.$(git rev-parse --short HEAD)-x86_64.AppImage ``` @@ -95,8 +115,14 @@ When you save your change, then Travis CI should build and upload an AppImage fo For this to work, you need to enable Travis CI for your repository as [described here](https://travis-ci.org/getting_started) __prior to merging this__, if you haven't already done so. +By default, qmake `.pro` files generated by Qt Creator unfortunately don't support `make install` out of the box. In this case you will get + +``` +make: Nothing to be done for `install'. +find: `appdir/': No such file or directory +``` -Note that if `qmake` does not allow for `make install` or does not install the desktop file and icon, then change it similar to https://github.com/probonopd/FeedTheMonkey/blob/master/FeedTheMonkey.pro. +If `qmake` does not allow for `make install` or does not install the desktop file and icon, then you need to change your `.pro` file it similar to https://github.com/probonopd/FeedTheMonkey/blob/master/FeedTheMonkey.pro. ``` - make INSTALL_ROOT=appdir install ; find appdir/ diff --git a/linuxdeployqt.pro b/linuxdeployqt.pro index 1e2f2d5..58c33f2 100644 --- a/linuxdeployqt.pro +++ b/linuxdeployqt.pro @@ -1,2 +1 @@ -TEMPLATE = subdirs -SUBDIRS = linuxdeployqt +load(qt_parts) diff --git a/linuxdeployqt/linuxdeployqt.pro b/linuxdeployqt/linuxdeployqt.pro deleted file mode 100644 index b9e628a..0000000 --- a/linuxdeployqt/linuxdeployqt.pro +++ /dev/null @@ -1,2 +0,0 @@ -QT = core -SOURCES += main.cpp ../shared/shared.cpp diff --git a/src/src.pro b/src/src.pro new file mode 100644 index 0000000..86290fc --- /dev/null +++ b/src/src.pro @@ -0,0 +1 @@ +TEMPLATE = aux diff --git a/sync.profile b/sync.profile new file mode 100644 index 0000000..58dbecb --- /dev/null +++ b/sync.profile @@ -0,0 +1,5 @@ +%modules = ( +); + +%moduleheaders = ( +); diff --git a/tests/tests-ci.sh b/tests/tests-ci.sh index 901ac43..a704606 100755 --- a/tests/tests-ci.sh +++ b/tests/tests-ci.sh @@ -10,8 +10,8 @@ mkdir -p linuxdeployqt.AppDir/usr/bin/ cp /usr/bin/patchelf /usr/local/bin/{appimagetool,mksquashfs,zsyncmake} linuxdeployqt.AppDir/usr/bin/ find linuxdeployqt.AppDir/ export VERSION=continuous -cp ./linuxdeployqt/linuxdeployqt linuxdeployqt.AppDir/usr/bin/ -./linuxdeployqt/linuxdeployqt linuxdeployqt.AppDir/linuxdeployqt.desktop -verbose=3 -appimage +cp ./bin/linuxdeployqt linuxdeployqt.AppDir/usr/bin/ +./bin/linuxdeployqt linuxdeployqt.AppDir/linuxdeployqt.desktop -verbose=3 -appimage ls -lh find *.AppDir xpra start :99 diff --git a/tests/tests.pro b/tests/tests.pro new file mode 100644 index 0000000..089e590 --- /dev/null +++ b/tests/tests.pro @@ -0,0 +1,11 @@ +TEMPLATE = subdirs + +SUBDIRS += \ + QtQuickControls2Application \ + QtWebEngineApplication \ + QtWidgetsApplication + +DISTFILES += \ + tests-ci.sh \ + tests-environment.sh \ + tests.sh diff --git a/tools/linuxdeployqt/linuxdeployqt.pro b/tools/linuxdeployqt/linuxdeployqt.pro new file mode 100644 index 0000000..26f115e --- /dev/null +++ b/tools/linuxdeployqt/linuxdeployqt.pro @@ -0,0 +1,17 @@ +option(host_build) + +QT = core +CONFIG += console + +TARGET = linuxdeployqt +VERSION = $$MODULE_VERSION + +DEFINES += BUILD_LINUXDEPLOYQT + +load(qt_tool) + +HEADERS += shared.h +SOURCES += main.cpp \ + shared.cpp + +DEFINES -= QT_USE_QSTRINGBUILDER #leads to compile errors if not disabled diff --git a/linuxdeployqt/main.cpp b/tools/linuxdeployqt/main.cpp similarity index 98% rename from linuxdeployqt/main.cpp rename to tools/linuxdeployqt/main.cpp index a87d407..e438fa9 100644 --- a/linuxdeployqt/main.cpp +++ b/tools/linuxdeployqt/main.cpp @@ -28,7 +28,7 @@ #include #include #include -#include "../shared/shared.h" +#include "shared.h" #include #include #include @@ -188,7 +188,7 @@ int main(int argc, char **argv) if (QDir().exists(appBinaryPath)) { qDebug() << "app-binary:" << appBinaryPath; } else { - qDebug() << "Error: Could not find app-binary" << appBinaryPath; + LogError() << "Error: Could not find app-binary" << appBinaryPath; return 1; } @@ -202,6 +202,11 @@ int main(int argc, char **argv) QString relativePrefix = fhsPrefix.replace(appDirPath+"/", ""); relativeBinPath = relativePrefix + "/bin/" + appName; } + if(appDirPath == "/"){ + LogError() << "'/' is not a valid AppDir. Please refer to the documentation."; + LogError() << "Consider adding INSTALL_ROOT or DESTDIR to your install steps."; + return 1; + } qDebug() << "appDirPath:" << appDirPath; qDebug() << "relativeBinPath:" << relativeBinPath; diff --git a/shared/shared.cpp b/tools/linuxdeployqt/shared.cpp similarity index 93% rename from shared/shared.cpp rename to tools/linuxdeployqt/shared.cpp index 1c7103c..d8ef4fa 100644 --- a/shared/shared.cpp +++ b/tools/linuxdeployqt/shared.cpp @@ -50,18 +50,18 @@ bool runStripEnabled = true; bool bundleAllButCoreLibs = false; bool fhsLikeMode = false; QString fhsPrefix; -bool alwaysOwerwriteEnabled = false; -QStringList librarySearchPath; -bool appstoreCompliant = false; +static bool alwaysOwerwriteEnabled = false; +static QStringList librarySearchPath; +static bool appstoreCompliant = false; int logLevel = 1; -bool qtDetected = 0; -bool qtDetectionComplete = 0; // As long as Qt is not detected yet, ldd may encounter "not found" messages, continue anyway -bool deployLibrary = false; +static int qtDetected = 0; +static bool qtDetectionComplete = 0; // As long as Qt is not detected yet, ldd may encounter "not found" messages, continue anyway +static bool deployLibrary = false; using std::cout; using std::endl; -QMap qtToBeBundledInfo; +static QMap qtToBeBundledInfo; enum QtModule #if defined(Q_COMPILER_CLASS_ENUM) || defined(Q_CC_MSVC) @@ -202,7 +202,7 @@ QDebug operator<<(QDebug debug, const LibraryInfo &info) return debug; } -QString bundleLibraryDirectory; +static QString bundleLibraryDirectory; inline QDebug operator<<(QDebug debug, const AppDirInfo &info) { @@ -298,6 +298,14 @@ LddInfo findDependencyInfo(const QString &binaryPath) } foreach (QString outputLine, outputLines) { + + if(outputLine.contains("libQt5")){ + qtDetected = 5; + } + if(outputLine.contains("libQtCore.so.4")){ + qtDetected = 4; + } + // LogDebug() << "ldd outputLine:" << outputLine; if ((outputLine.contains("not found")) && (qtDetectionComplete == 1)){ LogError() << "ldd outputLine:" << outputLine.replace("\t", ""); @@ -374,7 +382,7 @@ LibraryInfo parseLddLibraryLine(const QString &line, const QString &appDirPath, */ QStringList excludelist; - excludelist << "libasound.so.2" << "libcom_err.so.2" << "libcrypt.so.1" << "libc.so.6" << "libdl.so.2" << "libdrm.so.2" << "libexpat.so.1" << "libfontconfig.so.1" << "libgcc_s.so.1" << "libgdk_pixbuf-2.0.so.0" << "libgdk-x11-2.0.so.0" << "libgio-2.0.so.0" << "libglib-2.0.so.0" << "libGL.so.1" << "libgobject-2.0.so.0" << "libgpg-error.so.0" << "libgssapi_krb5.so.2" << "libgtk-x11-2.0.so.0" << "libhcrypto.so.4" << "libhx509.so.5" << "libICE.so.6" << "libidn.so.11" << "libk5crypto.so.3" << "libkeyutils.so.1" << "libkrb5.so.26" << "libkrb5.so.3" << "libkrb5support.so.0" << "libm.so.6" << "libnss3.so" << "libnssutil3.so" << "libp11-kit.so.0" << "libpangoft2-1.0.so.0" << "libpangocairo-1.0.so.0" << "libpango-1.0.so.0" << "libpcre.so.3" << "libpthread.so.0" << "libresolv.so.2" << "libroken.so.18" << "librt.so.1" << "libselinux.so.1" << "libSM.so.6" << "libstdc++.so.6" << "libusb-1.0.so.0" << "libuuid.so.1" << "libwind.so.0" << "libX11.so.6" << "libxcb.so.1" << "libz.so.1"; + excludelist << "libasound.so.2" << "libcom_err.so.2" << "libcrypt.so.1" << "libc.so.6" << "libdl.so.2" << "libdrm.so.2" << "libexpat.so.1" << "libfontconfig.so.1" << "libgcc_s.so.1" << "libgdk_pixbuf-2.0.so.0" << "libgdk-x11-2.0.so.0" << "libgio-2.0.so.0" << "libglib-2.0.so.0" << "libGL.so.1" << "libgobject-2.0.so.0" << "libgpg-error.so.0" << "libgssapi_krb5.so.2" << "libgtk-x11-2.0.so.0" << "libICE.so.6" << "libidn.so.11" << "libk5crypto.so.3" << "libkeyutils.so.1" << "libm.so.6" << "libnss3.so" << "libnssutil3.so" << "libp11-kit.so.0" << "libpangoft2-1.0.so.0" << "libpangocairo-1.0.so.0" << "libpango-1.0.so.0" << "libpthread.so.0" << "libresolv.so.2" << "librt.so.1" << "libselinux.so.1" << "libSM.so.6" << "libstdc++.so.6" << "libusb-1.0.so.0" << "libuuid.so.1" << "libX11.so.6" << "libxcb.so.1" << "libz.so.1"; LogDebug() << "excludelist:" << excludelist; if (! trimmed.contains("libicu")) { if (containsHowOften(excludelist, QFileInfo(trimmed).completeBaseName())) { @@ -577,53 +585,6 @@ QList getQtLibrariesForPaths(const QStringList &paths, const QStrin return result; } -QStringList getBinaryDependencies(const QString executablePath, - const QString &path, - const QList &additionalBinariesContainingRpaths) -{ - QStringList binaries; - - const QList dependencies = findDependencyInfo(path).dependencies; - - bool rpathsLoaded = false; - QSet rpaths; - - // return bundle-local dependencies. (those starting with @executable_path) - foreach (const DylibInfo &info, dependencies) { - QString trimmedLine = info.binaryPath; - if (trimmedLine.startsWith("@executable_path/")) { - QString binary = QDir::cleanPath(executablePath + trimmedLine.mid(QStringLiteral("@executable_path/").length())); - if (binary != path) - binaries.append(binary); - } else if (trimmedLine.startsWith("@rpath/")) { - if (!rpathsLoaded) { - rpaths = getBinaryRPaths(path, true, executablePath); - foreach (const QString &binaryPath, additionalBinariesContainingRpaths) { - QSet binaryRpaths = getBinaryRPaths(binaryPath, true); - rpaths += binaryRpaths; - } - rpathsLoaded = true; - } - bool resolved = false; - foreach (const QString &rpath, rpaths) { - QString binary = QDir::cleanPath(rpath + "/" + trimmedLine.mid(QStringLiteral("@rpath/").length())); - LogDebug() << "Checking for" << binary; - if (QFile::exists(binary)) { - binaries.append(binary); - resolved = true; - break; - } - } - if (!resolved && !rpaths.isEmpty()) { - LogError() << "Cannot resolve rpath" << trimmedLine; - LogError() << " using" << rpaths; - } - } - } - - return binaries; -} - // copies everything _inside_ sourcePath to destinationPath bool recursiveCopy(const QString &sourcePath, const QString &destinationPath) { @@ -717,26 +678,28 @@ QString copyDylib(const LibraryInfo &library, const QString path) return dylibDestinationBinaryPath; } -void runPatchelf(QStringList options) +QString runPatchelf(QStringList options) { QProcess patchelftool; + LogDebug() << "options:" << options; patchelftool.start("patchelf", options); if (!patchelftool.waitForStarted()) { - if(patchelftool.errorString().contains("execvp: No such file or directory")){ + if(patchelftool.errorString().contains("No such file or directory")){ LogError() << "Could not start patchelf."; LogError() << "Make sure it is installed on your $PATH, e.g., in /usr/local/bin."; LogError() << "You can get it from https://nixos.org/patchelf.html."; } else { - LogError() << "Could not start patchelftool. Process error is" << patchelftool.errorString(); + LogError() << "Could not start patchelf tool. Process error is" << patchelftool.errorString(); } exit(1); } patchelftool.waitForFinished(); if (patchelftool.exitCode() != 0) { LogError() << "runPatchelf:" << patchelftool.readAllStandardError(); - LogError() << "runPatchelf:" << patchelftool.readAllStandardOutput(); + // LogError() << "runPatchelf:" << patchelftool.readAllStandardOutput(); // exit(1); // Do not exit because this could be a script that patchelf can't work on } + return(patchelftool.readAllStandardOutput().trimmed()); } bool patchQtCore(const QString &path, const QString &variable, const QString &value) @@ -789,6 +752,21 @@ bool patchQtCore(const QString &path, const QString &variable, const QString &va void changeIdentification(const QString &id, const QString &binaryPath) { + LogNormal() << "Checking rpath in" << binaryPath; + QString oldRpath = runPatchelf(QStringList() << "--print-rpath" << binaryPath); + LogDebug() << "oldRpath:" << oldRpath; + if (oldRpath.startsWith("/")){ + LogDebug() << "Old rpath in" << binaryPath << "starts with /, hence adding it to LD_LIBRARY_PATH"; + // FIXME: Split along ":" characters, check each one, only append to LD_LIBRARY_PATH if not already there + QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); + QString oldPath = env.value("LD_LIBRARY_PATH"); + if (not oldPath.contains(oldRpath)){ + QString newPath = oldRpath + ":" + oldPath; // FIXME: If we use a ldd replacement, we still need to observe this path + // FIXME: Directory layout might be different for system Qt; cannot assume lib/ to always be inside the Qt directory + LogDebug() << "Added to LD_LIBRARY_PATH:" << newPath; + setenv("LD_LIBRARY_PATH",newPath.toUtf8().constData(),1); + } + } LogNormal() << "Changing rpath in" << binaryPath << "to" << id; runPatchelf(QStringList() << "--set-rpath" << id << binaryPath); @@ -941,8 +919,8 @@ DeploymentInfo deployQtLibraries(QList libraries, LogNormal() << "Setting deploymentInfo.qtPath to:" << library.libraryDirectory; deploymentInfo.qtPath = library.libraryDirectory; } - - if(library.libraryName.contains("libQt") and library.libraryName.contains("Widgets.so")) { + + if(library.libraryName.contains("libQt") and library.libraryName.contains("Widgets.so")) { deploymentInfo.requiresQtWidgetsLibrary = true; } @@ -1014,15 +992,6 @@ DeploymentInfo deployQtLibraries(const QString &appDirPath, const QStringList &a // Find out whether Qt is a dependency of the application to be bundled LddInfo lddInfo = findDependencyInfo(appBinaryPath); - foreach (const DylibInfo dep, lddInfo.dependencies) { - LogDebug() << "dep.binaryPath" << dep.binaryPath; - if(dep.binaryPath.contains("libQt5")){ - qtDetected = 5; - } - if(dep.binaryPath.contains("libQtCore.so.4")){ - qtDetected = 4; - } - } if(qtDetected != 0){ @@ -1032,21 +1001,22 @@ DeploymentInfo deployQtLibraries(const QString &appDirPath, const QStringList &a // Use the qmake executable passed in by the user: QString qmakePath = qmake; - // If we did not get a qmake, first try to find "qmake", which is the - // upstream name of the binary in both Qt4 and Qt5: if (qmakePath.isEmpty()) { - qmakePath = QStandardPaths::findExecutable("qmake"); - } - - // But openSUSE has qmake for Qt 4 and qmake-qt5 for Qt 5 - // Qt 4 on Fedora comes with suffix -qt4 - // http://www.geopsy.org/wiki/index.php/Installing_Qt_binary_packages - if(qmakePath.isEmpty()){ + // Try to find a version specific qmake first + // openSUSE has qmake for Qt 4 and qmake-qt5 for Qt 5 + // Qt 4 on Fedora comes with suffix -qt4 + // http://www.geopsy.org/wiki/index.php/Installing_Qt_binary_packages if(qtDetected == 5){ qmakePath = QStandardPaths::findExecutable("qmake-qt5"); - } - if(qtDetected == 4){ + LogDebug() << "qmake 5"; + } else if(qtDetected == 4){ qmakePath = QStandardPaths::findExecutable("qmake-qt4"); + LogDebug() << "qmake 4"; + } + + if(qmakePath == ""){ + // The upstream name of the binary is "qmake", for Qt 4 and Qt 5 + qmakePath = QStandardPaths::findExecutable("qmake"); } } @@ -1055,6 +1025,7 @@ DeploymentInfo deployQtLibraries(const QString &appDirPath, const QStringList &a exit(1); } + LogNormal() << "Using qmake: " << qmakePath; QString output = captureOutput(qmakePath + " -query"); LogDebug() << "-query output from qmake:" << output; @@ -1089,10 +1060,14 @@ DeploymentInfo deployQtLibraries(const QString &appDirPath, const QStringList &a /* From now on let ldd exit if it doesn't find something */ qtDetectionComplete = 1; + QString libraryPath; if(fhsLikeMode == false){ - changeIdentification("$ORIGIN/lib/" + bundleLibraryDirectory, QFileInfo(applicationBundle.binaryPath).canonicalFilePath()); + libraryPath = QFileInfo(applicationBundle.binaryPath).dir().filePath("lib/" + bundleLibraryDirectory); } else { - changeIdentification("$ORIGIN/../lib/" + bundleLibraryDirectory, QFileInfo(applicationBundle.binaryPath).canonicalFilePath()); + libraryPath = QFileInfo(applicationBundle.binaryPath).dir().filePath("../lib/" + bundleLibraryDirectory); + } + foreach (const QString &executable, QStringList() << applicationBundle.binaryPath << additionalExecutables) { + changeIdentification("$ORIGIN/" + QFileInfo(executable).dir().relativeFilePath(libraryPath) + "/" + bundleLibraryDirectory, QFileInfo(executable).canonicalFilePath()); } applicationBundle.libraryPaths = findAppLibraries(appDirPath); LogDebug() << "applicationBundle.libraryPaths:" << applicationBundle.libraryPaths; @@ -1288,23 +1263,23 @@ void createQtConf(const QString &appDirPath) // See https://github.com/probonopd/linuxdeployqt/issues/ 75, 98, 99 QByteArray contents; if(fhsLikeMode){ - contents = "# Generated by linuxdeployqt\n" - "# https://github.com/probonopd/linuxdeployqt/\n" - "[Paths]\n" - "Prefix = ../\n" - "Plugins = plugins\n" - "Imports = qml\n" - "Qml2Imports = qml\n"; + contents = "# Generated by linuxdeployqt\n" + "# https://github.com/probonopd/linuxdeployqt/\n" + "[Paths]\n" + "Prefix = ../\n" + "Plugins = plugins\n" + "Imports = qml\n" + "Qml2Imports = qml\n"; } else { - contents = "# Generated by linuxdeployqt\n" - "# https://github.com/probonopd/linuxdeployqt/\n" - "[Paths]\n" - "Prefix = ./\n" - "Plugins = plugins\n" - "Imports = qml\n" - "Qml2Imports = qml\n"; - } - + contents = "# Generated by linuxdeployqt\n" + "# https://github.com/probonopd/linuxdeployqt/\n" + "[Paths]\n" + "Prefix = ./\n" + "Plugins = plugins\n" + "Imports = qml\n" + "Qml2Imports = qml\n"; + } + QString filePath = appDirPath + "/"; // Is picked up when placed next to the main executable QString fileName = QDir::cleanPath(appBinaryPath + "/../qt.conf"); @@ -1629,7 +1604,7 @@ void deployTranslations(const QString &appDirPath, quint64 usedQtModules) LogDebug() << "Deploying translations..."; QString qtTranslationsPath = qtToBeBundledInfo.value("QT_INSTALL_TRANSLATIONS"); if (qtTranslationsPath.isEmpty() || !QFile::exists(qtTranslationsPath)) { - LogError() << "Qt translations path could not be determined"; + LogDebug() << "Qt translations path could not be determined, maybe there are no translations?"; return; } diff --git a/shared/shared.h b/tools/linuxdeployqt/shared.h similarity index 100% rename from shared/shared.h rename to tools/linuxdeployqt/shared.h diff --git a/tools/tools.pro b/tools/tools.pro new file mode 100644 index 0000000..91ee914 --- /dev/null +++ b/tools/tools.pro @@ -0,0 +1,4 @@ +TEMPLATE = subdirs +CONFIG += ordered + +SUBDIRS += linuxdeployqt