FindNGTCP2.cmake 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #***************************************************************************
  2. # _ _ ____ _
  3. # Project ___| | | | _ \| |
  4. # / __| | | | |_) | |
  5. # | (__| |_| | _ <| |___
  6. # \___|\___/|_| \_\_____|
  7. #
  8. # Copyright (C) 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.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. # SPDX-License-Identifier: curl
  22. #
  23. ###########################################################################
  24. #[=======================================================================[.rst:
  25. FindNGTCP2
  26. ----------
  27. Find the ngtcp2 library
  28. This module accepts optional COMPONENTS to control the crypto library (these are
  29. mutually exclusive)::
  30. quictls, LibreSSL: Use libngtcp2_crypto_quictls
  31. BoringSSL, AWS-LC: Use libngtcp2_crypto_boringssl
  32. wolfSSL: Use libngtcp2_crypto_wolfssl
  33. GnuTLS: Use libngtcp2_crypto_gnutls
  34. Result Variables
  35. ^^^^^^^^^^^^^^^^
  36. ``NGTCP2_FOUND``
  37. System has ngtcp2
  38. ``NGTCP2_INCLUDE_DIRS``
  39. The ngtcp2 include directories.
  40. ``NGTCP2_LIBRARIES``
  41. The libraries needed to use ngtcp2
  42. ``NGTCP2_VERSION``
  43. version of ngtcp2.
  44. #]=======================================================================]
  45. if(UNIX)
  46. find_package(PkgConfig QUIET)
  47. pkg_search_module(PC_NGTCP2 libngtcp2)
  48. endif()
  49. find_path(NGTCP2_INCLUDE_DIR ngtcp2/ngtcp2.h
  50. HINTS
  51. ${PC_NGTCP2_INCLUDEDIR}
  52. ${PC_NGTCP2_INCLUDE_DIRS}
  53. )
  54. find_library(NGTCP2_LIBRARY NAMES ngtcp2
  55. HINTS
  56. ${PC_NGTCP2_LIBDIR}
  57. ${PC_NGTCP2_LIBRARY_DIRS}
  58. )
  59. if(PC_NGTCP2_VERSION)
  60. set(NGTCP2_VERSION ${PC_NGTCP2_VERSION})
  61. endif()
  62. if(NGTCP2_FIND_COMPONENTS)
  63. set(NGTCP2_CRYPTO_BACKEND "")
  64. foreach(component IN LISTS NGTCP2_FIND_COMPONENTS)
  65. if(component MATCHES "^(BoringSSL|quictls|wolfSSL|GnuTLS)")
  66. if(NGTCP2_CRYPTO_BACKEND)
  67. message(FATAL_ERROR "NGTCP2: Only one crypto library can be selected")
  68. endif()
  69. set(NGTCP2_CRYPTO_BACKEND ${component})
  70. endif()
  71. endforeach()
  72. if(NGTCP2_CRYPTO_BACKEND)
  73. string(TOLOWER "ngtcp2_crypto_${NGTCP2_CRYPTO_BACKEND}" _crypto_library)
  74. if(UNIX)
  75. pkg_search_module(PC_${_crypto_library} lib${_crypto_library})
  76. endif()
  77. find_library(${_crypto_library}_LIBRARY
  78. NAMES
  79. ${_crypto_library}
  80. HINTS
  81. ${PC_${_crypto_library}_LIBDIR}
  82. ${PC_${_crypto_library}_LIBRARY_DIRS}
  83. )
  84. if(${_crypto_library}_LIBRARY)
  85. set(NGTCP2_${NGTCP2_CRYPTO_BACKEND}_FOUND TRUE)
  86. set(NGTCP2_CRYPTO_LIBRARY ${${_crypto_library}_LIBRARY})
  87. endif()
  88. endif()
  89. endif()
  90. include(FindPackageHandleStandardArgs)
  91. find_package_handle_standard_args(NGTCP2
  92. REQUIRED_VARS
  93. NGTCP2_LIBRARY
  94. NGTCP2_INCLUDE_DIR
  95. VERSION_VAR NGTCP2_VERSION
  96. HANDLE_COMPONENTS
  97. )
  98. if(NGTCP2_FOUND)
  99. set(NGTCP2_LIBRARIES ${NGTCP2_LIBRARY} ${NGTCP2_CRYPTO_LIBRARY})
  100. set(NGTCP2_INCLUDE_DIRS ${NGTCP2_INCLUDE_DIR})
  101. endif()
  102. mark_as_advanced(NGTCP2_INCLUDE_DIRS NGTCP2_LIBRARIES)