1 # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 # file Copyright.txt or https://cmake.org/licensing for details.
4 #[=======================================================================[.rst:
10 Find the SQLite libraries, v3
15 This module defines the following :prop_tgt:`IMPORTED` target:
22 This module will set the following variables if found:
24 ``SQLite3_INCLUDE_DIRS``
25 where to find sqlite3.h, etc.
27 the libraries to link against to use SQLite3.
29 version of the SQLite3 library found
33 #]=======================================================================]
36 cmake_policy(SET CMP0159 NEW) # file(STRINGS) with REGEX updates CMAKE_MATCH_<n>
38 find_package(PkgConfig QUIET)
40 pkg_check_modules(PC_SQLite3 QUIET sqlite3)
43 # Look for the necessary header
44 find_path(SQLite3_INCLUDE_DIR NAMES sqlite3.h
46 ${PC_SQLite3_INCLUDE_DIRS}
48 mark_as_advanced(SQLite3_INCLUDE_DIR)
50 # Look for the necessary library
51 find_library(SQLite3_LIBRARY NAMES sqlite3 sqlite
53 ${PC_SQLite3_LIBRARY_DIRS}
55 mark_as_advanced(SQLite3_LIBRARY)
57 # Extract version information from the header file
58 if(SQLite3_INCLUDE_DIR)
59 file(STRINGS ${SQLite3_INCLUDE_DIR}/sqlite3.h _ver_line
60 REGEX "^#define SQLITE_VERSION *\"[0-9]+\\.[0-9]+\\.[0-9]+\""
62 string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+"
63 SQLite3_VERSION "${_ver_line}")
67 include(FindPackageHandleStandardArgs)
68 find_package_handle_standard_args(SQLite3
69 REQUIRED_VARS SQLite3_INCLUDE_DIR SQLite3_LIBRARY
70 VERSION_VAR SQLite3_VERSION)
72 # Create the imported target
74 set(SQLite3_INCLUDE_DIRS ${SQLite3_INCLUDE_DIR})
75 set(SQLite3_LIBRARIES ${SQLite3_LIBRARY})
76 if(NOT TARGET SQLite::SQLite3)
77 add_library(SQLite::SQLite3 UNKNOWN IMPORTED)
78 set_target_properties(SQLite::SQLite3 PROPERTIES
79 IMPORTED_LOCATION "${SQLite3_LIBRARY}"
80 INTERFACE_INCLUDE_DIRECTORIES "${SQLite3_INCLUDE_DIR}")