From 48b4e0bf6f1cc4ce4831c2212d57f00fe792468f Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Wed, 20 Jul 2016 12:44:16 +0200 Subject: [PATCH] Improve library version handling Output the version as a define into the private config header as a define using a hex number. Like that we can easily do version checks on libraries using the QT_LIBRARY_VERSION(lib) and QT_VERSION_CHECK() macros. Change-Id: I6dc4ac6550886ca95c5542b6e75cd933ed079d76 Reviewed-by: Lars Knoll Reviewed-by: Oswald Buddenhagen --- configure.json | 1 + mkspecs/features/qt_configure.prf | 17 ++++++++++++++++- qtbase.pro | 1 + src/corelib/global/qglobal_p.h | 9 +++++++++ src/platformsupport/input/libinput/libinput.pri | 2 -- .../input/libinput/qlibinputpointer.cpp | 2 +- .../platforms/xcb/qxcbconnection_xi2.cpp | 9 ++++++--- src/plugins/platforms/xcb/xcb_qpa_lib.pro | 5 ----- sync.profile | 2 +- 9 files changed, 35 insertions(+), 13 deletions(-) diff --git a/configure.json b/configure.json index 004d7777fd..3ea5d19d61 100644 --- a/configure.json +++ b/configure.json @@ -1,6 +1,7 @@ { "files": { "publicHeader": "src/corelib/global/qconfig.h", + "privateHeader": "src/corelib/global/qconfig_p.h", "publicPro": "mkspecs/qconfig.pri", "privatePro": "mkspecs/qmodule.pri" }, diff --git a/mkspecs/features/qt_configure.prf b/mkspecs/features/qt_configure.prf index 880d71fab1..7d5814e4b1 100644 --- a/mkspecs/features/qt_configure.prf +++ b/mkspecs/features/qt_configure.prf @@ -515,6 +515,18 @@ defineReplace(qtConfLibraryArgs) { return($$qmake_args) } +defineReplace(qtConfGetHexVersion) { + version = $$split(1, '.') + number = + for(i, 0..2) { + n = $$member(version, $$i) + isEmpty(n): n = 0 + number += $$format_number($$n, obase=16 zeropad width=2) + } + number = "0x$$join(number)" + return($$number) +} + defineTest(qtConfExportLibrary) { isEmpty(2): return() !$$qtConfEvaluate($$eval($${1}.export)): return() @@ -524,7 +536,7 @@ defineTest(qtConfExportLibrary) { eval(libs = $$eval($${1}.libs)) eval(cflags = $$eval($${1}.cflags)) eval(includes = $$eval($${1}.includedir)) - version = $$split($${1}.version, '.') + version = $$eval($${1}.version) NAME = $$upper($$2) !isEmpty(libs): qtConfOutputVar(assign, $$output, QMAKE_LIBS_$$NAME, $$libs) @@ -534,6 +546,9 @@ defineTest(qtConfExportLibrary) { !isEmpty(cflags): qtConfOutputVar(assign, $$output, QMAKE_CFLAGS_$$NAME, $$cflags) !isEmpty(includes): qtConfOutputVar(assign, $$output, QMAKE_INCDIR_$$NAME, $$includes) !isEmpty(version) { + qtConfOutputVar(assign, $$output, QMAKE_$${NAME}_VERSION, $$version) + qtConfOutputSetDefine("privateHeader", "QT_LIBRARY_VERSION_$${2}", $$qtConfGetHexVersion($$version)) + version = $$split(version, '.') qtConfOutputVar(assign, $$output, QMAKE_$${NAME}_VERSION_MAJOR, $$member(version, 0)) qtConfOutputVar(assign, $$output, QMAKE_$${NAME}_VERSION_MINOR, $$member(version, 1)) qtConfOutputVar(assign, $$output, QMAKE_$${NAME}_VERSION_PATCH, $$member(version, 2)) diff --git a/qtbase.pro b/qtbase.pro index 481374b0da..fce2c9fa6c 100644 --- a/qtbase.pro +++ b/qtbase.pro @@ -31,6 +31,7 @@ QMAKE_DISTCLEAN += \ mkspecs/qhost.pri \ mkspecs/qmodule.pri \ src/corelib/global/qconfig.h \ + src/corelib/global/qconfig_p.h \ src/corelib/global/qconfig.cpp \ bin/qt.conf diff --git a/src/corelib/global/qglobal_p.h b/src/corelib/global/qglobal_p.h index e8d822b6c6..e75d87b384 100644 --- a/src/corelib/global/qglobal_p.h +++ b/src/corelib/global/qglobal_p.h @@ -48,5 +48,14 @@ #include "qglobal.h" #include "qglobal_p.h" // include self to avoid syncqt warning - no-op +#ifndef QT_BOOTSTRAPPED +#include +#endif + +#define QT_LIBRARY_VERSION(lib) QT_LIBRARY_VERSION_##lib +#define QT_LIBRARY_VERSION_MAJOR(lib) (QT_LIBRARY_VERSION_##lib >> 16) +#define QT_LIBRARY_VERSION_MINOR(lib) ((QT_LIBRARY_VERSION_##lib >> 8) & 0xff) +#define QT_LIBRARY_VERSION_PATCH(lib) (QT_LIBRARY_VERSION_##lib & 0xff) + #endif // QGLOBAL_P_H diff --git a/src/platformsupport/input/libinput/libinput.pri b/src/platformsupport/input/libinput/libinput.pri index 9595e15f4e..d9f64c7449 100644 --- a/src/platformsupport/input/libinput/libinput.pri +++ b/src/platformsupport/input/libinput/libinput.pri @@ -19,5 +19,3 @@ contains(QT_CONFIG, xkbcommon-evdev) { } else { DEFINES += QT_NO_XKBCOMMON_EVDEV } - -DEFINES += QT_LIBINPUT_VERSION_MAJOR=$$QMAKE_LIBINPUT_VERSION_MAJOR QT_LIBINPUT_VERSION_MINOR=$$QMAKE_LIBINPUT_VERSION_MINOR diff --git a/src/platformsupport/input/libinput/qlibinputpointer.cpp b/src/platformsupport/input/libinput/qlibinputpointer.cpp index d5a3a8b437..3b583ec99d 100644 --- a/src/platformsupport/input/libinput/qlibinputpointer.cpp +++ b/src/platformsupport/input/libinput/qlibinputpointer.cpp @@ -96,7 +96,7 @@ void QLibInputPointer::processMotion(libinput_event_pointer *e) void QLibInputPointer::processAxis(libinput_event_pointer *e) { -#if QT_LIBINPUT_VERSION_MAJOR == 0 && QT_LIBINPUT_VERSION_MINOR <= 7 +#if QT_LIBRARY_VERSION(libinput) < QT_VERSION_CHECK(0, 8, 0) const double v = libinput_event_pointer_get_axis_value(e) * 120; const Qt::Orientation ori = libinput_event_pointer_get_axis(e) == LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL ? Qt::Vertical : Qt::Horizontal; diff --git a/src/plugins/platforms/xcb/qxcbconnection_xi2.cpp b/src/plugins/platforms/xcb/qxcbconnection_xi2.cpp index 5b7f45fb6c..bda167bce9 100644 --- a/src/plugins/platforms/xcb/qxcbconnection_xi2.cpp +++ b/src/plugins/platforms/xcb/qxcbconnection_xi2.cpp @@ -697,7 +697,7 @@ void QXcbConnection::xi2ProcessTouch(void *xiDevEvent, QXcbWindow *platformWindo if (m_xiGrab) { // XIAllowTouchEvents deadlocks with libXi < 1.7.4 (this has nothing to do with the XI2 versions like 2.2) // http://lists.x.org/archives/xorg-devel/2014-July/043059.html -#ifndef LIBXI_MAJOR +#ifndef XCB_USE_XINPUT2 static bool allowTouchWarningShown = false; if (!allowTouchWarningShown) { allowTouchWarningShown = true; @@ -705,13 +705,16 @@ void QXcbConnection::xi2ProcessTouch(void *xiDevEvent, QXcbWindow *platformWindo " Minimum libXi version required is 1.7.4." " Expect issues with touch behavior."); } -#elif LIBXI_MAJOR == 1 && (LIBXI_MINOR < 7 || (LIBXI_MINOR == 7 && LIBXI_PATCH < 4)) +#elif QT_LIBRARY_VERSION(xinput2) < QT_VERSION_CHECK(1, 7, 4) static bool allowTouchWarningShown = false; if (!allowTouchWarningShown) { allowTouchWarningShown = true; qWarning("Skipping XIAllowTouchEvents() due to not having libXi >= 1.7.4." " libXi version at build time was %d.%d.%d." - " Expect issues with touch behavior.", LIBXI_MAJOR, LIBXI_MINOR, LIBXI_PATCH); + " Expect issues with touch behavior.", + QT_LIBRARY_VERSION_MAJOR(xinput2), + QT_LIBRARY_VERSION_MINOR(xinput2), + QT_LIBRARY_VERSION_PATCH(xinput2)); } #else XIAllowTouchEvents(static_cast(m_xlib_display), xiDeviceEvent->deviceid, diff --git a/src/plugins/platforms/xcb/xcb_qpa_lib.pro b/src/plugins/platforms/xcb/xcb_qpa_lib.pro index b81d38fab1..d2584ca291 100644 --- a/src/plugins/platforms/xcb/xcb_qpa_lib.pro +++ b/src/plugins/platforms/xcb/xcb_qpa_lib.pro @@ -48,11 +48,6 @@ contains(QT_CONFIG, xcb-xlib) { DEFINES += XCB_USE_XINPUT2 SOURCES += qxcbconnection_xi2.cpp QMAKE_USE += xinput2 - !isEmpty(QMAKE_XINPUT2_VERSION_MAJOR) { - DEFINES += LIBXI_MAJOR=$$QMAKE_XINPUT2_VERSION_MAJOR \ - LIBXI_MINOR=$$QMAKE_XINPUT2_VERSION_MINOR \ - LIBXI_PATCH=$$QMAKE_XINPUT2_VERSION_PATCH - } } } diff --git a/sync.profile b/sync.profile index 6e73a8ef98..0860c7692a 100644 --- a/sync.profile +++ b/sync.profile @@ -65,7 +65,7 @@ my @zlib_headers = ( "zconf.h", "zlib.h" ); @ignore_headers = ( @internal_zlib_headers ); @ignore_for_include_check = ( "qsystemdetection.h", "qcompilerdetection.h", "qprocessordetection.h", @zlib_headers, @angle_headers); @ignore_for_qt_begin_namespace_check = ( "qt_windows.h", @zlib_headers, @angle_headers); -%inject_headers = ( "$basedir/src/corelib/global" => [ "qconfig.h", "qfeatures.h" ] ); +%inject_headers = ( "$basedir/src/corelib/global" => [ "qconfig.h", "qconfig_p.h", "qfeatures.h" ] ); # Module dependencies. # Every module that is required to build this module should have one entry. # Each of the module version specifiers can take one of the following values: