diff options
author | Tobias Markmann <tm@ayena.de> | 2015-04-13 13:14:23 (GMT) |
---|---|---|
committer | Tobias Markmann <tm@ayena.de> | 2015-04-28 12:38:26 (GMT) |
commit | 4ac05ebaf6c913b4bfcc7c4e7abeb6ace9efe5c8 (patch) | |
tree | 24be42f31167f2ca82bb3026e939a65233f84846 | |
parent | 908b442c7b5e74c9d557a1468b321ef4255e402e (diff) | |
download | swift-4ac05ebaf6c913b4bfcc7c4e7abeb6ace9efe5c8.zip swift-4ac05ebaf6c913b4bfcc7c4e7abeb6ace9efe5c8.tar.bz2 |
Add Qt flags detection using pkg-config on Linux platforms
Fix qt4.py SCons module to use the specific tools of the correct Qt
verison.
On non-Windows and non-Darwin platforms SCons will try to detect the
correct Qt compiler and linker flags from pkg-config.
Added the ability to build Slimber with Qt5.
Fixed Qt5 support on Linux when using prebuilt Qt distribution from Qt.
This patch adds support for building Swift on Arch Linux, with Qt4 and
Qt5.
Test-Information:
Tested under Mac OS X 10.9.5 and Manjaor Linux (Arch Linux) in Qt4
and Qt5 configuration, and tested Qt5 Linux binary from their website
on Arch Linux with the qt variable set in config.py.
Change-Id: I2e19ab4aa7a26fdd989e2a12faa51a0f3f89c3ce
-rw-r--r-- | BuildTools/SCons/Tools/qt4.py | 75 | ||||
-rw-r--r-- | Slimber/Qt/SConscript | 10 | ||||
-rw-r--r-- | Swift/QtUI/QtCertificateViewerDialog.cpp | 29 | ||||
-rw-r--r-- | Swift/QtUI/QtUtilities.cpp | 9 | ||||
-rw-r--r-- | Swift/QtUI/SConscript | 2 |
5 files changed, 94 insertions, 31 deletions
diff --git a/BuildTools/SCons/Tools/qt4.py b/BuildTools/SCons/Tools/qt4.py index ad4f1c0..ea86223 100644 --- a/BuildTools/SCons/Tools/qt4.py +++ b/BuildTools/SCons/Tools/qt4.py @@ -197,13 +197,17 @@ def _detect(env): try: return env['QTDIR'] except KeyError: pass try: return os.environ['QTDIR'] except KeyError: pass - moc = env.WhereIs('moc-qt4') or env.WhereIs('moc4') or env.WhereIs('moc') + moc = None + if env["qt5"]: + moc = env.WhereIs('moc-qt5') or env.WhereIs('moc5') or env.WhereIs('moc') + else : + moc = env.WhereIs('moc-qt4') or env.WhereIs('moc4') or env.WhereIs('moc') if moc: import sys if sys.platform == "darwin" : return "" QTDIR = os.path.dirname(os.path.dirname(moc)) SCons.Warnings.warn( @@ -219,20 +223,30 @@ def _detect(env): def generate(env): """Add Builders and construction variables for qt to an Environment.""" def locateQt4Command(env, command, qtdir) : if len(qtdir) == 0 : qtdir = "/usr" - suffixes = [ - '-qt4', - '-qt4.exe', - '4', - '4.exe', - '', - '.exe', - ] + if env["qt5"]: + suffixes = [ + '-qt5', + '-qt5.exe', + '5', + '5.exe', + '', + '.exe', + ] + else : + suffixes = [ + '-qt4', + '-qt4.exe', + '4', + '4.exe', + '', + '.exe', + ] triedPaths = [] for suffix in suffixes : fullpath = os.path.join(qtdir,'bin',command + suffix) if os.access(fullpath, os.X_OK) : return fullpath triedPaths.append(fullpath) @@ -423,12 +437,14 @@ def enable_modules(self, modules, debug=False, crosscompiling=False, version='4' # Qt5 modules 'QtWidgets', 'QtMultimedia', 'QtWebKitWidgets', ] + if sys.platform != "win32" and sys.platform != "darwin" and not crosscompiling : + validModules += ['QtX11Extras'] staticModules = [ 'QtUiTools', ] invalidModules=[] for module in modules: if module not in validModules : @@ -453,22 +469,43 @@ def enable_modules(self, modules, debug=False, crosscompiling=False, version='4' for module in modules : try : self.AppendUnique(CPPDEFINES=moduleDefines[module]) except: pass debugSuffix = '' if sys.platform != "win32" and sys.platform != "darwin" and not crosscompiling : - if debug : debugSuffix = '_debug' - if version == '4' : - self.AppendUnique(CPPPATH=[os.path.join("$QTDIR","include", "phonon")]) - for module in modules : - self.AppendUnique(LIBS=[module+debugSuffix]) - self.AppendUnique(LIBPATH=[os.path.join("$QTDIR","lib")]) - self.AppendUnique(CPPPATH=[os.path.join("$QTDIR","include")]) - self.AppendUnique(CPPPATH=[os.path.join("$QTDIR","include",module)]) - self["QT4_MOCCPPPATH"] = self["CPPPATH"] - return + if self["qt"]: + # The user specified qt path in config.py and we are going to use the + # installation under that location. + UsePkgConfig = False + else: + # The user did not specify a qt path in config py and we are going to + # ask pkg-config for the correct flags. + UsePkgConfig = True + if not UsePkgConfig: + if debug : debugSuffix = '_debug' + if version == '4' : + self.AppendUnique(CPPPATH=[os.path.join("$QTDIR","include", "phonon")]) + for module in modules : + module_str = module + if not version == '4' : + module_str = module_str.replace('Qt', 'Qt5') + self.AppendUnique(LIBS=[module_str+debugSuffix]) + self.AppendUnique(LIBPATH=[os.path.join("$QTDIR","lib")]) + self.AppendUnique(CPPPATH=[os.path.join("$QTDIR","include")]) + self.AppendUnique(CPPPATH=[os.path.join("$QTDIR","include",module)]) + self["QT4_MOCCPPPATH"] = self["CPPPATH"] + return + else: + test_env = self.Clone() + modules_str = " ".join(modules) + if not version == '4' : + modules_str = modules_str.replace('Qt', 'Qt5') + test_env.ParseConfig("pkg-config --cflags --libs " + modules_str) + self.AppendUnique(LIBS=test_env["LIBS"], LIBPATH=test_env["LIBPATH"], CPPPATH=test_env["CPPPATH"]) + self["QT4_MOCCPPPATH"] = self["CPPPATH"] + return if sys.platform == "win32" or crosscompiling : if crosscompiling: transformedQtdir = transformToWinePath(self['QTDIR']) self['QT4_MOC'] = "QTDIR=%s %s"%( transformedQtdir, self['QT4_MOC']) self.AppendUnique(CPPPATH=[os.path.join("$QTDIR","include")]) diff --git a/Slimber/Qt/SConscript b/Slimber/Qt/SConscript index b4f0bc3..7a18465 100644 --- a/Slimber/Qt/SConscript +++ b/Slimber/Qt/SConscript @@ -20,13 +20,21 @@ if myenv.get("HAVE_ICU") : if myenv.get("HAVE_LIBIDN") : myenv.MergeFlags(env["LIBIDN_FLAGS"]) myenv.Append(CPPDEFINES = ["HAVE_LIBIDN"]) myenv.Tool("qt4", toolpath = ["#/BuildTools/SCons/Tools"]) myenv.Tool("nsis", toolpath = ["#/BuildTools/SCons/Tools"]) -myenv.EnableQt4Modules(['QtCore', 'QtGui'], debug = False) + + +qt4modules = ['QtCore', 'QtGui'] +if myenv["qt5"] : + qt_version = '5' + qt4modules += ['QtWidgets'] +else : + qt_version = '4' +myenv.EnableQt4Modules(qt4modules, debug = False, version = qt_version) myenv.Append(CPPPATH = ["."]) if env["PLATFORM"] == "win32" : myenv.Append(LINKFLAGS = ["/SUBSYSTEM:WINDOWS"]) myenv.Append(LIBS = "qtmain") diff --git a/Swift/QtUI/QtCertificateViewerDialog.cpp b/Swift/QtUI/QtCertificateViewerDialog.cpp index 15a52ba..8108978 100644 --- a/Swift/QtUI/QtCertificateViewerDialog.cpp +++ b/Swift/QtUI/QtCertificateViewerDialog.cpp @@ -1,20 +1,28 @@ /* * Copyright (c) 2012 Tobias Markmann * Licensed under the simplified BSD license. * See Documentation/Licenses/BSD-simplified.txt for more information. */ +/* + * Copyright (c) 2015 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ + #include "QtCertificateViewerDialog.h" #include "ui_QtCertificateViewerDialog.h" #include <Swiften/Base/foreach.h> -#include <QTreeWidgetItem> -#include <QLabel> #include <QDateTime> +#include <QLabel> +#include <QString> +#include <QStringList> +#include <QTreeWidgetItem> namespace Swift { QtCertificateViewerDialog::QtCertificateViewerDialog(QWidget* parent) : QDialog(parent), ui(new Ui::QtCertificateViewerDialog) { ui->setupUi(this); connect(ui->certChainTreeWidget, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)), SLOT(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*))); @@ -45,13 +53,13 @@ void QtCertificateViewerDialog::setCertificateChain(const std::vector<Certificat root->setData(0, Qt::UserRole, QVariant(0)); root->setExpanded(true); ui->certChainTreeWidget->addTopLevelItem(root); if (currentChain.size() > 1) { QTreeWidgetItem* parent = root; for (int n = 1; n < currentChain.size(); n++) { - QTreeWidgetItem* link = new QTreeWidgetItem(parent, QStringList(QString("↳ ") + currentChain.at(n).subjectInfo(QSslCertificate::CommonName))); + QTreeWidgetItem* link = new QTreeWidgetItem(parent, QStringList(QString("↳ ") + (QStringList(currentChain.at(n).subjectInfo(QSslCertificate::CommonName)).join(", ")))); link->setExpanded(true); link->setData(0, Qt::UserRole, QVariant(n)); parent = link; } ui->certChainTreeWidget->setCurrentItem(parent); } else { @@ -71,13 +79,14 @@ void QtCertificateViewerDialog::currentItemChanged(QTreeWidgetItem* current, QTr #define ADD_SECTION( TITLE ) \ ui->certGridLayout->addWidget(new QLabel("<strong>" + TITLE + "</strong>"), rowCount++, 0, 1, 2); #define ADD_FIELD( TITLE, VALUE) \ ui->certGridLayout->addWidget(new QLabel(TITLE), rowCount, 0, 1, 1, Qt::AlignRight); \ - valueLabel = new QLabel(VALUE); \ + valueLabel = new QLabel(); \ + valueLabel->setText(QStringList(VALUE).join(", ")); \ valueLabel->setTextFormat(Qt::PlainText); \ valueLabel->setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard); \ ui->certGridLayout->addWidget(valueLabel, rowCount++, 1, 1, 1, Qt::AlignLeft); void QtCertificateViewerDialog::setCertificateDetails(const QSslCertificate& cert) { QLayoutItem* item; @@ -103,16 +112,22 @@ void QtCertificateViewerDialog::setCertificateDetails(const QSslCertificate& cer ADD_FIELD(tr("Common Name"), cert.subjectInfo(QSslCertificate::CommonName)); ADD_FIELD(tr("Locality"), cert.subjectInfo(QSslCertificate::LocalityName)); ADD_FIELD(tr("Organizational Unit"), cert.subjectInfo(QSslCertificate::OrganizationalUnitName)); ADD_FIELD(tr("Country"), cert.subjectInfo(QSslCertificate::CountryName)); ADD_FIELD(tr("State"), cert.subjectInfo(QSslCertificate::StateOrProvinceName)); - if (!cert.alternateSubjectNames().empty()) { +#if QT_VERSION < 0x050000 + QMultiMap<QSsl::AlternateNameEntryType, QString> altNames = cert.alternateSubjectNames(); +#define SANTYPE QSsl::AlternateNameEntryType +#else + QMultiMap<QSsl::AlternativeNameEntryType, QString> altNames = cert.subjectAlternativeNames(); +#define SANTYPE QSsl::AlternativeNameEntryType +#endif + if (!altNames.empty()) { ADD_SECTION(tr("Alternate Subject Names")); - QMultiMap<QSsl::AlternateNameEntryType, QString> altNames = cert.alternateSubjectNames(); - foreach (const QSsl::AlternateNameEntryType &type, altNames.uniqueKeys()) { + foreach (const SANTYPE &type, altNames.uniqueKeys()) { foreach (QString name, altNames.values(type)) { if (type == QSsl::EmailEntry) { ADD_FIELD(tr("E-mail Address"), name); } else { ADD_FIELD(tr("DNS Name"), name); } diff --git a/Swift/QtUI/QtUtilities.cpp b/Swift/QtUI/QtUtilities.cpp index 70686e7..b4b1b09 100644 --- a/Swift/QtUI/QtUtilities.cpp +++ b/Swift/QtUI/QtUtilities.cpp @@ -1,29 +1,30 @@ /* - * Copyright (c) 2010-2013 Isode Limited. + * Copyright (c) 2010-2015 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include "QtUtilities.h" -#include <QTextDocument> -#include <QWidget> +#include <QtGui> #if defined (Q_OS_UNIX) && !defined(Q_OS_MAC) #include <QX11Info> #include <X11/Xlib.h> #include <X11/Xutil.h> #endif +#include <QTextDocument> +#include <QWidget> #include "Swift/Controllers/ApplicationInfo.h" namespace QtUtilities { void setX11Resource(QWidget* widget, const QString& c) { -#if defined (Q_OS_UNIX) && !defined(Q_OS_MAC) +#if defined (Q_OS_UNIX) && !defined(Q_OS_MAC) && QT_VERSION < 0x050000 char res_class[] = SWIFT_APPLICATION_NAME; XClassHint hint; QByteArray resName = (QString(SWIFT_APPLICATION_NAME) + "-" + c).toUtf8(); hint.res_name = resName.data(); hint.res_class = res_class; XSetClassHint(widget->x11Info().display(), widget->winId(), &hint); diff --git a/Swift/QtUI/SConscript b/Swift/QtUI/SConscript index f3251d2..86b41d3 100644 --- a/Swift/QtUI/SConscript +++ b/Swift/QtUI/SConscript @@ -58,12 +58,14 @@ myenv.Tool("nsis", toolpath = ["#/BuildTools/SCons/Tools"]) myenv.Tool("wix", toolpath = ["#/BuildTools/SCons/Tools"]) myenv.Tool("textfile", toolpath = ["#/BuildTools/SCons/Tools"]) qt4modules = ['QtCore', 'QtWebKit', 'QtGui'] if myenv["qt5"] : qt_version = '5' qt4modules += ['QtWidgets', 'QtWebKitWidgets', 'QtMultimedia'] + if env["PLATFORM"] != "win32" and env["PLATFORM"] != "darwin" : + qt4modules += ['QtX11Extras'] else : qt_version = '4' if env["PLATFORM"] == "posix" : qt4modules += ["QtDBus"] if env["PLATFORM"] != "win32" and env["PLATFORM"] != "darwin" : qt4modules += ["QtNetwork"] |