FindSQLite3.cmake 2.1 KB

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