FindNGTCP2.cmake 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #***************************************************************************
  2. # _ _ ____ _
  3. # Project ___| | | | _ \| |
  4. # / __| | | | |_) | |
  5. # | (__| |_| | _ <| |___
  6. # \___|\___/|_| \_\_____|
  7. #
  8. # Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
  9. #
  10. # This software is licensed as described in the file COPYING, which
  11. # you should have received as part of this distribution. The terms
  12. # are also available at https://curl.haxx.se/docs/copyright.html.
  13. #
  14. # You may opt to use, copy, modify, merge, publish, distribute and/or sell
  15. # copies of the Software, and permit persons to whom the Software is
  16. # furnished to do so, under the terms of the COPYING file.
  17. #
  18. # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  19. # KIND, either express or implied.
  20. #
  21. ###########################################################################
  22. #[=======================================================================[.rst:
  23. FindNGTCP2
  24. ----------
  25. Find the ngtcp2 library
  26. This module accepts optional COMPONENTS to control the crypto library (these are
  27. mutually exclusive)::
  28. OpenSSL: Use libngtcp2_crypto_openssl
  29. GnuTLS: Use libngtcp2_crypto_gnutls
  30. Result Variables
  31. ^^^^^^^^^^^^^^^^
  32. ``NGTCP2_FOUND``
  33. System has ngtcp2
  34. ``NGTCP2_INCLUDE_DIRS``
  35. The ngtcp2 include directories.
  36. ``NGTCP2_LIBRARIES``
  37. The libraries needed to use ngtcp2
  38. ``NGTCP2_VERSION``
  39. version of ngtcp2.
  40. #]=======================================================================]
  41. if(UNIX)
  42. find_package(PkgConfig QUIET)
  43. pkg_search_module(PC_NGTCP2 libngtcp2)
  44. endif()
  45. find_path(NGTCP2_INCLUDE_DIR ngtcp2/ngtcp2.h
  46. HINTS
  47. ${PC_NGTCP2_INCLUDEDIR}
  48. ${PC_NGTCP2_INCLUDE_DIRS}
  49. )
  50. find_library(NGTCP2_LIBRARY NAMES ngtcp2
  51. HINTS
  52. ${PC_NGTCP2_LIBDIR}
  53. ${PC_NGTCP2_LIBRARY_DIRS}
  54. )
  55. if(PC_NGTCP2_VERSION)
  56. set(NGTCP2_VERSION ${PC_NGTCP2_VERSION})
  57. endif()
  58. if(NGTCP2_FIND_COMPONENTS)
  59. set(NGTCP2_CRYPTO_BACKEND "")
  60. foreach(component IN LISTS NGTCP2_FIND_COMPONENTS)
  61. if(component MATCHES "^(OpenSSL|GnuTLS)")
  62. if(NGTCP2_CRYPTO_BACKEND)
  63. message(FATAL_ERROR "NGTCP2: Only one crypto library can be selected")
  64. endif()
  65. set(NGTCP2_CRYPTO_BACKEND ${component})
  66. endif()
  67. endforeach()
  68. if(NGTCP2_CRYPTO_BACKEND)
  69. string(TOLOWER "ngtcp2_crypto_${NGTCP2_CRYPTO_BACKEND}" _crypto_library)
  70. if(UNIX)
  71. pkg_search_module(PC_${_crypto_library} lib${_crypto_library})
  72. endif()
  73. find_library(${_crypto_library}_LIBRARY
  74. NAMES
  75. ${_crypto_library}
  76. HINTS
  77. ${PC_${_crypto_library}_LIBDIR}
  78. ${PC_${_crypto_library}_LIBRARY_DIRS}
  79. )
  80. if(${_crypto_library}_LIBRARY)
  81. set(NGTCP2_${NGTCP2_CRYPTO_BACKEND}_FOUND TRUE)
  82. set(NGTCP2_CRYPTO_LIBRARY ${${_crypto_library}_LIBRARY})
  83. endif()
  84. endif()
  85. endif()
  86. include(FindPackageHandleStandardArgs)
  87. find_package_handle_standard_args(NGTCP2
  88. REQUIRED_VARS
  89. NGTCP2_LIBRARY
  90. NGTCP2_INCLUDE_DIR
  91. VERSION_VAR NGTCP2_VERSION
  92. HANDLE_COMPONENTS
  93. )
  94. if(NGTCP2_FOUND)
  95. set(NGTCP2_LIBRARIES ${NGTCP2_LIBRARY} ${NGTCP2_CRYPTO_LIBRARY})
  96. set(NGTCP2_INCLUDE_DIRS ${NGTCP2_INCLUDE_DIR})
  97. endif()
  98. mark_as_advanced(NGTCP2_INCLUDE_DIRS NGTCP2_LIBRARIES)