FindUthash.cmake 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. include(FindPackageHandleStandardArgs)
  23. find_path(Uthash_INCLUDE_DIR NAMES uthash.h PATHS /usr/include /usr/local/include DOC "uthash include directory")
  24. if(EXISTS "${Uthash_INCLUDE_DIR}/uthash.h")
  25. file(
  26. STRINGS
  27. "${Uthash_INCLUDE_DIR}/uthash.h"
  28. _version_string
  29. REGEX "#define[ \t]+UTHASH_VERSION[ \t]+[0-9]+\\.[0-9]+\\.[0-9]+"
  30. )
  31. string(
  32. REGEX REPLACE
  33. "#define[ \t]+UTHASH_VERSION[ \t]+([0-9]+\\.[0-9]+\\.[0-9]+)"
  34. "\\1"
  35. Uthash_VERSION
  36. "${_version_string}"
  37. )
  38. else()
  39. if(NOT Uthash_FIND_QUIETLY)
  40. message(AUTHOR_WARNING "Failed to find uthash version.")
  41. endif()
  42. set(Uthash_VERSION 0.0.0)
  43. endif()
  44. if(CMAKE_HOST_SYSTEM_NAME MATCHES "Darwin|Windows")
  45. set(Uthash_ERROR_REASON "Ensure that obs-deps is provided as part of CMAKE_PREFIX_PATH.")
  46. elseif(CMAKE_HOST_SYSTEM_NAME MATCHES "Linux|FreeBSD")
  47. set(Uthash_ERROR_REASON "Ensure uthash library is available in local include paths.")
  48. endif()
  49. find_package_handle_standard_args(
  50. Uthash
  51. REQUIRED_VARS Uthash_INCLUDE_DIR
  52. VERSION_VAR Uthash_VERSION
  53. REASON_FAILURE_MESSAGE "${Uthash_ERROR_REASON}"
  54. )
  55. mark_as_advanced(Uthash_INCLUDE_DIR)
  56. unset(Uthash_ERROR_REASON)
  57. if(Uthash_FOUND)
  58. if(NOT TARGET Uthash::Uthash)
  59. add_library(Uthash::Uthash INTERFACE IMPORTED)
  60. set_target_properties(Uthash::Uthash PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${Uthash_INCLUDE_DIR}")
  61. endif()
  62. endif()
  63. include(FeatureSummary)
  64. set_package_properties(
  65. Uthash
  66. PROPERTIES URL "https://troydhanson.github.io/uthash" DESCRIPTION "A hash table for C structures"
  67. )