1# Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
2# file Copyright.txt or https://cmake.org/licensing for details.
3
4#[=======================================================================[.rst:
5FindSQLite3
6-----------
7
8.. versionadded:: 3.14
9
10Find the SQLite libraries, v3
11
12IMPORTED targets
13^^^^^^^^^^^^^^^^
14
15This module defines the following :prop_tgt:`IMPORTED` target:
16
17``SQLite::SQLite3``
18
19Result variables
20^^^^^^^^^^^^^^^^
21
22This module will set the following variables if found:
23
24``SQLite3_INCLUDE_DIRS``
25  where to find sqlite3.h, etc.
26``SQLite3_LIBRARIES``
27  the libraries to link against to use SQLite3.
28``SQLite3_VERSION``
29  version of the SQLite3 library found
30``SQLite3_FOUND``
31  TRUE if found
32
33#]=======================================================================]
34
35# Look for the necessary header
36find_path(SQLite3_INCLUDE_DIR NAMES sqlite3.h)
37mark_as_advanced(SQLite3_INCLUDE_DIR)
38
39# Look for the necessary library
40find_library(SQLite3_LIBRARY NAMES sqlite3 sqlite)
41mark_as_advanced(SQLite3_LIBRARY)
42
43# Extract version information from the header file
44if(SQLite3_INCLUDE_DIR)
45    file(STRINGS ${SQLite3_INCLUDE_DIR}/sqlite3.h _ver_line
46         REGEX "^#define SQLITE_VERSION  *\"[0-9]+\\.[0-9]+\\.[0-9]+\""
47         LIMIT_COUNT 1)
48    string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+"
49           SQLite3_VERSION "${_ver_line}")
50    unset(_ver_line)
51endif()
52
53include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
54find_package_handle_standard_args(SQLite3
55    REQUIRED_VARS SQLite3_INCLUDE_DIR SQLite3_LIBRARY
56    VERSION_VAR SQLite3_VERSION)
57
58# Create the imported target
59if(SQLite3_FOUND)
60    set(SQLite3_INCLUDE_DIRS ${SQLite3_INCLUDE_DIR})
61    set(SQLite3_LIBRARIES ${SQLite3_LIBRARY})
62    if(NOT TARGET SQLite::SQLite3)
63        add_library(SQLite::SQLite3 UNKNOWN IMPORTED)
64        set_target_properties(SQLite::SQLite3 PROPERTIES
65            IMPORTED_LOCATION             "${SQLite3_LIBRARY}"
66            INTERFACE_INCLUDE_DIRECTORIES "${SQLite3_INCLUDE_DIR}")
67    endif()
68endif()
69