Skip to content

Commit

Permalink
Use CMake's SQLite targets
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Simon-Lopez committed Sep 13, 2024
1 parent adc1224 commit c06c7c9
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 32 deletions.
9 changes: 5 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
37 changes: 24 additions & 13 deletions cmake/FindSqlite3.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand Down Expand Up @@ -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()
5 changes: 1 addition & 4 deletions external/qspatialite/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ add_definitions(${QT_DEFINITIONS})
add_definitions(-DQT_PLUGIN)
add_definitions(-DQT_SHARED)

include_directories(SYSTEM
${SQLITE3_INCLUDE_DIR}
${${QT_VERSION_BASE}Sql_PRIVATE_INCLUDE_DIRS}
)
include_directories(SYSTEM ${${QT_VERSION_BASE}Sql_PRIVATE_INCLUDE_DIRS})

set(QSQLSPATIALITE_SRC qsql_spatialite.cpp smain.cpp qsql_spatialite.h smain.h)

Expand Down
1 change: 0 additions & 1 deletion python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ include_directories(SYSTEM
${QWT_INCLUDE_DIR}
${QCA_INCLUDE_DIR}
${QTKEYCHAIN_INCLUDE_DIR}
${SQLITE3_INCLUDE_DIR}
${SPATIALINDEX_INCLUDE_DIR}
)

Expand Down
1 change: 0 additions & 1 deletion src/analysis/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
3 changes: 1 addition & 2 deletions src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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}
Expand Down
4 changes: 2 additions & 2 deletions src/providers/mdal/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/quickgui/plugin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ include_directories(
include_directories(SYSTEM
${LIBZIP_INCLUDE_DIRS}
${SPATIALINDEX_INCLUDE_DIR}
${SQLITE3_INCLUDE_DIR}
${QCA_INCLUDE_DIR}
${QTKEYCHAIN_INCLUDE_DIR}
)
Expand Down
4 changes: 0 additions & 4 deletions tests/bench/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c06c7c9

Please sign in to comment.