FindSQLite3.cmake 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. pkg_check_modules(PC_SQLite3 QUIET sqlite3)
  28. # Look for the necessary header
  29. find_path(SQLite3_INCLUDE_DIR NAMES sqlite3.h
  30. HINTS
  31. ${PC_SQLite3_INCLUDE_DIRS}
  32. )
  33. mark_as_advanced(SQLite3_INCLUDE_DIR)
  34. # Look for the necessary library
  35. find_library(SQLite3_LIBRARY NAMES sqlite3 sqlite
  36. HINTS
  37. ${PC_SQLite3_LIBRARY_DIRS}
  38. )
  39. mark_as_advanced(SQLite3_LIBRARY)
  40. # Extract version information from the header file
  41. if(SQLite3_INCLUDE_DIR)
  42. file(STRINGS ${SQLite3_INCLUDE_DIR}/sqlite3.h _ver_line
  43. REGEX "^#define SQLITE_VERSION *\"[0-9]+\\.[0-9]+\\.[0-9]+\""
  44. LIMIT_COUNT 1)
  45. string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+"
  46. SQLite3_VERSION "${_ver_line}")
  47. unset(_ver_line)
  48. endif()
  49. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  50. find_package_handle_standard_args(SQLite3
  51. REQUIRED_VARS SQLite3_INCLUDE_DIR SQLite3_LIBRARY
  52. VERSION_VAR SQLite3_VERSION)
  53. # Create the imported target
  54. if(SQLite3_FOUND)
  55. set(SQLite3_INCLUDE_DIRS ${SQLite3_INCLUDE_DIR})
  56. set(SQLite3_LIBRARIES ${SQLite3_LIBRARY})
  57. if(NOT TARGET SQLite::SQLite3)
  58. add_library(SQLite::SQLite3 UNKNOWN IMPORTED)
  59. set_target_properties(SQLite::SQLite3 PROPERTIES
  60. IMPORTED_LOCATION "${SQLite3_LIBRARY}"
  61. INTERFACE_INCLUDE_DIRECTORIES "${SQLite3_INCLUDE_DIR}")
  62. endif()
  63. endif()
  64. cmake_policy(POP)