make mqtt optional if QT module not present

This commit is contained in:
Justin Hammond 2019-11-05 17:52:50 +08:00
parent 5078f38acc
commit ce0022e4d2
2 changed files with 87 additions and 72 deletions

View file

@ -6,9 +6,12 @@
#include <QCoreApplication>
#include <QLoggingCategory>
#include <QCommandLineParser>
#include "qtozwdaemon.h"
#include "mqttpublisher.h"
#include <qt-openzwave/qt-openzwavedatabase.h>
#include "qtozwdaemon.h"
#ifdef HAVE_MQTT
#include "mqttpublisher.h"
#warning "MQTT Enabled"
#endif
void handler(int sig) {
void *array[10];
@ -59,6 +62,7 @@ int main(int argc, char *argv[])
parser.addOption(userDir);
#ifdef HAVE_MQTT
QCommandLineOption MQTTServer(QStringList() << "mqtt-server",
"MQTT Server Hostname/IP Address",
"IP/Hostname"
@ -71,9 +75,8 @@ int main(int argc, char *argv[])
"Port"
);
parser.addOption(MQTTPort);
#endif
parser.process(a);
if (!parser.isSet(serialPort)) {
@ -83,12 +86,14 @@ int main(int argc, char *argv[])
exit(-1);
}
QSettings settings;
#ifdef HAVE_MQTT
if (parser.isSet(MQTTServer)) {
settings.setValue("MQTTServer", parser.value(MQTTServer));
}
if (parser.isSet(MQTTPort)) {
settings.setValue("MQTTPort", parser.value(MQTTPort).toInt());
}
#endif
#if 0
QLoggingCategory::setFilterRules("qt.remoteobjects.debug=true\n"
@ -161,8 +166,10 @@ int main(int argc, char *argv[])
qtozwdaemon daemon;
#ifdef HAVE_MQTT
mqttpublisher mqttpublisher;
mqttpublisher.setOZWDaemon(&daemon);
#endif
daemon.setSerialPort(parser.value(serialPort));
daemon.startOZW();
return a.exec();

View file

@ -1,6 +1,6 @@
QT -= gui
QT += remoteobjects mqtt
QT += remoteobjects
TARGET = ../ozwdaemon
@ -18,10 +18,10 @@ DEFINES += QT_DEPRECATED_WARNINGS
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
main.cpp \
mqttpublisher.cpp \
qtozwdaemon.cpp \
qtHaveModule(mqtt) {
QT += mqtt
DEFINES += HAVE_MQTT
SOURCES += mqttpublisher.cpp \
mqttcommands/mqttcommands.cpp \
mqttcommands/ping.cpp \
mqttcommands/open.cpp \
@ -54,15 +54,7 @@ SOURCES += \
mqttcommands/downloadLatestConfigFileRevision.cpp \
mqttcommands/downloadLatestMFSRevision.cpp
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
HEADERS += \
mqttpublisher.h \
qtozwdaemon.h \
HEADERS += mqttpublisher.h \
mqttcommands/mqttcommands.h \
mqttcommands/ping.h \
mqttcommands/open.h \
@ -94,6 +86,22 @@ HEADERS += \
mqttcommands/CheckLatestMFSRevision.h \
mqttcommands/downloadLatestConfigFileRevision.h \
mqttcommands/downloadLatestMFSRevision.h
} else {
warning("MQTT Qt Module Not Found. Not Building MQTT Client Capabilities")
}
SOURCES += main.cpp \
qtozwdaemon.cpp
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
HEADERS += \
qtozwdaemon.h \