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