Merge topic 'cxx-checks-tolerate-unused-arguments'
[kiteware-cmake.git] / Modules / FindSQLite3.cmake
blob308a444d624809951627b8d274b78af29f41a8c2
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 pkg_check_modules(PC_SQLite3 QUIET sqlite3)
41 # Look for the necessary header
42 find_path(SQLite3_INCLUDE_DIR NAMES sqlite3.h
43   HINTS
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
50   HINTS
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]+\""
59          LIMIT_COUNT 1)
60     string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+"
61            SQLite3_VERSION "${_ver_line}")
62     unset(_ver_line)
63 endif()
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
71 if(SQLite3_FOUND)
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}")
79     endif()
80 endif()
82 cmake_policy(POP)