Browse Source

Merge pull request #116 from mhoeher/master

Allow the qmake executable to be passed on CLI
master
TheAssassin 7 years ago
committed by GitHub
parent
commit
05eb73a516
  1. 6
      README.md
  2. 18
      tests/tests.sh
  3. 14
      tools/linuxdeployqt/main.cpp
  4. 122
      tools/linuxdeployqt/shared.cpp
  5. 4
      tools/linuxdeployqt/shared.h

6
README.md

@ -30,6 +30,7 @@ Options:
-executable=<path> : Let the given executable use the deployed libraries too -executable=<path> : Let the given executable use the deployed libraries too
-qmldir=<path> : Scan for QML imports to bundle from the given directory, determined by Qt's qmlimportscanner -qmldir=<path> : 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 -always-overwrite : Copy files even if the target file exists
-qmake=<path> : The qmake executable to use
-no-translations : Skip deployment of translations -no-translations : Skip deployment of translations
linuxdeployqt takes an application as input and makes it linuxdeployqt takes an application as input and makes it
@ -54,7 +55,7 @@ Open in Qt Creator and build your application. Run it from the command line and
#### QMake configuration #### QMake configuration
__Important:__ `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: __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:
``` ```
qmake -v qmake -v
@ -62,8 +63,11 @@ qmake -v
QMake version 3.0 QMake version 3.0
Using Qt version 5.7.0 in /tmp/.mount_QtCreator-5.7.0-x86_64/5.7/gcc_64/lib 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`. 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 #### 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: 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:

18
tests/tests.sh

@ -79,6 +79,24 @@ killall QtWidgetsApplication && echo "SUCCESS"
cd ../../../ cd ../../../
###############################################################################
# Test bundling the sample Qt Widgets Application passing in the qmake exe
###############################################################################
cd tests/QtWidgetsApplication/build/
mkdir -p explicitqmake
cp QtWidgetsApplication explicitqmake/
../../../linuxdeployqt-*-x86_64.AppImage explicitqmake/QtWidgetsApplication \
-qmake=$(which qmake)
ldd explicitqmake/QtWidgetsApplication
find explicitqmake/
LD_DEBUG=libs explicitqmake/QtWidgetsApplication &
sleep 5
killall QtWidgetsApplication && echo "SUCCESS"
cd ../../../
############################################################################### ###############################################################################
# Test bundling the sample Qt Quick Controls 2 Application that comes with Qt Creator # Test bundling the sample Qt Quick Controls 2 Application that comes with Qt Creator
############################################################################### ###############################################################################

14
tools/linuxdeployqt/main.cpp

