Skip to content

Commit ef9dd06

Browse files
committedMay 7, 2021
Add cmake flag to optionally disable spatialite support
If turned off, disables the spatialite, wfs, virtual providers and the offline editing plugin as a result. Intended for development purposes only, as the spatialite linkage can be problematic when building against non-system proj/gdal versions
1 parent 3248cc5 commit ef9dd06

File tree

10 files changed

+106
-12
lines changed

10 files changed

+106
-12
lines changed
 

‎CMakeLists.txt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,11 @@ if(WITH_CORE)
233233
set (POSTGRESQL_PREFIX "" CACHE PATH "Path to POSTGRESQL base directory")
234234
endif()
235235

236-
set (WITH_QSPATIALITE FALSE CACHE BOOL "Determines whether QSPATIALITE sql driver should be built")
236+
# try to configure and build POSTGRESQL support
237+
set (WITH_SPATIALITE TRUE CACHE BOOL "Determines whether Spatialite support should be built (required for spatialite, virtual, wfs providers)")
238+
if (WITH_SPATIALITE)
239+
set (WITH_QSPATIALITE FALSE CACHE BOOL "Determines whether QSPATIALITE sql driver should be built")
240+
endif()
237241

238242
set (WITH_ORACLE FALSE CACHE BOOL "Determines whether Oracle support should be built")
239243
if(WITH_ORACLE)
@@ -390,7 +394,10 @@ if(WITH_CORE)
390394
find_package(Poly2Tri REQUIRED)
391395
endif()
392396

393-
find_package(SpatiaLite REQUIRED)
397+
if (WITH_SPATIALITE)
398+
find_package(SpatiaLite REQUIRED)
399+
set (HAVE_SPATIALITE TRUE)
400+
endif()
394401

395402
if (NOT PROJ_FOUND OR NOT GEOS_FOUND OR NOT GDAL_FOUND)
396403
message (SEND_ERROR "Some dependencies were not found! Proj: ${PROJ_FOUND}, Geos: ${GEOS_FOUND}, GDAL: ${GDAL_FOUND}")

‎cmake_templates/qgsconfig.h.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@
5757

5858
#cmakedefine HAVE_GUI
5959

60+
#cmakedefine HAVE_SPATIALITE
61+
6062
#cmakedefine HAVE_POSTGRESQL
6163

6264
#cmakedefine HAVE_ORACLE

‎src/app/CMakeLists.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,15 +226,20 @@ set(QGIS_APP_SRCS
226226
pluginmanager/qgspluginsortfilterproxymodel.cpp
227227
pluginmanager/qgspluginitemdelegate.cpp
228228

229-
qgsnewspatialitelayerdialog.cpp
230-
231229
qgssettingstree.cpp
232230
qgsvariantdelegate.cpp
233231
qgscrashhandler.cpp
234232

235233
mesh/qgsmeshcalculatordialog.cpp
236234
)
237235

