Skip to content

Commit bfdb3ec

Browse files
committed
Qt5SerialPort optional
1 parent 3b97096 commit bfdb3ec

File tree

6 files changed

+32
-6
lines changed

6 files changed

+32
-6
lines changed

CMakeLists.txt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,15 @@ IF(WITH_CORE)
316316
#############################################################
317317
# search for Qt5
318318
SET(QT_MIN_VERSION 5.9.0)
319+
320+
# Use Qt5SerialPort optionally for GPS
321+
SET (WITH_QT5SERIALPORT TRUE CACHE BOOL "Determines whether Qt5SerialPort should be tried for GPS positioning")
322+
IF (WITH_QT5SERIALPORT)
323+
FIND_PACKAGE(Qt5SerialPort REQUIRED)
324+
# following variable is used in qgsconfig.h
325+
SET (HAVE_QT5SERIALPORT TRUE)
326+
ENDIF(WITH_QT5SERIALPORT)
327+
319328
FIND_PACKAGE(Qt5Core QUIET)
320329
FIND_PACKAGE(Qt5Gui REQUIRED)
321330
FIND_PACKAGE(Qt5Widgets REQUIRED)
@@ -324,7 +333,6 @@ IF(WITH_CORE)
324333
FIND_PACKAGE(Qt5Svg REQUIRED)
325334
FIND_PACKAGE(Qt5Concurrent REQUIRED)
326335
FIND_PACKAGE(Qt5PrintSupport REQUIRED)
327-
FIND_PACKAGE(Qt5SerialPort REQUIRED)
328336
FIND_PACKAGE(Qt5Positioning)
329337
IF (WITH_QTWEBKIT)
330338
FIND_PACKAGE(Qt5WebKit REQUIRED)
@@ -352,7 +360,7 @@ IF(WITH_CORE)
352360
IF(${CMAKE_SYSTEM_NAME} MATCHES "Android")
353361
FIND_PACKAGE(Qt5AndroidExtras)
354362
ELSE(${CMAKE_SYSTEM_NAME} MATCHES "Android")
355-
FIND_PACKAGE(QtQmlTools REQUIRED)
363+
FIND_PACKAGE(QtQmlTools)
356364
ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "Android")
357365

358366
# following variable is used in qgsconfig.h

cmake_templates/qgsconfig.h.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,5 +69,7 @@
6969

7070
#cmakedefine HAVE_QUICK
7171

72+
#cmakedefine HAVE_QT5SERIALPORT
73+
7274
#endif
7375

src/core/CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1362,9 +1362,14 @@ TARGET_LINK_LIBRARIES(qgis_core
13621362
${SQLITE3_LIBRARY}
13631363
${SPATIALITE_LIBRARY}
13641364
${LIBZIP_LIBRARY}
1365-
Qt5::SerialPort
13661365
)
13671366

1367+
IF (Qt5SerialPort_FOUND)
1368+
TARGET_LINK_LIBRARIES(qgis_core
1369+
Qt5::SerialPort
1370+
)
1371+
ENDIF (Qt5SerialPort_FOUND)
1372+
13681373
IF (Qt5Positioning_FOUND)
13691374
TARGET_LINK_LIBRARIES(qgis_core
13701375
Qt5::Positioning

src/core/gps/qgsgpsconnection.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
#include <QIODevice>
2323
#include <QStringList>
2424
#include <QFileInfo>
25-
#include <QSerialPort>
26-
#include <QSerialPortInfo>
2725

2826
#include "qgsnmeaconnection.h"
2927
#include "qgslogger.h"

src/core/gps/qgsgpsdetector.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@
2929
#include <QStringList>
3030
#include <QFileInfo>
3131
#include <QTimer>
32+
33+
#if defined( HAVE_QT5SERIALPORT )
3234
#include <QSerialPortInfo>
35+
#include <QSerialPort>
36+
#endif
3337

3438
QList< QPair<QString, QString> > QgsGpsDetector::availablePorts()
3539
{
@@ -43,18 +47,24 @@ QList< QPair<QString, QString> > QgsGpsDetector::availablePorts()
4347
// try local gpsd first
4448
devs << QPair<QString, QString>( QStringLiteral( "localhost:2947:" ), tr( "local gpsd" ) );
4549

50+
// try serial ports
51+
#if defined( HAVE_QT5SERIALPORT )
4652
for ( auto p : QSerialPortInfo::availablePorts() )
4753
{
4854
devs << QPair<QString, QString>( p.portName(), tr( "%1: %2" ).arg( p.portName(), p.description() ) );
4955
}
56+
#endif
5057

5158
return devs;
5259
}
5360

5461
QgsGpsDetector::QgsGpsDetector( const QString &portName )
5562
{
5663
mConn = nullptr;
64+
65+
#if defined( HAVE_QT5SERIALPORT )
5766
mBaudList << QSerialPort::Baud4800 << QSerialPort::Baud9600 << QSerialPort::Baud38400 << QSerialPort::Baud57600 << QSerialPort::Baud115200; //add 57600 for SXBlueII GPS unit
67+
#endif
5868

5969
if ( portName.isEmpty() )
6070
{
@@ -116,6 +126,7 @@ void QgsGpsDetector::advance()
116126
}
117127
else
118128
{
129+
#if defined( HAVE_QT5SERIALPORT )
119130
QSerialPort *serial = new QSerialPort( mPortList.at( mPortIndex ).first );
120131

121132
serial->setBaudRate( mBaudList[ mBaudIndex ] );
@@ -132,6 +143,9 @@ void QgsGpsDetector::advance()
132143
{
133144
delete serial;
134145
}
146+
#else
147+
qWarning( "QT5SERIALPORT not found and mPortList matches serial port, this should never happen" );
148+
#endif
135149
}
136150
}
137151

src/core/gps/qgsgpsdetector.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#include <QObject>
2222
#include <QList>
2323
#include <QPair>
24-
#include <QSerialPort>
2524

2625
#include "qgis_core.h"
2726

0 commit comments

Comments
 (0)