@ -55,14 +55,16 @@ int main(int argc, char **argv)
qDebug() << " -executable=<path> : Let the given executable use the deployed libraries too"; qDebug() << " -executable=<path> : Let the given executable use the deployed libraries too";
qDebug() << " -qmldir=<path> : Scan for QML imports in the given path"; qDebug() << " -qmldir=<path> : Scan for QML imports in the given path";
qDebug() << " -always-overwrite : Copy files even if the target file exists"; qDebug() << " -always-overwrite : Copy files even if the target file exists";
qDebug() << " -qmake=<path> : The qmake executable to use";
qDebug() << " -no-translations : Skip deployment of translations."; qDebug() << " -no-translations : Skip deployment of translations.";
qDebug() << ""; qDebug() << "";
qDebug() << "linuxdeployqt takes an application as input and makes it"; qDebug() << "linuxdeployqt takes an application as input and makes it";
qDebug() << "self-contained by copying in the Qt libraries and plugins that"; qDebug() << "self-contained by copying in the Qt libraries and plugins that";
qDebug() << "the application uses."; qDebug() << "the application uses.";
qDebug() << ""; qDebug() << "";
qDebug() << "It deploys the Qt instance that qmake on the $PATH points to,"; qDebug() << "By default it deploys the Qt instance that qmake on the $PATH points to.";
qDebug() << "so make sure that it is the correct one."; qDebug() << "The '-qmake' option can be used to point to the qmake executable";
qDebug() << "to be used instead.";
qDebug() << ""; qDebug() << "";
qDebug() << "Plugins related to a Qt library are copied in with the library."; qDebug() << "Plugins related to a Qt library are copied in with the library.";
/* TODO: To be implemented /* TODO: To be implemented
@ -171,6 +173,7 @@ int main(int argc, char **argv)
bool qmldirArgumentUsed = false; bool qmldirArgumentUsed = false;
bool skipTranslations = false; bool skipTranslations = false;
QStringList qmlDirs; QStringList qmlDirs;
QString qmakeExecutable;
/* FHS-like mode is for an application that has been installed to a $PREFIX which is otherwise empty, e.g., /path/to/usr. /* FHS-like mode is for an application that has been installed to a $PREFIX which is otherwise empty, e.g., /path/to/usr.
* In this case, we want to construct an AppDir in /path/to. */ * In this case, we want to construct an AppDir in /path/to. */
@ -365,6 +368,10 @@ int main(int argc, char **argv)
} else if (argument == QByteArray("-always-overwrite")) { } else if (argument == QByteArray("-always-overwrite")) {
LogDebug() << "Argument found:" << argument; LogDebug() << "Argument found:" << argument;
alwaysOwerwriteEnabled = true; alwaysOwerwriteEnabled = true;
} else if (argument.startsWith("-qmake=")) {
LogDebug() << "Argument found:" << argument;
int index = argument.indexOf("=");
qmakeExecutable = argument.mid(index+1);
} else if (argument == QByteArray("-no-translations")) { } else if (argument == QByteArray("-no-translations")) {
LogDebug() << "Argument found:" << argument; LogDebug() << "Argument found:" << argument;
skipTranslations = true; skipTranslations = true;
@ -381,7 +388,8 @@ int main(int argc, char **argv)
} }
} }
DeploymentInfo deploymentInfo = deployQtLibraries(appDirPath, additionalExecutables); DeploymentInfo deploymentInfo = deployQtLibraries(appDirPath, additionalExecutables,
qmakeExecutable);
// Convenience: Look for .qml files in the current directoty if no -qmldir specified. // Convenience: Look for .qml files in the current directoty if no -qmldir specified.
if (qmlDirs.isEmpty()) { if (qmlDirs.isEmpty()) {

122
tools/linuxdeployqt/shared.cpp

@ -61,7 +61,7 @@ bool deployLibrary = false;
using std::cout; using std::cout;
using std::endl; using std::endl;
QMap<QString,QString> qtToBeBundledInfo; static QMap<QString,QString> qtToBeBundledInfo;
enum QtModule enum QtModule
#if defined(Q_COMPILER_CLASS_ENUM) || defined(Q_CC_MSVC) #if defined(Q_COMPILER_CLASS_ENUM) || defined(Q_CC_MSVC)
@ -202,7 +202,7 @@ QDebug operator<<(QDebug debug, const LibraryInfo &info)
return debug; return debug;
} }
QString bundleLibraryDirectory; static QString bundleLibraryDirectory;
inline QDebug operator<<(QDebug debug, const AppDirInfo &info) inline QDebug operator<<(QDebug debug, const AppDirInfo &info)
{ {
@ -217,20 +217,20 @@ inline QDebug operator<<(QDebug debug, const AppDirInfo &info)
// on architecture. See "vDSO names" in the notes section of vdso(7) // on architecture. See "vDSO names" in the notes section of vdso(7)
// for more information. // for more information.
static bool lddOutputContainsLinuxVDSO(const QString &lddOutput) { static bool lddOutputContainsLinuxVDSO(const QString &lddOutput) {
// aarch64, arm, mips, x86_64, x86/x32 // aarch64, arm, mips, x86_64, x86/x32
if (lddOutput.contains(QStringLiteral("linux-vdso.so.1"))) { if (lddOutput.contains(QStringLiteral("linux-vdso.so.1"))) {
return true; return true;
// ppc32, s390 // ppc32, s390
} else if (lddOutput.contains(QStringLiteral("linux-vdso32.so.1"))) { } else if (lddOutput.contains(QStringLiteral("linux-vdso32.so.1"))) {
return true; return true;
// ppc64, s390x // ppc64, s390x
} else if (lddOutput.contains(QStringLiteral("linux-vdso64.so.1"))) { } else if (lddOutput.contains(QStringLiteral("linux-vdso64.so.1"))) {
return true; return true;
// ia64, sh, i386 // ia64, sh, i386
} else if (lddOutput.contains(QStringLiteral("linux-gate.so.1"))) { } else if (lddOutput.contains(QStringLiteral("linux-gate.so.1"))) {
return true; return true;
} }
return false; return false;
} }
bool copyFilePrintStatus(const QString &from, const QString &to) bool copyFilePrintStatus(const QString &from, const QString &to)
@ -756,16 +756,16 @@ void changeIdentification(const QString &id, const QString &binaryPath)
QString oldRpath = runPatchelf(QStringList() << "--print-rpath" << binaryPath); QString oldRpath = runPatchelf(QStringList() << "--print-rpath" << binaryPath);
LogDebug() << "oldRpath:" << oldRpath; LogDebug() << "oldRpath:" << oldRpath;
if (oldRpath.startsWith("/")){ if (oldRpath.startsWith("/")){
LogDebug() << "Old rpath in" << binaryPath << "starts with /, hence adding it to LD_LIBRARY_PATH"; 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 // FIXME: Split along ":" characters, check each one, only append to LD_LIBRARY_PATH if not already there
QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
QString oldPath = env.value("LD_LIBRARY_PATH"); QString oldPath = env.value("LD_LIBRARY_PATH");
if (not oldPath.contains(oldRpath)){ if (not oldPath.contains(oldRpath)){
QString newPath = oldRpath + ":" + oldPath; // FIXME: If we use a ldd replacement, we still need to observe this path 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 // 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; LogDebug() << "Added to LD_LIBRARY_PATH:" << newPath;
setenv("LD_LIBRARY_PATH",newPath.toUtf8().constData(),1); setenv("LD_LIBRARY_PATH",newPath.toUtf8().constData(),1);
} }
} }
LogNormal() << "Changing rpath in" << binaryPath << "to" << id; LogNormal() << "Changing rpath in" << binaryPath << "to" << id;
runPatchelf(QStringList() << "--set-rpath" << id << binaryPath); runPatchelf(QStringList() << "--set-rpath" << id << binaryPath);
@ -920,7 +920,7 @@ DeploymentInfo deployQtLibraries(QList<LibraryInfo> libraries,
deploymentInfo.qtPath = 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; deploymentInfo.requiresQtWidgetsLibrary = true;
} }
@ -981,7 +981,7 @@ static QString captureOutput(const QString &command)
return process.readAllStandardOutput(); return process.readAllStandardOutput();
} }
DeploymentInfo deployQtLibraries(const QString &appDirPath, const QStringList &additionalExecutables) DeploymentInfo deployQtLibraries(const QString &appDirPath, const QStringList &additionalExecutables, const QString& qmake)
{ {
AppDirInfo applicationBundle; AppDirInfo applicationBundle;
@ -998,24 +998,26 @@ DeploymentInfo deployQtLibraries(const QString &appDirPath, const QStringList &a
// Determine the location of the Qt to be bundled // Determine the location of the Qt to be bundled
LogDebug() << "Using qmake to determine the location of the Qt to be bundled"; LogDebug() << "Using qmake to determine the location of the Qt to be bundled";
QString qmakePath = ""; // Use the qmake executable passed in by the user:
QString qmakePath = qmake;
// Try to find a version specific qmake first if (qmakePath.isEmpty()) {
// openSUSE has qmake for Qt 4 and qmake-qt5 for Qt 5 // Try to find a version specific qmake first
// Qt 4 on Fedora comes with suffix -qt4 // openSUSE has qmake for Qt 4 and qmake-qt5 for Qt 5
// http://www.geopsy.org/wiki/index.php/Installing_Qt_binary_packages // Qt 4 on Fedora comes with suffix -qt4
if(qtDetected == 5){ // http://www.geopsy.org/wiki/index.php/Installing_Qt_binary_packages
qmakePath = QStandardPaths::findExecutable("qmake-qt5"); if(qtDetected == 5){
LogDebug() << "qmake 5"; qmakePath = QStandardPaths::findExecutable("qmake-qt5");
} else if(qtDetected == 4){ LogDebug() << "qmake 5";
qmakePath = QStandardPaths::findExecutable("qmake-qt4"); } else if(qtDetected == 4){
LogDebug() << "qmake 4"; qmakePath = QStandardPaths::findExecutable("qmake-qt4");
} LogDebug() << "qmake 4";
}
if(qmakePath == ""){ if(qmakePath == ""){
// The upstream name of the binary is "qmake", for Qt 4 and Qt 5 // The upstream name of the binary is "qmake", for Qt 4 and Qt 5
qmakePath = QStandardPaths::findExecutable("qmake"); qmakePath = QStandardPaths::findExecutable("qmake");
}
} }
if(qmakePath == ""){ if(qmakePath == ""){
@ -1120,7 +1122,7 @@ void deployPlugins(const AppDirInfo &appDirInfo, const QString &pluginSourcePath
} }
} else { } else {
pluginList.append(QStringLiteral("imageformats/") + plugin); pluginList.append(QStringLiteral("imageformats/") + plugin);
} }
} }
} }
@ -1261,21 +1263,21 @@ void createQtConf(const QString &appDirPath)
// See https://github.com/probonopd/linuxdeployqt/issues/ 75, 98, 99 // See https://github.com/probonopd/linuxdeployqt/issues/ 75, 98, 99
QByteArray contents; QByteArray contents;
if(fhsLikeMode){ if(fhsLikeMode){
contents = "# Generated by linuxdeployqt\n" contents = "# Generated by linuxdeployqt\n"
"# https://github.com/probonopd/linuxdeployqt/\n" "# https://github.com/probonopd/linuxdeployqt/\n"
"[Paths]\n" "[Paths]\n"
"Prefix = ../\n" "Prefix = ../\n"
"Plugins = plugins\n" "Plugins = plugins\n"
"Imports = qml\n" "Imports = qml\n"
"Qml2Imports = qml\n"; "Qml2Imports = qml\n";
} else { } else {
contents = "# Generated by linuxdeployqt\n" contents = "# Generated by linuxdeployqt\n"
"# https://github.com/probonopd/linuxdeployqt/\n" "# https://github.com/probonopd/linuxdeployqt/\n"
"[Paths]\n" "[Paths]\n"
"Prefix = ./\n" "Prefix = ./\n"
"Plugins = plugins\n" "Plugins = plugins\n"
"Imports = qml\n" "Imports = qml\n"
"Qml2Imports = qml\n"; "Qml2Imports = qml\n";
} }
QString filePath = appDirPath + "/"; // Is picked up when placed next to the main executable QString filePath = appDirPath + "/"; // Is picked up when placed next to the main executable

