From bfdb3ec4890e2a5b164c085d7fc52d7d881b132d Mon Sep 17 00:00:00 2001 From: Peter Petrik Date: Wed, 10 Oct 2018 18:05:45 +0200 Subject: [PATCH] Qt5SerialPort optional --- CMakeLists.txt | 12 ++++++++++-- cmake_templates/qgsconfig.h.in | 2 ++ src/core/CMakeLists.txt | 7 ++++++- src/core/gps/qgsgpsconnection.cpp | 2 -- src/core/gps/qgsgpsdetector.cpp | 14 ++++++++++++++ src/core/gps/qgsgpsdetector.h | 1 - 6 files changed, 32 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 804f3426ae0..ade8f5b730d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -316,6 +316,15 @@ IF(WITH_CORE) ############################################################# # search for Qt5 SET(QT_MIN_VERSION 5.9.0) + + # Use Qt5SerialPort optionally for GPS + SET (WITH_QT5SERIALPORT TRUE CACHE BOOL "Determines whether Qt5SerialPort should be tried for GPS positioning") + IF (WITH_QT5SERIALPORT) + FIND_PACKAGE(Qt5SerialPort REQUIRED) + # following variable is used in qgsconfig.h + SET (HAVE_QT5SERIALPORT TRUE) + ENDIF(WITH_QT5SERIALPORT) + FIND_PACKAGE(Qt5Core QUIET) FIND_PACKAGE(Qt5Gui REQUIRED) FIND_PACKAGE(Qt5Widgets REQUIRED) @@ -324,7 +333,6 @@ IF(WITH_CORE) FIND_PACKAGE(Qt5Svg REQUIRED) FIND_PACKAGE(Qt5Concurrent REQUIRED) FIND_PACKAGE(Qt5PrintSupport REQUIRED) - FIND_PACKAGE(Qt5SerialPort REQUIRED) FIND_PACKAGE(Qt5Positioning) IF (WITH_QTWEBKIT) FIND_PACKAGE(Qt5WebKit REQUIRED) @@ -352,7 +360,7 @@ IF(WITH_CORE) IF(${CMAKE_SYSTEM_NAME} MATCHES "Android") FIND_PACKAGE(Qt5AndroidExtras) ELSE(${CMAKE_SYSTEM_NAME} MATCHES "Android") - FIND_PACKAGE(QtQmlTools REQUIRED) + FIND_PACKAGE(QtQmlTools) ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "Android") # following variable is used in qgsconfig.h diff --git a/cmake_templates/qgsconfig.h.in b/cmake_templates/qgsconfig.h.in index e267d32e5af..80fc2468546 100644 --- a/cmake_templates/qgsconfig.h.in +++ b/cmake_templates/qgsconfig.h.in @@ -69,5 +69,7 @@ #cmakedefine HAVE_QUICK +#cmakedefine HAVE_QT5SERIALPORT + #endif diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index f39b3517f02..3926e33a50a 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -1362,9 +1362,14 @@ TARGET_LINK_LIBRARIES(qgis_core ${SQLITE3_LIBRARY} ${SPATIALITE_LIBRARY} ${LIBZIP_LIBRARY} - Qt5::SerialPort ) +IF (Qt5SerialPort_FOUND) + TARGET_LINK_LIBRARIES(qgis_core + Qt5::SerialPort + ) +ENDIF (Qt5SerialPort_FOUND) + IF (Qt5Positioning_FOUND) TARGET_LINK_LIBRARIES(qgis_core Qt5::Positioning diff --git a/src/core/gps/qgsgpsconnection.cpp b/src/core/gps/qgsgpsconnection.cpp index 4df4fd31520..8f46e4e73b8 100644 --- a/src/core/gps/qgsgpsconnection.cpp +++ b/src/core/gps/qgsgpsconnection.cpp @@ -22,8 +22,6 @@ #include #include #include -#include -#include #include "qgsnmeaconnection.h" #include "qgslogger.h" diff --git a/src/core/gps/qgsgpsdetector.cpp b/src/core/gps/qgsgpsdetector.cpp index 29f552bc7db..7e757de30f1 100644 --- a/src/core/gps/qgsgpsdetector.cpp +++ b/src/core/gps/qgsgpsdetector.cpp @@ -29,7 +29,11 @@ #include #include #include + +#if defined( HAVE_QT5SERIALPORT ) #include +#include +#endif QList< QPair > QgsGpsDetector::availablePorts() { @@ -43,10 +47,13 @@ QList< QPair > QgsGpsDetector::availablePorts() // try local gpsd first devs << QPair( QStringLiteral( "localhost:2947:" ), tr( "local gpsd" ) ); + // try serial ports +#if defined( HAVE_QT5SERIALPORT ) for ( auto p : QSerialPortInfo::availablePorts() ) { devs << QPair( p.portName(), tr( "%1: %2" ).arg( p.portName(), p.description() ) ); } +#endif return devs; } @@ -54,7 +61,10 @@ QList< QPair > QgsGpsDetector::availablePorts() QgsGpsDetector::QgsGpsDetector( const QString &portName ) { mConn = nullptr; + +#if defined( HAVE_QT5SERIALPORT ) mBaudList << QSerialPort::Baud4800 << QSerialPort::Baud9600 << QSerialPort::Baud38400 << QSerialPort::Baud57600 << QSerialPort::Baud115200; //add 57600 for SXBlueII GPS unit +#endif if ( portName.isEmpty() ) { @@ -116,6 +126,7 @@ void QgsGpsDetector::advance() } else { +#if defined( HAVE_QT5SERIALPORT ) QSerialPort *serial = new QSerialPort( mPortList.at( mPortIndex ).first ); serial->setBaudRate( mBaudList[ mBaudIndex ] ); @@ -132,6 +143,9 @@ void QgsGpsDetector::advance() { delete serial; } +#else + qWarning( "QT5SERIALPORT not found and mPortList matches serial port, this should never happen" ); +#endif } } diff --git a/src/core/gps/qgsgpsdetector.h b/src/core/gps/qgsgpsdetector.h index 0029522fcdf..7e8dd6fd4d7 100644 --- a/src/core/gps/qgsgpsdetector.h +++ b/src/core/gps/qgsgpsdetector.h @@ -21,7 +21,6 @@ #include #include #include -#include #include "qgis_core.h"