Make it possible to disable Qt type pack handlers at build time

usable with either
  qmake DEFINES+=MSGPACK_NO_PACKTYPES
or
  DEFINES += MSGPACK_STATIC MSGPACK_NO_PACKTYPES
  include(path/to/qmsgpack/qmsgpack.pri)
This commit is contained in:
Konstantin Ritt
2018-11-20 20:57:25 +03:00
parent 34afb5aba3
commit 0b8282d592
4 changed files with 45 additions and 26 deletions

View File

@ -7,10 +7,7 @@ SOURCES += \
$$PWD/src/msgpackcommon.cpp \ $$PWD/src/msgpackcommon.cpp \
$$PWD/src/private/pack_p.cpp \ $$PWD/src/private/pack_p.cpp \
$$PWD/src/private/unpack_p.cpp \ $$PWD/src/private/unpack_p.cpp \
$$PWD/src/private/qt_types_p.cpp \ $$PWD/src/msgpackstream.cpp
$$PWD/src/msgpackstream.cpp \
$$PWD/src/stream/time.cpp \
$$PWD/src/stream/geometry.cpp
HEADERS += \ HEADERS += \
$$PWD/src/msgpack.h \ $$PWD/src/msgpack.h \
@ -19,18 +16,27 @@ HEADERS += \
$$PWD/src/endianhelper.h \ $$PWD/src/endianhelper.h \
$$PWD/src/msgpackcommon.h \ $$PWD/src/msgpackcommon.h \
$$PWD/src/msgpack_export.h \ $$PWD/src/msgpack_export.h \
$$PWD/src/msgpackstream.h
!contains(DEFINES, MSGPACK_NO_PACKTYPES) {
SOURCES += \
$$PWD/src/private/qt_types_p.cpp \
$$PWD/src/stream/time.cpp \
$$PWD/src/stream/geometry.cpp
HEADERS += \
$$PWD/src/private/qt_types_p.h \ $$PWD/src/private/qt_types_p.h \
$$PWD/src/msgpackstream.h \
$$PWD/src/stream/time.h \ $$PWD/src/stream/time.h \
$$PWD/src/stream/geometry.h $$PWD/src/stream/geometry.h
qtHaveModule(gui) { qtHaveModule(gui) {
QT += gui QT += gui
} }
qtHaveModule(location) { qtHaveModule(location) {
QT += location QT += location
SOURCES += $$PWD/src/stream/location.cpp SOURCES += $$PWD/src/stream/location.cpp
HEADERS += $$PWD/src/stream/location.h HEADERS += $$PWD/src/stream/location.h
}
} }

View File

@ -3,13 +3,16 @@
#include "msgpack.h" #include "msgpack.h"
#include "private/unpack_p.h" #include "private/unpack_p.h"
#include "private/pack_p.h" #include "private/pack_p.h"
#include "private/qt_types_p.h"
#include <QVector> #include <QVector>
#ifndef MSGPACK_NO_PACKTYPES
#include "private/qt_types_p.h"
#ifdef QT_LOCATION_LIB #ifdef QT_LOCATION_LIB
#include <QGeoCoordinate> #include <QGeoCoordinate>
#endif #endif
#endif // MSGPACK_NO_PACKTYPES
QVariant MsgPack::unpack(const QByteArray &data) QVariant MsgPack::unpack(const QByteArray &data)
{ {
@ -51,6 +54,7 @@ qint8 MsgPack::msgpackType(int qType)
bool MsgPack::registerType(QMetaType::Type qType, quint8 msgpackType) bool MsgPack::registerType(QMetaType::Type qType, quint8 msgpackType)
{ {
#ifndef MSGPACK_NO_PACKTYPES
switch (qType) { switch (qType) {
#ifdef QT_GUI_LIB #ifdef QT_GUI_LIB
case QMetaType::QColor: case QMetaType::QColor:
@ -92,6 +96,9 @@ bool MsgPack::registerType(QMetaType::Type qType, quint8 msgpackType)
#endif // QT_LOCATION_LIB #endif // QT_LOCATION_LIB
break; break;
} }
#else
Q_UNUSED(msgpackType)
#endif // MSGPACK_NO_PACKTYPES
qWarning("qmsgpack was built without metatype %d support.", int(qType)); qWarning("qmsgpack was built without metatype %d support.", int(qType));
qWarning("Use MsgPack::registerPacker() and MsgPack::registerUnpacker() to register metatype %d manually.", int(qType)); qWarning("Use MsgPack::registerPacker() and MsgPack::registerUnpacker() to register metatype %d manually.", int(qType));

View File

@ -18,12 +18,14 @@ HEADERS_INSTALL = \
msgpack_export.h \ msgpack_export.h \
msgpackstream.h \ msgpackstream.h \
STREAM_HEADERS_INSTALL = \ !contains(DEFINES, MSGPACK_NO_PACKTYPES) {
STREAM_HEADERS_INSTALL = \
stream/geometry.h \ stream/geometry.h \
stream/time.h stream/time.h
qtHaveModule(location) { qtHaveModule(location) {
STREAM_HEADERS_INSTALL += stream/location.h STREAM_HEADERS_INSTALL += stream/location.h
}
} }
unix { unix {

View File

@ -3,6 +3,10 @@ TEMPLATE = subdirs
SUBDIRS += \ SUBDIRS += \
pack \ pack \
unpack \ unpack \
mixed \ mixed
!contains(DEFINES, MSGPACK_NO_PACKTYPES) {
SUBDIRS += \
stream \ stream \
qttypes qttypes
}