2
0

FindNGTCP2.cmake 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. OpenSSL: Use libngtcp2_crypto_quictls
  31. GnuTLS: Use libngtcp2_crypto_gnutls
  32. Result Variables
  33. ^^^^^^^^^^^^^^^^
  34. ``NGTCP2_FOUND``
  35. System has ngtcp2
  36. ``NGTCP2_INCLUDE_DIRS``
  37. The ngtcp2 include directories.
  38. ``NGTCP2_LIBRARIES``
  39. The libraries needed to use ngtcp2
  40. ``NGTCP2_VERSION``
  41. version of ngtcp2.
  42. #]=======================================================================]
  43. if(UNIX)
  44. find_package(PkgConfig QUIET)
  45. pkg_search_module(PC_NGTCP2 libngtcp2)
  46. endif()
  47. find_path(NGTCP2_INCLUDE_DIR ngtcp2/ngtcp2.h
  48. HINTS
  49. ${PC_NGTCP2_INCLUDEDIR}
  50. ${PC_NGTCP2_INCLUDE_DIRS}
  51. )
  52. find_library(NGTCP2_LIBRARY NAMES ngtcp2
  53. HINTS
  54. ${PC_NGTCP2_LIBDIR}
  55. ${PC_NGTCP2_LIBRARY_DIRS}
  56. )
  57. if(PC_NGTCP2_VERSION)
  58. set(NGTCP2_VERSION ${PC_NGTCP2_VERSION})
  59. endif()
  60. if(NGTCP2_FIND_COMPONENTS)
  61. set(NGTCP2_CRYPTO_BACKEND "")
  62. foreach(component IN LISTS NGTCP2_FIND_COMPONENTS)
  63. if(component MATCHES "^(BoringSSL|quictls|wolfSSL|GnuTLS)")
  64. if(NGTCP2_CRYPTO_BACKEND)
  65. message(FATAL_ERROR "NGTCP2: Only one crypto library can be selected")
  66. endif()
  67. set(NGTCP2_CRYPTO_BACKEND ${component})
  68. endif()
  69. endforeach()
  70. if(NGTCP2_CRYPTO_BACKEND)
  71. string(TOLOWER "ngtcp2_crypto_${NGTCP2_CRYPTO_BACKEND}" _crypto_library)
  72. if(UNIX)
  73. pkg_search_module(PC_${_crypto_library} lib${_crypto_library})
  74. endif()
  75. find_library(${_crypto_library}_LIBRARY
  76. NAMES
  77. ${_crypto_library}
  78. HINTS
  79. ${PC_${_crypto_library}_LIBDIR}
  80. ${PC_${_crypto_library}_LIBRARY_DIRS}
  81. )
  82. if(${_crypto_library}_LIBRARY)
  83. set(NGTCP2_${NGTCP2_CRYPTO_BACKEND}_FOUND TRUE)
  84. set(NGTCP2_CRYPTO_LIBRARY ${${_crypto_library}_LIBRARY})
  85. endif()
  86. endif()
  87. endif()
  88. include(FindPackageHandleStandardArgs)
  89. find_package_handle_standard_args(NGTCP2
  90. REQUIRED_VARS
  91. NGTCP2_LIBRARY
  92. NGTCP2_INCLUDE_DIR
  93. VERSION_VAR NGTCP2_VERSION
  94. HANDLE_COMPONENTS
  95. )
  96. if(NGTCP2_FOUND)
  97. set(NGTCP2_LIBRARIES ${NGTCP2_LIBRARY} ${NGTCP2_CRYPTO_LIBRARY})
  98. set(NGTCP2_INCLUDE_DIRS ${NGTCP2_INCLUDE_DIR})
  99. endif()
  100. mark_as_advanced(NGTCP2_INCLUDE_DIRS NGTCP2_LIBRARIES)