FindSQLite3.cmake 2.3 KB

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