FindWebsocketpp.cmake 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #[=======================================================================[.rst
  2. FindWebsocketpp
  3. ---------------
  4. FindModule for WebSocket++ and the associated library
  5. Imported Targets
  6. ^^^^^^^^^^^^^^^^
  7. .. versionadded:: 2.0
  8. This module defines the :prop_tgt:`IMPORTED` target ``Websocketpp::Websocketpp``.
  9. Result Variables
  10. ^^^^^^^^^^^^^^^^
  11. This module sets the following variables:
  12. ``Websocketpp_FOUND``
  13. True, if the library was found.
  14. ``Websocketpp_VERSION``
  15. Detected version of found Websocketpp library.
  16. Cache variables
  17. ^^^^^^^^^^^^^^^
  18. The following cache variables may also be set:
  19. ``Websocketpp_INCLUDE_DIR``
  20. Directory containing ``websocketpp/client.hpp``.
  21. #]=======================================================================]
  22. include(FindPackageHandleStandardArgs)
  23. find_path(
  24. Websocketpp_INCLUDE_DIR
  25. NAMES websocketpp/client.hpp
  26. PATHS /usr/include /usr/local/include
  27. DOC "WebSocket++ include directory"
  28. )
  29. if(EXISTS "${Websocketpp_INCLUDE_DIR}/websocketpp/version.hpp")
  30. file(
  31. STRINGS
  32. "${Websocketpp_INCLUDE_DIR}/websocketpp/version.hpp"
  33. _version_string
  34. REGEX "^.*(major|minor|patch)_version[ \t]+=[ \t]+[0-9]+"
  35. )
  36. string(REGEX REPLACE ".*major_version[ \t]+=[ \t]+([0-9]+).*" "\\1" _version_major "${_version_string}")
  37. string(REGEX REPLACE ".*minor_version[ \t]+=[ \t]+([0-9]+).*" "\\1" _version_minor "${_version_string}")
  38. string(REGEX REPLACE ".*patch_version[ \t]+=[ \t]+([0-9]+).*" "\\1" _version_patch "${_version_string}")
  39. set(Websocketpp_VERSION "${_version_major}.${_version_minor}.${_version_patch}")
  40. unset(_version_major)
  41. unset(_version_minor)
  42. unset(_version_patch)
  43. else()
  44. if(NOT Websocketpp_FIND_QUIETLY)
  45. message(AUTHOR_WARNING "Failed to find WebSocket++ version.")
  46. endif()
  47. set(Websocketpp_VERSION 0.0.0)
  48. endif()
  49. if(CMAKE_HOST_SYSTEM_NAME MATCHES "Darwin|Windows")
  50. set(Websocketpp_ERROR_REASON "Ensure that obs-deps is provided as part of CMAKE_PREFIX_PATH.")
  51. elseif(CMAKE_HOST_SYSTEM_NAME MATCHES "Linux|FreeBSD")
  52. set(Websocketpp_ERROR_REASON "Ensure WebSocket++ library is available in local include paths.")
  53. endif()
  54. find_package_handle_standard_args(
  55. Websocketpp
  56. REQUIRED_VARS Websocketpp_INCLUDE_DIR
  57. VERSION_VAR Websocketpp_VERSION
  58. REASON_FAILURE_MESSAGE "${Websocketpp_ERROR_REASON}"
  59. )
  60. mark_as_advanced(Websocketpp_INCLUDE_DIR)
  61. unset(Websocketpp_ERROR_REASON)
  62. if(Websocketpp_FOUND)
  63. if(NOT TARGET Websocketpp::Websocketpp)
  64. add_library(Websocketpp::Websocketpp INTERFACE IMPORTED)
  65. set_target_properties(
  66. Websocketpp::Websocketpp
  67. PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${Websocketpp_INCLUDE_DIR}"
  68. )
  69. endif()
  70. endif()
  71. include(FeatureSummary)
  72. set_package_properties(
  73. Websocketpp
  74. PROPERTIES
  75. URL "https://www.zaphoyd.com/websocketpp/"
  76. DESCRIPTION "WebSocket++ is a header only C++ library that implements RFC6455 The WebSocket Protocol."
  77. )