236+
if (WITH_SPATIALITE)
237+
set(QGIS_APP_SRCS
238+
${QGIS_APP_SRCS}
239+
qgsnewspatialitelayerdialog.cpp
240+
)
241+
endif()
242+
238243
if (WITH_GEOREFERENCER)
239244
set(QGIS_APP_SRCS
240245
${QGIS_APP_SRCS}

‎src/app/qgisapp.cpp

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -472,11 +472,14 @@ Q_GUI_EXPORT extern int qt_defaultDpiX();
472472

473473
#include <sqlite3.h>
474474

475+
#ifdef HAVE_SPATIALITE
475476
extern "C"
476477
{
477478
#include <spatialite.h>
478479
}
479480
#include "qgsnewspatialitelayerdialog.h"
481+
#endif
482+
480483
#include "qgsnewgeopackagelayerdialog.h"
481484

482485
#ifdef WITH_BINDINGS
@@ -2648,7 +2651,9 @@ void QgisApp::createActions()
26482651

26492652
connect( mActionDataSourceManager, &QAction::triggered, this, [ = ]() { dataSourceManager(); } );
26502653
connect( mActionNewVectorLayer, &QAction::triggered, this, &QgisApp::newVectorLayer );
2654+
#ifdef HAVE_SPATIALITE
26512655
connect( mActionNewSpatiaLiteLayer, &QAction::triggered, this, &QgisApp::newSpatialiteLayer );
2656+
#endif
26522657
connect( mActionNewGeoPackageLayer, &QAction::triggered, this, &QgisApp::newGeoPackageLayer );
26532658
connect( mActionNewMemoryLayer, &QAction::triggered, this, &QgisApp::newMemoryLayer );
26542659
connect( mActionNewVirtualLayer, &QAction::triggered, this, &QgisApp::addVirtualLayer );
@@ -2661,7 +2666,9 @@ void QgisApp::createActions()
26612666
connect( mActionAddRasterLayer, &QAction::triggered, this, [ = ] { dataSourceManager( QStringLiteral( "gdal" ) ); } );
26622667
connect( mActionAddMeshLayer, &QAction::triggered, this, [ = ] { dataSourceManager( QStringLiteral( "mdal" ) ); } );
26632668
connect( mActionAddPgLayer, &QAction::triggered, this, [ = ] { dataSourceManager( QStringLiteral( "postgres" ) ); } );
2669+
#ifdef HAVE_SPATIALITE
26642670
connect( mActionAddSpatiaLiteLayer, &QAction::triggered, this, [ = ] { dataSourceManager( QStringLiteral( "spatialite" ) ); } );
2671+
#endif
26652672
connect( mActionAddMssqlLayer, &QAction::triggered, this, [ = ] { dataSourceManager( QStringLiteral( "mssql" ) ); } );
26662673
connect( mActionAddDb2Layer, &QAction::triggered, this, [ = ] { dataSourceManager( QStringLiteral( "DB2" ) ); } );
26672674
connect( mActionAddOracleLayer, &QAction::triggered, this, [ = ] { dataSourceManager( QStringLiteral( "oracle" ) ); } );
@@ -2671,7 +2678,9 @@ void QgisApp::createActions()
26712678
connect( mActionAddVectorTileLayer, &QAction::triggered, this, [ = ] { dataSourceManager( QStringLiteral( "vectortile" ) ); } );
26722679
connect( mActionAddPointCloudLayer, &QAction::triggered, this, [ = ] { dataSourceManager( QStringLiteral( "ept" ) ); } );
26732680
connect( mActionAddWcsLayer, &QAction::triggered, this, [ = ] { dataSourceManager( QStringLiteral( "wcs" ) ); } );
2681+
#ifdef HAVE_SPATIALITE
26742682
connect( mActionAddWfsLayer, &QAction::triggered, this, [ = ] { dataSourceManager( QStringLiteral( "WFS" ) ); } );
2683+
#endif
26752684
connect( mActionAddAfsLayer, &QAction::triggered, this, [ = ] { dataSourceManager( QStringLiteral( "arcgisfeatureserver" ) ); } );
26762685
connect( mActionAddDelimitedText, &QAction::triggered, this, [ = ] { dataSourceManager( QStringLiteral( "delimitedtext" ) ); } );
26772686
connect( mActionAddVirtualLayer, &QAction::triggered, this, [ = ] { dataSourceManager( QStringLiteral( "virtual" ) ); } );
@@ -3428,7 +3437,9 @@ void QgisApp::createToolBars()
34283437
bt = new QToolButton();
34293438
bt->setPopupMode( QToolButton::MenuButtonPopup );
34303439
bt->addAction( mActionNewVectorLayer );
3440+
#ifdef HAVE_SPATIALITE
34313441
bt->addAction( mActionNewSpatiaLiteLayer );
3442+
#endif
34323443
bt->addAction( mActionNewGeoPackageLayer );
34333444
bt->addAction( mActionNewMemoryLayer );
34343445

@@ -3929,8 +3940,10 @@ void QgisApp::setTheme( const QString &themeName )
39293940
#ifdef HAVE_POSTGRESQL
39303941
mActionAddPgLayer->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddPostgisLayer.svg" ) ) );
39313942
#endif
3943+
#ifdef HAVE_SPATIALITE
39323944
mActionNewSpatiaLiteLayer->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionNewSpatiaLiteLayer.svg" ) ) );
39333945
mActionAddSpatiaLiteLayer->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddSpatiaLiteLayer.svg" ) ) );
3946+
#endif
39343947
mActionAddMssqlLayer->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddMssqlLayer.svg" ) ) );
39353948
mActionAddDb2Layer->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddDb2Layer.svg" ) ) );
39363949
#ifdef HAVE_ORACLE
@@ -4052,7 +4065,9 @@ void QgisApp::setTheme( const QString &themeName )
40524065
mActionAddXyzLayer->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddXyzLayer.svg" ) ) );
40534066
mActionAddVectorTileLayer->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddVectorTileLayer.svg" ) ) );
40544067
mActionAddWcsLayer->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddWcsLayer.svg" ) ) );
4068+
#ifdef HAVE_SPATIALITE
40554069
mActionAddWfsLayer->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddWfsLayer.svg" ) ) );
4070+
#endif
40564071
mActionAddAfsLayer->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddAfsLayer.svg" ) ) );
40574072
mActionAddToOverview->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionInOverview.svg" ) ) );
40584073
mActionAnnotation->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionAnnotation.svg" ) ) );
@@ -5279,8 +5294,13 @@ void QgisApp::about()
52795294
versionString += QStringLiteral( "</td></tr><tr>" );
52805295

52815296
// spatialite
5282-
versionString += QStringLiteral( "<td>%1</td><td colspan=\"3\">%2</td>" ).arg( tr( "SpatiaLite version" ), spatialite_version() );
5283-
versionString += QLatin1String( "</tr><tr>" );
5297+
versionString += QStringLiteral( "<td>%1</td><td colspan=\"3\">" ).arg( tr( "SpatiaLite version" ) );
5298+
#ifdef HAVE_SPATIALITE
5299+
versionString += QStringLiteral( "%1</td>" ).arg( spatialite_version() );
5300+
#else
5301+
versionString += tr( "No support" );
5302+
#endif
5303+
versionString += QStringLiteral( "</td></tr><tr>" );
52845304

52855305
// QWT
52865306
versionString += QStringLiteral( "<td>%1</td><td colspan=\"3\">%2</td>" ).arg( tr( "QWT version" ), QWT_VERSION_STR );
@@ -6732,11 +6752,13 @@ void QgisApp::newMemoryLayer()
67326752
}
67336753
}
67346754

