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)
39 pkg_check_modules(PC_SQLite3 QUIET sqlite3)
41 # Look for the necessary header
42 find_path(SQLite3_INCLUDE_DIR NAMES sqlite3.h
44 ${PC_SQLite3_INCLUDE_DIRS}
46 mark_as_advanced(SQLite3_INCLUDE_DIR)
48 # Look for the necessary library
49 find_library(SQLite3_LIBRARY NAMES sqlite3 sqlite
51 ${PC_SQLite3_LIBRARY_DIRS}
53 mark_as_advanced(SQLite3_LIBRARY)
55 # Extract version information from the header file
56 if(SQLite3_INCLUDE_DIR)
57 file(STRINGS ${SQLite3_INCLUDE_DIR}/sqlite3.h _ver_line
58 REGEX "^#define SQLITE_VERSION *\"[0-9]+\\.[0-9]+\\.[0-9]+\""
60 string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+"
61 SQLite3_VERSION "${_ver_line}")
65 include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
66 find_package_handle_standard_args(SQLite3
67 REQUIRED_VARS SQLite3_INCLUDE_DIR SQLite3_LIBRARY
68 VERSION_VAR SQLite3_VERSION)
70 # Create the imported target
72 set(SQLite3_INCLUDE_DIRS ${SQLite3_INCLUDE_DIR})
73 set(SQLite3_LIBRARIES ${SQLite3_LIBRARY})
74 if(NOT TARGET SQLite::SQLite3)
75 add_library(SQLite::SQLite3 UNKNOWN IMPORTED)
76 set_target_properties(SQLite::SQLite3 PROPERTIES
77 IMPORTED_LOCATION "${SQLite3_LIBRARY}"
78 INTERFACE_INCLUDE_DIRECTORIES "${SQLite3_INCLUDE_DIR}")