FindSQLite3.cmake 2.0 KB

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