From 8e3dd24cac3b02ed648253edd47a2d8df276e501 Mon Sep 17 00:00:00 2001 From: Mike Taves Date: Wed, 17 Jan 2024 20:54:34 +1300 Subject: [PATCH] CMake: Replace custom FindSqlite3 with FindSQLite3 built-in --- CMakeLists.txt | 17 +++++--- cmake/FindSqlite3.cmake | 88 ---------------------------------------- docs/source/install.rst | 26 ++++++------ test/unit/CMakeLists.txt | 10 ++--- 4 files changed, 29 insertions(+), 112 deletions(-) delete mode 100644 cmake/FindSqlite3.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 45bd855bd8..d18d8dc5ee 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -176,15 +176,22 @@ if(NOT EXE_SQLITE3) message(SEND_ERROR "sqlite3 binary not found!") endif() -find_package(Sqlite3 REQUIRED) -if(NOT SQLITE3_FOUND) - message(SEND_ERROR "sqlite3 dependency not found!") +# Deprecated variables since PROJ 9.4.0 +if(DEFINED SQLITE3_INCLUDE_DIR) + message(DEPRECATION "Use SQLite3_INCLUDE_DIR instead of SQLITE3_INCLUDE_DIR") + set(SQLite3_INCLUDE_DIR ${SQLITE3_INCLUDE_DIR}) endif() +if(DEFINED SQLITE3_LIBRARY) + message(DEPRECATION "Use SQLite3_LIBRARY instead of SQLITE3_LIBRARY") + set(SQLite3_LIBRARY ${SQLITE3_LIBRARY}) +endif() + +find_package(SQLite3 REQUIRED) # Would build and run with older versions, but with horrible performance # See https://github.com/OSGeo/PROJ/issues/1718 -if("${SQLITE3_VERSION}" VERSION_LESS "3.11") - message(SEND_ERROR "sqlite3 >= 3.11 required!") +if(SQLite3_VERSION VERSION_LESS "3.11") + message(SEND_ERROR "SQLite3 >= 3.11 required!") endif() ################################################################################ diff --git a/cmake/FindSqlite3.cmake b/cmake/FindSqlite3.cmake deleted file mode 100644 index 31d1ca3cc1..0000000000 --- a/cmake/FindSqlite3.cmake +++ /dev/null @@ -1,88 +0,0 @@ -# Find Sqlite3 -# ~~~~~~~~~~~~ -# Copyright (c) 2007, Martin Dobias -# Redistribution and use is allowed according to the terms of the BSD license. -# For details see the accompanying COPYING-CMAKE-SCRIPTS file. -# -# CMake module to search for Sqlite3 library -# -# If it's found it sets SQLITE3_FOUND to TRUE -# and following variables are set: -# SQLITE3_INCLUDE_DIR -# SQLITE3_LIBRARY -# SQLITE3_VERSION - - -# 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. - -# try to use framework on mac -# want clean framework path, not unix compatibility path -if(APPLE) - if(CMAKE_FIND_FRAMEWORK MATCHES "FIRST" - OR CMAKE_FRAMEWORK_PATH MATCHES "ONLY" - OR NOT CMAKE_FIND_FRAMEWORK) - set(CMAKE_FIND_FRAMEWORK_save ${CMAKE_FIND_FRAMEWORK} CACHE STRING "" FORCE) - set(CMAKE_FIND_FRAMEWORK "ONLY" CACHE STRING "" FORCE) - #find_path(SQLITE3_INCLUDE_DIR SQLite3/sqlite3.h) - find_library(SQLITE3_LIBRARY SQLite3) - if(SQLITE3_LIBRARY) - # find_path doesn't add "Headers" for a framework - set(SQLITE3_INCLUDE_DIR ${SQLITE3_LIBRARY}/Headers - CACHE PATH "Path to a file.") - endif() - set(CMAKE_FIND_FRAMEWORK ${CMAKE_FIND_FRAMEWORK_save} CACHE STRING "" FORCE) - endif() -endif() - -find_path(SQLITE3_INCLUDE_DIR sqlite3.h - "$ENV{LIB_DIR}/include" - "$ENV{LIB_DIR}/include/sqlite" - "$ENV{INCLUDE}" -) - -find_library(SQLITE3_LIBRARY NAMES sqlite3_i sqlite3 PATHS - "$ENV{LIB_DIR}/lib" - "$ENV{LIB}/lib" -) - -if(SQLITE3_INCLUDE_DIR AND SQLITE3_LIBRARY) - set(SQLITE3_FOUND TRUE) -endif() - -# Extract version information from the header file -if(SQLITE3_INCLUDE_DIR) - file(STRINGS ${SQLITE3_INCLUDE_DIR}/sqlite3.h _ver_line - REGEX "^#define SQLITE_VERSION *\"[0-9]+\\.[0-9]+\\.[0-9]+\"" - LIMIT_COUNT 1) - string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" - SQLITE3_VERSION "${_ver_line}") - unset(_ver_line) -endif() - - -if(SQLITE3_FOUND) - - 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}") - endif() - - if(NOT SQLITE3_FIND_QUIETLY) - message(STATUS "Found Sqlite3: ${SQLITE3_LIBRARY}") - message(STATUS "Sqlite3 version: ${SQLITE3_VERSION}") - endif() - -else() - - if(SQLITE3_FIND_REQUIRED) - message(FATAL_ERROR "Could not find Sqlite3") - endif() - -endif() diff --git a/docs/source/install.rst b/docs/source/install.rst index 9613705ade..3eec8a8903 100644 --- a/docs/source/install.rst +++ b/docs/source/install.rst @@ -173,12 +173,8 @@ On Windows, one may need to specify generator:: cmake -G "Visual Studio 15 2017" .. -If the SQLite3 dependency is installed in a custom location, specify the -paths to the include directory and the library:: - - cmake -DSQLITE3_INCLUDE_DIR=/opt/SQLite/include -DSQLITE3_LIBRARY=/opt/SQLite/lib/libsqlite3.so .. - -Alternatively, the custom prefix for SQLite3 can be specified:: +If the SQLite3 dependency is installed in a custom location, specify +:option:`CMAKE_PREFIX_PATH`:: cmake -DCMAKE_PREFIX_PATH=/opt/SQLite .. @@ -315,6 +311,12 @@ All cached entries can be viewed using ``cmake -LAH`` from a build directory. :envvar:`OSGEO4W_ROOT` (if set), otherwise is ``c:/OSGeo4W``. Default for Unix-like is ``/usr/local/``. +.. option:: CMAKE_PREFIX_PATH + + `CMake variable + `_ + used to specify installation prefixes for SQLite3 and other dependencies. + .. option:: CMAKE_UNITY_BUILD=OFF .. versionadded:: 9.4 @@ -341,14 +343,10 @@ All cached entries can be viewed using ``cmake -LAH`` from a build directory. Path to an ``sqlite3`` or ``sqlite3.exe`` executable. -.. option:: SQLITE3_INCLUDE_DIR - - Path to an include directory with the ``sqlite3.h`` header file. - -.. option:: SQLITE3_LIBRARY - - Path to a shared or static library file, such as ``sqlite3.dll``, - ``libsqlite3.so``, ``sqlite3.lib`` or other name. +.. deprecated:: 9.4.0 + ``SQLITE3_INCLUDE_DIR`` and ``SQLITE3_LIBRARY`` should be replaced with + ``SQLite3_INCLUDE_DIR`` and ``SQLite3_LIBRARY``, respectively. + Users may also consider :option:`CMAKE_PREFIX_PATH` instead. .. option:: ENABLE_CURL=ON diff --git a/test/unit/CMakeLists.txt b/test/unit/CMakeLists.txt index c07be1b76e..17a6b79daf 100644 --- a/test/unit/CMakeLists.txt +++ b/test/unit/CMakeLists.txt @@ -64,7 +64,7 @@ endif() # USE_EXTERNAL_GTEST # include_directories(${PROJ_SOURCE_DIR}/include) -include_directories(${SQLITE3_INCLUDE_DIR}) + # Add the directory containing proj_config.h include_directories(${PROJ_BINARY_DIR}/src) @@ -140,8 +140,8 @@ set_property(SOURCE ${PROJ_TEST_CPP_API_SOURCES} PROPERTY SKIP_UNITY_BUILD_INCLU target_link_libraries(proj_test_cpp_api PRIVATE GTest::gtest - PRIVATE ${PROJ_LIBRARIES} - PRIVATE ${SQLITE3_LIBRARY}) + PRIVATE SQLite::SQLite3 + PRIVATE ${PROJ_LIBRARIES}) add_test(NAME proj_test_cpp_api COMMAND proj_test_cpp_api) set_property(TEST proj_test_cpp_api PROPERTY ENVIRONMENT ${PROJ_TEST_ENVIRONMENT}) @@ -172,8 +172,8 @@ if(CURL_ENABLED) endif() target_link_libraries(test_network PRIVATE GTest::gtest - PRIVATE ${PROJ_LIBRARIES} - PRIVATE ${SQLITE3_LIBRARY}) + PRIVATE SQLite::SQLite3 + PRIVATE ${PROJ_LIBRARIES}) if(TIFF_ENABLED) add_test(NAME test_network COMMAND test_network) set_property(TEST test_network