Merge topic 'cuda_add_12.8_new_sm_support'
[kiteware-cmake.git] / Modules / FindSQLite3.cmake
blob34205381bd20dfc28e5653747b1793393992b64c
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:
5 FindSQLite3
6 -----------
8 .. versionadded:: 3.14
10 Find the SQLite libraries, v3
12 Imported Targets
13 ^^^^^^^^^^^^^^^^
15 This module defines the following :prop_tgt:`IMPORTED` target:
17 ``SQLite::SQLite3``
19 Result variables
20 ^^^^^^^^^^^^^^^^
22 This module will set the following variables if found:
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
33 #]=======================================================================]
35 cmake_policy(PUSH)
36 cmake_policy(SET CMP0159 NEW) # file(STRINGS) with REGEX updates CMAKE_MATCH_<n>
38 find_package(PkgConfig QUIET)
39 if(PKG_CONFIG_FOUND)
40   pkg_check_modules(PC_SQLite3 QUIET sqlite3)
41 endif()
43 # Look for the necessary header
44 find_path(SQLite3_INCLUDE_DIR NAMES sqlite3.h
45   HINTS
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
52   HINTS
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]+\""
61          LIMIT_COUNT 1)
62     string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+"
63            SQLite3_VERSION "${_ver_line}")
64     unset(_ver_line)
65 endif()
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
73 if(SQLite3_FOUND)
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}")
81     endif()
82 endif()
84 cmake_policy(POP)