6755+
#ifdef HAVE_SPATIALITE
67356756
void QgisApp::newSpatialiteLayer()
67366757
{
67376758
QgsNewSpatialiteLayerDialog spatialiteDialog( this, QgsGuiUtils::ModalDialogFlags, QgsProject::instance()->defaultCrsForNewLayers() );
67386759
spatialiteDialog.exec();
67396760
}
6761+
#endif
67406762

67416763
void QgisApp::newGeoPackageLayer()
67426764
{

‎src/app/qgisapp.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,18 +539,30 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
539539

540540
QAction *actionDataSourceManager() { return mActionDataSourceManager; }
541541
QAction *actionNewVectorLayer() { return mActionNewVectorLayer; }
542+
#ifdef HAVE_SPATIALITE
542543
QAction *actionNewSpatialLiteLayer() { return mActionNewSpatiaLiteLayer; }
544+
#else
545+
QAction *actionNewSpatialLiteLayer() { return nullptr; }
546+
#endif
543547
QAction *actionEmbedLayers() { return mActionEmbedLayers; }
544548
QAction *actionAddOgrLayer() { return mActionAddOgrLayer; }
545549
QAction *actionAddRasterLayer() { return mActionAddRasterLayer; }
546550
QAction *actionAddPgLayer() { return mActionAddPgLayer; }
551+
#ifdef HAVE_SPATIALITE
547552
QAction *actionAddSpatiaLiteLayer() { return mActionAddSpatiaLiteLayer; }
553+
#else
554+
QAction *actionAddSpatiaLiteLayer() { return nullptr; }
555+
#endif
548556
QAction *actionAddWmsLayer() { return mActionAddWmsLayer; }
549557
QAction *actionAddXyzLayer() { return mActionAddXyzLayer; }
550558
QAction *actionAddVectorTileLayer() { return mActionAddVectorTileLayer; }
551559
QAction *actionAddPointCloudLayer() { return mActionAddPointCloudLayer; }
552560
QAction *actionAddWcsLayer() { return mActionAddWcsLayer; }
561+
#ifdef HAVE_SPATIALITE
553562
QAction *actionAddWfsLayer() { return mActionAddWfsLayer; }
563+
#else
564+
QAction *actionAddWfsLayer() { return nullptr; }
565+
#endif
554566
QAction *actionAddAfsLayer() { return mActionAddAfsLayer; }
555567
QAction *actionCopyLayerStyle() { return mActionCopyStyle; }
556568
QAction *actionPasteLayerStyle() { return mActionPasteStyle; }
@@ -1561,8 +1573,10 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
15611573
void newVectorLayer();
15621574
//! Create a new memory layer
15631575
void newMemoryLayer();
1576+
#ifdef HAVE_SPATIALITE
15641577
//! Create a new empty SpatiaLite layer
15651578
void newSpatialiteLayer();
1579+
#endif
15661580
//! Create a new empty GeoPackage layer
15671581
void newGeoPackageLayer();
15681582

‎src/core/CMakeLists.txt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1774,14 +1774,19 @@ target_include_directories(qgis_core SYSTEM PUBLIC
17741774
${GEOS_INCLUDE_DIR}
17751775
${EXPAT_INCLUDE_DIR}
17761776
${SQLITE3_INCLUDE_DIR}
1777-
${SPATIALITE_INCLUDE_DIR}
17781777
${QCA_INCLUDE_DIR}
17791778
${QTKEYCHAIN_INCLUDE_DIR}
17801779
${${QT_VERSION_BASE}SerialPort_INCLUDE_DIRS}
17811780
${Protobuf_INCLUDE_DIRS}
17821781
${ZLIB_INCLUDE_DIRS}
17831782
)
17841783

1784+
if (WITH_SPATIALITE)
1785+
target_include_directories(qgis_core SYSTEM PUBLIC
1786+
${SPATIALITE_INCLUDE_DIR}
1787+
)
1788+
endif()
1789+
17851790
target_include_directories(qgis_core PUBLIC
17861791
${CMAKE_CURRENT_SOURCE_DIR}
17871792
${CMAKE_CURRENT_BINARY_DIR}
@@ -1941,12 +1946,15 @@ target_link_libraries(qgis_core
19411946
${SPATIALINDEX_LIBRARY}
19421947
${EXPAT_LIBRARY}
19431948
${SQLITE3_LIBRARY}
1944-
${SPATIALITE_LIBRARY}
19451949
${LIBZIP_LIBRARY}
19461950
${Protobuf_LITE_LIBRARY}
19471951
${ZLIB_LIBRARIES}
19481952
)
19491953

1954+
if (WITH_SPATIALITE)
1955+
target_link_libraries(qgis_core ${SPATIALITE_LIBRARY})
1956+
endif()
1957+
19501958
if (WITH_QT6)
19511959
target_link_libraries(qgis_core Qt6::Core5Compat)
19521960
endif()

‎src/core/qgsofflineediting.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,14 @@
5353
extern "C"
5454
{
5555
#include <sqlite3.h>
56+
}
57+
58+
#ifdef HAVE_SPATIALITE
59+
extern "C"
60+
{
5661
#include <spatialite.h>
5762
}
63+
#endif
5864

5965
#define CUSTOM_PROPERTY_IS_OFFLINE_EDITABLE "isOfflineEditable"
6066
#define CUSTOM_PROPERTY_REMOTE_SOURCE "remoteSource"
@@ -368,6 +374,7 @@ void QgsOfflineEditing::synchronize()
368374

369375
void QgsOfflineEditing::initializeSpatialMetadata( sqlite3 *sqlite_handle )
370376
{
377+
#ifdef HAVE_SPATIALITE
371378
// attempting to perform self-initialization for a newly created DB
372379
if ( !sqlite_handle )
373380
return;
@@ -425,6 +432,9 @@ void QgsOfflineEditing::initializeSpatialMetadata( sqlite3 *sqlite_handle )
425432
return;
426433
}
427434
spatial_ref_sys_init( sqlite_handle, 0 );
435+
#else
436+
( void )sqlite_handle;
437+
#endif
428438
}
429439

430440
bool QgsOfflineEditing::createOfflineDb( const QString &offlineDbPath, ContainerType containerType )
@@ -557,6 +567,7 @@ QgsVectorLayer *QgsOfflineEditing::copyVectorLayer( QgsVectorLayer *layer, sqlit
557567
{
558568
case SpatiaLite:
559569
{
570+
#ifdef HAVE_SPATIALITE
560571
// create table
561572
QString sql = QStringLiteral( "CREATE TABLE '%1' (" ).arg( tableName );
562573
QString delim;
@@ -669,7 +680,13 @@ QgsVectorLayer *QgsOfflineEditing::copyVectorLayer( QgsVectorLayer *layer, sqlit
669680
newLayer = new QgsVectorLayer( connectionString,
670681
layer->name() + layerNameSuffix, QStringLiteral( "spatialite" ), options );
671682
break;
683+
684+
#else
685+
showWarning( tr( "No Spatialite support available" ) );
686+
return nullptr;
687+
#endif
672688
}
689+
673690
case GPKG:
674691
{
675692
// Set options

‎src/core/qgsspatialiteutils.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@
2020
#include "qgslogger.h"
2121

2222
#include <sqlite3.h>
23+
24+
#ifdef HAVE_SPATIALITE
2325
#include <spatialite.h>
26+
#endif
2427

2528
// Define this variable to print all spatialite SQL statements
2629
#ifdef SPATIALITE_PRINT_ALL_SQL
@@ -40,15 +43,19 @@ static int trace_callback( unsigned, void *ctx, void *p, void * )
4043

4144
int spatialite_database_unique_ptr::open( const QString &path )
4245
{
46+
#ifdef HAVE_SPATIALITE
4347
auto &deleter = get_deleter();
4448
deleter.mSpatialiteContext = spatialite_alloc_connection();
49+
#endif
4550

4651
sqlite3 *database = nullptr;
4752
int result = sqlite3_open( path.toUtf8(), &database );
4853
std::unique_ptr< sqlite3, QgsSpatialiteCloser>::reset( database );
4954

55+
#ifdef HAVE_SPATIALITE
5056
if ( result == SQLITE_OK )
5157
spatialite_init_ex( database, deleter.mSpatialiteContext, 0 );
58+
#endif
5259

5360
return result;
5461
}
@@ -60,15 +67,19 @@ void spatialite_database_unique_ptr::reset()
6067

6168
int spatialite_database_unique_ptr::open_v2( const QString &path, int flags, const char *zVfs )
6269
{
70+
#ifdef HAVE_SPATIALITE
6371
auto &deleter = get_deleter();
6472
deleter.mSpatialiteContext = spatialite_alloc_connection();
73+
#endif
6574

6675
sqlite3 *database = nullptr;
6776
int result = sqlite3_open_v2( path.toUtf8(), &database, flags, zVfs );
6877
std::unique_ptr< sqlite3, QgsSpatialiteCloser>::reset( database );
6978

79+
#ifdef HAVE_SPATIALITE
7080
if ( result == SQLITE_OK )
7181
spatialite_init_ex( database, deleter.mSpatialiteContext, 0 );
82+
#endif
7283

7384
#ifdef SPATIALITE_PRINT_ALL_SQL
7485
// Log all queries
@@ -107,6 +118,8 @@ void QgsSpatialiteCloser::operator()( sqlite3 *handle )
107118
QgsDebugMsg( QStringLiteral( "sqlite3_close_v2() failed: %1" ).arg( res ) );
108119
}
109120

121+
#ifdef HAVE_SPATIALITE
110122
spatialite_cleanup_ex( mSpatialiteContext );
123+
#endif
111124
mSpatialiteContext = nullptr;
112125
}

‎src/plugins/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@ set (CMAKE_LIBRARY_OUTPUT_DIRECTORY ${QGIS_OUTPUT_DIRECTORY}/${QGIS_PLUGIN_SUBDI
88

99
add_subdirectory(gps_importer)
1010
add_subdirectory(topology)
11-
add_subdirectory(offline_editing)
1211
add_subdirectory(geometry_checker)
1312

13+
if (WITH_SPATIALITE)
14+
add_subdirectory(offline_editing)
15+
endif()
16+
1417
if (GRASS_FOUND)
1518
add_subdirectory(grass)
1619
endif()

‎src/providers/CMakeLists.txt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,15 @@ if (NOT FORCE_STATIC_PROVIDERS)
1616
add_subdirectory(ows)
1717
add_subdirectory(wcs)
1818
add_subdirectory(gpx)
19-
add_subdirectory(wfs)
20-
add_subdirectory(spatialite)
21-
add_subdirectory(virtual)
2219
add_subdirectory(db2)
2320
add_subdirectory(mdal)
2421

22+
if (WITH_SPATIALITE)
23+
add_subdirectory(spatialite)
24+
add_subdirectory(virtual)
25+
add_subdirectory(wfs)
26+
endif()
27+
2528
if (WITH_ORACLE)
2629
add_subdirectory(oracle)
2730
endif()

0 commit comments

Comments
 (0)
Please sign in to comment.