aports/testing/qgis/30-find-sqlite.patch
2025-01-19 21:37:56 +00:00

205 lines
7.2 KiB
Diff

From c06c7c938e08e68a25bc9b39c8b4347801bcc340 Mon Sep 17 00:00:00 2001
From: Simon Lopez <s.lopez@brgm.fr>
Date: Fri, 13 Sep 2024 12:57:00 +0200
Subject: [PATCH] Use CMake's SQLite targets
This uses the same targets and variables introduced in
the FindSQLite3 module in CMake starting with version 3.14.
The other CMakeFiles.txt are modified accordingly.
---
CMakeLists.txt | 9 +++----
cmake/FindSqlite3.cmake | 37 +++++++++++++++++++----------
external/qspatialite/CMakeLists.txt | 5 +---
python/CMakeLists.txt | 1 -
src/analysis/CMakeLists.txt | 1 -
src/core/CMakeLists.txt | 3 +--
src/providers/mdal/CMakeLists.txt | 4 ++--
src/quickgui/plugin/CMakeLists.txt | 1 -
tests/bench/CMakeLists.txt | 4 ----
9 files changed, 33 insertions(+), 32 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 096fb1a4fc78..13aefcfe5e78 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -368,10 +368,11 @@ if(WITH_CORE)
set (WITH_INTERNAL_NLOHMANN_JSON ON CACHE BOOL "Determines whether the vendored copy of nlohmann-json should be used")
find_package(nlohmann_json REQUIRED)
- find_package(Sqlite3)
- if (NOT SQLITE3_FOUND)
- message (SEND_ERROR "sqlite3 dependency was not found!")
- endif()
+ # The following bypasses the FindSQLite3 module introduced in CMake 3.14
+ # On case insensitive platforms (e.g. Windows) this is because
+ # ./cmake/FindSqlite3.cmake comes first on the CMAKE_MODULE_PATH
+ # (otherwise it is because of the case: *Sqlite3* vs. *SQLite3*)
+ find_package(Sqlite3 REQUIRED)
find_package(Protobuf CONFIG)
find_package(Protobuf REQUIRED)
diff --git a/cmake/FindSqlite3.cmake b/cmake/FindSqlite3.cmake
index 4b3c34b53cca..9b4f4a2f481e 100644
--- a/cmake/FindSqlite3.cmake
+++ b/cmake/FindSqlite3.cmake
@@ -11,13 +11,15 @@
# SQLITE3_INCLUDE_DIR
# SQLITE3_LIBRARY
-
-# FIND_PATH and FIND_LIBRARY normally search standard locations
-# before the specified paths. To search non-standard paths first,
-# FIND_* is invoked first with specified paths and NO_DEFAULT_PATH
-# and then again with no specified paths to search the default
-# locations. When an earlier FIND_* succeeds, subsequent FIND_*s
-# searching for the same item do nothing.
+# We ensure consistency between the target defined by this file
+# and the official CMake's FindSQLite3.cmake
+# https://cmake.org/cmake/help/latest/module/FindSQLite3.html
+if(SQLITE3_FOUND)
+ if(NOT SQLite3_FOUND OR NOT TARGET SQLite::SQLite3)
+ message(FATAL_ERROR "Unconsistency between SQLite3 dependencies")
+ endif()
+ return()
+endif()
# try to use framework on mac
# want clean framework path, not unix compatibility path
@@ -37,12 +39,6 @@ IF (APPLE AND NOT QGIS_MAC_DEPS_DIR)
ENDIF ()
ENDIF (APPLE AND NOT QGIS_MAC_DEPS_DIR)
-# FIND_PATH and FIND_LIBRARY normally search standard locations
-# before the specified paths. To search non-standard paths first,
-# FIND_* is invoked first with specified paths and NO_DEFAULT_PATH
-# and then again with no specified paths to search the default
-# locations. When an earlier FIND_* succeeds, subsequent FIND_*s
-# searching for the same item do nothing.
FIND_PATH(SQLITE3_INCLUDE_DIR sqlite3.h
"$ENV{LIB_DIR}/include"
"$ENV{LIB_DIR}/include/sqlite"
@@ -74,3 +70,18 @@ ELSE (SQLITE3_FOUND)
ENDIF (SQLITE3_FIND_REQUIRED)
ENDIF (SQLITE3_FOUND)
+
+# Create the imported target following the official CMake's FindSQLite3.cmake
+if(SQLITE3_FOUND)
+ set(SQLite3_FOUND TRUE)
+ set(SQLite3_INCLUDE_DIRS ${SQLITE3_INCLUDE_DIR})
+ set(SQLite3_LIBRARIES ${SQLITE3_LIBRARY})
+ if(NOT TARGET SQLite::SQLite3)
+ add_library(SQLite::SQLite3 UNKNOWN IMPORTED)
+ set_target_properties(SQLite::SQLite3 PROPERTIES
+ IMPORTED_LOCATION "${SQLITE3_LIBRARY}"
+ INTERFACE_INCLUDE_DIRECTORIES "${SQLITE3_INCLUDE_DIR}")
+ else()
+ message(FATAL_ERROR "SQLite::SQLite3 target should not have been defined at this point.")
+ endif()
+endif()
diff --git a/external/qspatialite/CMakeLists.txt b/external/qspatialite/CMakeLists.txt
index 527f383303c7..489a41f6cc33 100644
--- a/external/qspatialite/CMakeLists.txt
+++ b/external/qspatialite/CMakeLists.txt
@@ -6,7 +6,6 @@
add_definitions(-DQT_SHARED)
include_directories(SYSTEM
- ${SQLITE3_INCLUDE_DIR}
${Qt5Sql_PRIVATE_INCLUDE_DIRS}
)
diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt
index 2ea2b5078cba..c71d7f0453d1 100644
--- a/python/CMakeLists.txt
+++ b/python/CMakeLists.txt
@@ -77,7 +77,6 @@ include_directories(SYSTEM
${QWT_INCLUDE_DIR}
${QCA_INCLUDE_DIR}
${QTKEYCHAIN_INCLUDE_DIR}
- ${SQLITE3_INCLUDE_DIR}
${SPATIALINDEX_INCLUDE_DIR}
)
diff --git a/src/analysis/CMakeLists.txt b/src/analysis/CMakeLists.txt
index 86475bd4d53c..00bf1bc3f481 100644
--- a/src/analysis/CMakeLists.txt
+++ b/src/analysis/CMakeLists.txt
@@ -471,7 +471,6 @@ if (WITH_PDAL AND PDAL_2_5_OR_HIGHER)
endif()
include_directories(SYSTEM ${SPATIALINDEX_INCLUDE_DIR})
-include_directories(SYSTEM ${SQLITE3_INCLUDE_DIR})
include_directories(BEFORE raster)
include_directories(BEFORE mesh)
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt
index 2d16aa06efbb..b436b4537e07 100644
--- a/src/core/CMakeLists.txt
+++ b/src/core/CMakeLists.txt
@@ -2331,7 +2331,6 @@ target_include_directories(qgis_core SYSTEM PUBLIC
${${QT_VERSION_BASE}Concurrent_INCLUDE_DIRS}
${LIBZIP_INCLUDE_DIRS}
${SPATIALINDEX_INCLUDE_DIR} # before GEOS for case-insensitive filesystems
- ${SQLITE3_INCLUDE_DIR}
${QCA_INCLUDE_DIR}
${${QT_VERSION_BASE}SerialPort_INCLUDE_DIRS}
${Protobuf_INCLUDE_DIRS}
@@ -2512,7 +2511,7 @@ target_link_libraries(qgis_core
GDAL::GDAL
${SPATIALINDEX_LIBRARY}
EXPAT::EXPAT
- ${SQLITE3_LIBRARY}
+ SQLite::SQLite3
${LIBZIP_LIBRARY}
$<TARGET_NAME_IF_EXISTS:protobuf::libprotobuf-lite>
${ZLIB_LIBRARIES}
diff --git a/src/providers/mdal/CMakeLists.txt b/src/providers/mdal/CMakeLists.txt
index 906cb30db609..7b5f50e5a25c 100644
--- a/src/providers/mdal/CMakeLists.txt
+++ b/src/providers/mdal/CMakeLists.txt
@@ -90,11 +90,11 @@ if (WITH_INTERNAL_MDAL)
set (HAVE_HDF5 TRUE)
endif()
- if(SQLITE3_FOUND)
+ if(SQLite3_FOUND)
set(HAVE_SQLITE3 TRUE)
endif()
- if(SQLITE3_FOUND AND NETCDF_FOUND)
+ if(SQLite3_FOUND AND NETCDF_FOUND)
set(MDAL_LIB_SRCS ${MDAL_LIB_SRCS}
${CMAKE_SOURCE_DIR}/external/mdal/frmts/mdal_sqlite3.cpp
${CMAKE_SOURCE_DIR}/external/mdal/frmts/mdal_3di.cpp
diff --git a/src/quickgui/plugin/CMakeLists.txt b/src/quickgui/plugin/CMakeLists.txt
index 0060aca22ffc..9a9f37544f41 100644
--- a/src/quickgui/plugin/CMakeLists.txt
+++ b/src/quickgui/plugin/CMakeLists.txt
@@ -30,7 +30,6 @@ include_directories(
include_directories(SYSTEM
${LIBZIP_INCLUDE_DIRS}
${SPATIALINDEX_INCLUDE_DIR}
- ${SQLITE3_INCLUDE_DIR}
${QCA_INCLUDE_DIR}
${QTKEYCHAIN_INCLUDE_DIR}
)
diff --git a/tests/bench/CMakeLists.txt b/tests/bench/CMakeLists.txt
index 8a3d60a7ccef..481e449d9d7f 100644
--- a/tests/bench/CMakeLists.txt
+++ b/tests/bench/CMakeLists.txt
@@ -19,13 +19,9 @@ include_directories(
${CMAKE_BINARY_DIR}
)
-include_directories(SYSTEM
- ${SQLITE3_INCLUDE_DIR}
-)
target_link_libraries(qgis_bench
qgis_core
- ${SQLITE3_LIBRARY}
${QT_VERSION_BASE}::Core
${QT_VERSION_BASE}::Network
${QT_VERSION_BASE}::Svg