FindNGTCP2.cmake 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. # Find the ngtcp2 library
  25. #
  26. # This module accepts optional COMPONENTS to control the crypto library (these are
  27. # mutually exclusive):
  28. #
  29. # - quictls: Use `libngtcp2_crypto_quictls`. (choose this for LibreSSL)
  30. # - BoringSSL: Use `libngtcp2_crypto_boringssl`. (choose this for AWS-LC)
  31. # - wolfSSL: Use `libngtcp2_crypto_wolfssl`.
  32. # - GnuTLS: Use `libngtcp2_crypto_gnutls`.
  33. #
  34. # Input variables:
  35. #
  36. # - `NGTCP2_INCLUDE_DIR`: The ngtcp2 include directory.
  37. # - `NGTCP2_LIBRARY`: Path to `ngtcp2` library.
  38. #
  39. # Result variables:
  40. #
  41. # - `NGTCP2_FOUND`: System has ngtcp2.
  42. # - `NGTCP2_INCLUDE_DIRS`: The ngtcp2 include directories.
  43. # - `NGTCP2_LIBRARIES`: The ngtcp2 library names.
  44. # - `NGTCP2_VERSION`: Version of ngtcp2.
  45. if(CURL_USE_PKGCONFIG)
  46. find_package(PkgConfig QUIET)
  47. pkg_check_modules(PC_NGTCP2 "libngtcp2")
  48. endif()
  49. find_path(NGTCP2_INCLUDE_DIR NAMES "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. elseif(NGTCP2_INCLUDE_DIR AND EXISTS "${NGTCP2_INCLUDE_DIR}/ngtcp2/version.h")
  62. set(_version_regex "#[\t ]*define[\t ]+NGTCP2_VERSION[\t ]+\"([^\"]*)\"")
  63. file(STRINGS "${NGTCP2_INCLUDE_DIR}/ngtcp2/version.h" _version_str REGEX "${_version_regex}")
  64. string(REGEX REPLACE "${_version_regex}" "\\1" _version_str "${_version_str}")
  65. set(NGTCP2_VERSION "${_version_str}")
  66. unset(_version_regex)
  67. unset(_version_str)
  68. endif()
  69. if(NGTCP2_FIND_COMPONENTS)
  70. set(_ngtcp2_crypto_backend "")
  71. foreach(_component IN LISTS NGTCP2_FIND_COMPONENTS)
  72. if(_component MATCHES "^(BoringSSL|quictls|wolfSSL|GnuTLS)")
  73. if(_ngtcp2_crypto_backend)
  74. message(FATAL_ERROR "NGTCP2: Only one crypto library can be selected")
  75. endif()
  76. set(_ngtcp2_crypto_backend ${_component})
  77. endif()
  78. endforeach()
  79. if(_ngtcp2_crypto_backend)
  80. string(TOLOWER "ngtcp2_crypto_${_ngtcp2_crypto_backend}" _crypto_library)
  81. if(CURL_USE_PKGCONFIG)
  82. pkg_check_modules(PC_${_crypto_library} "lib${_crypto_library}")
  83. endif()
  84. get_filename_component(_ngtcp2_library_dir "${NGTCP2_LIBRARY}" DIRECTORY)
  85. find_library(${_crypto_library}_LIBRARY NAMES ${_crypto_library}
  86. HINTS
  87. ${_ngtcp2_library_dir}
  88. ${PC_${_crypto_library}_LIBDIR}
  89. ${PC_${_crypto_library}_LIBRARY_DIRS}
  90. )
  91. if(${_crypto_library}_LIBRARY)
  92. set(NGTCP2_${_ngtcp2_crypto_backend}_FOUND TRUE)
  93. set(NGTCP2_CRYPTO_LIBRARY ${${_crypto_library}_LIBRARY})
  94. endif()
  95. endif()
  96. endif()
  97. include(FindPackageHandleStandardArgs)
  98. find_package_handle_standard_args(NGTCP2
  99. REQUIRED_VARS
  100. NGTCP2_INCLUDE_DIR
  101. NGTCP2_LIBRARY
  102. VERSION_VAR
  103. NGTCP2_VERSION
  104. HANDLE_COMPONENTS
  105. )
  106. if(NGTCP2_FOUND)
  107. set(NGTCP2_INCLUDE_DIRS ${NGTCP2_INCLUDE_DIR})
  108. set(NGTCP2_LIBRARIES ${NGTCP2_LIBRARY} ${NGTCP2_CRYPTO_LIBRARY})
  109. endif()
  110. mark_as_advanced(NGTCP2_INCLUDE_DIR NGTCP2_LIBRARY NGTCP2_CRYPTO_LIBRARY)