4
tools/linuxdeployqt/shared.h

@ -114,7 +114,9 @@ QString findAppBinary(const QString &appDirPath);
QList<LibraryInfo> getQtLibraries(const QString &path, const QString &appDirPath, const QSet<QString> &rpaths); QList<LibraryInfo> getQtLibraries(const QString &path, const QString &appDirPath, const QSet<QString> &rpaths);
QList<LibraryInfo> getQtLibraries(const QStringList &lddLines, const QString &appDirPath, const QSet<QString> &rpaths); QList<LibraryInfo> getQtLibraries(const QStringList &lddLines, const QString &appDirPath, const QSet<QString> &rpaths);
QString copyLibrary(const LibraryInfo &library, const QString path); QString copyLibrary(const LibraryInfo &library, const QString path);
DeploymentInfo deployQtLibraries(const QString &appDirPath, const QStringList &additionalExecutables); DeploymentInfo deployQtLibraries(const QString &appDirPath,
const QStringList &additionalExecutables,
const QString &qmake);
DeploymentInfo deployQtLibraries(QList<LibraryInfo> libraries,const QString &bundlePath, const QStringList &binaryPaths, bool useLoaderPath); DeploymentInfo deployQtLibraries(QList<LibraryInfo> libraries,const QString &bundlePath, const QStringList &binaryPaths, bool useLoaderPath);
void createQtConf(const QString &appDirPath); void createQtConf(const QString &appDirPath);
void createQtConfForQtWebEngineProcess(const QString &appDirPath); void createQtConfForQtWebEngineProcess(const QString &appDirPath);

Loading…
Cancel
Save