FindUthash.cmake 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #[=======================================================================[.rst
  2. FindUthash
  3. ----------
  4. FindModule for uthash and the associated library
  5. Imported Targets
  6. ^^^^^^^^^^^^^^^^
  7. .. versionadded:: 3.0
  8. This module defines the :prop_tgt:`IMPORTED` target ``Uthash::Uthash``.
  9. Result Variables
  10. ^^^^^^^^^^^^^^^^
  11. This module sets the following variables:
  12. ``Uthash_FOUND``
  13. True, if the library was found.
  14. ``Uthash_VERSION``
  15. Detected version of found uthash library.
  16. Cache variables
  17. ^^^^^^^^^^^^^^^
  18. The following cache variables may also be set:
  19. ``Uthash_INCLUDE_DIR``
  20. Directory containing ``uthash.h``.
  21. #]=======================================================================]
  22. # cmake-format: off
  23. # cmake-lint: disable=C0103
  24. # cmake-lint: disable=C0301
  25. # cmake-format: on
  26. include(FindPackageHandleStandardArgs)
  27. find_path(
  28. Uthash_INCLUDE_DIR
  29. NAMES uthash.h
  30. PATHS /usr/include /usr/local/include
  31. DOC "uthash include directory")
  32. if(EXISTS "${Uthash_INCLUDE_DIR}/uthash.h")
  33. file(STRINGS "${Uthash_INCLUDE_DIR}/uthash.h" _version_string
  34. REGEX "#define[ \t]+UTHASH_VERSION[ \t]+[0-9]+\\.[0-9]+\\.[0-9]+")
  35. string(REGEX REPLACE "#define[ \t]+UTHASH_VERSION[ \t]+([0-9]+\\.[0-9]+\\.[0-9]+)" "\\1" Uthash_VERSION
  36. "${_version_string}")
  37. else()
  38. if(NOT Uthash_FIND_QUIETLY)
  39. message(AUTHOR_WARNING "Failed to find uthash version.")
  40. endif()
  41. set(Uthash_VERSION 0.0.0)
  42. endif()
  43. if(CMAKE_HOST_SYSTEM_NAME MATCHES "Darwin|Windows")
  44. set(Uthash_ERROR_REASON "Ensure that obs-deps is provided as part of CMAKE_PREFIX_PATH.")
  45. elseif(CMAKE_HOST_SYSTEM_NAME MATCHES "Linux|FreeBSD")
  46. set(Uthash_ERROR_REASON "Ensure uthash library is available in local include paths.")
  47. endif()
  48. find_package_handle_standard_args(
  49. Uthash
  50. REQUIRED_VARS Uthash_INCLUDE_DIR
  51. VERSION_VAR Uthash_VERSION REASON_FAILURE_MESSAGE "${Uthash_ERROR_REASON}")
  52. mark_as_advanced(Uthash_INCLUDE_DIR)
  53. unset(Uthash_ERROR_REASON)
  54. if(Uthash_FOUND)
  55. if(NOT TARGET Uthash::Uthash)
  56. add_library(Uthash::Uthash INTERFACE IMPORTED)
  57. set_target_properties(Uthash::Uthash PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${Uthash_INCLUDE_DIR}")
  58. endif()
  59. endif()
  60. include(FeatureSummary)
  61. set_package_properties(
  62. Uthash PROPERTIES
  63. URL "https://troydhanson.github.io/uthash"
  64. DESCRIPTION "A hash table for C structures")