FindRustls.cmake 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 Rustls library
  25. #
  26. # Input variables:
  27. #
  28. # - `RUSTLS_INCLUDE_DIR`: The Rustls include directory.
  29. # - `RUSTLS_LIBRARY`: Path to `rustls` library.
  30. #
  31. # Result variables:
  32. #
  33. # - `RUSTLS_FOUND`: System has Rustls.
  34. # - `RUSTLS_INCLUDE_DIRS`: The Rustls include directories.
  35. # - `RUSTLS_LIBRARIES`: The Rustls library names.
  36. # - `RUSTLS_LIBRARY_DIRS`: The Rustls library directories.
  37. # - `RUSTLS_PC_REQUIRES`: The Rustls pkg-config packages.
  38. # - `RUSTLS_CFLAGS`: Required compiler flags.
  39. # - `RUSTLS_VERSION`: Version of Rustls.
  40. if(CURL_USE_PKGCONFIG AND
  41. NOT DEFINED RUSTLS_INCLUDE_DIR AND
  42. NOT DEFINED RUSTLS_LIBRARY)
  43. find_package(PkgConfig QUIET)
  44. pkg_check_modules(RUSTLS "rustls")
  45. endif()
  46. if(RUSTLS_FOUND)
  47. set(RUSTLS_PC_REQUIRES "rustls")
  48. string(REPLACE ";" " " RUSTLS_CFLAGS "${RUSTLS_CFLAGS}")
  49. message(STATUS "Found Rustls (via pkg-config): ${RUSTLS_INCLUDE_DIRS} (found version \"${RUSTLS_VERSION}\")")
  50. else()
  51. find_path(RUSTLS_INCLUDE_DIR NAMES "rustls.h")
  52. find_library(RUSTLS_LIBRARY NAMES "rustls")
  53. include(FindPackageHandleStandardArgs)
  54. find_package_handle_standard_args(Rustls
  55. REQUIRED_VARS
  56. RUSTLS_INCLUDE_DIR
  57. RUSTLS_LIBRARY
  58. )
  59. if(RUSTLS_FOUND)
  60. set(RUSTLS_INCLUDE_DIRS ${RUSTLS_INCLUDE_DIR})
  61. set(RUSTLS_LIBRARIES ${RUSTLS_LIBRARY})
  62. endif()
  63. mark_as_advanced(RUSTLS_INCLUDE_DIR RUSTLS_LIBRARY)
  64. endif()
  65. if(APPLE)
  66. find_library(SECURITY_FRAMEWORK "Security")
  67. mark_as_advanced(SECURITY_FRAMEWORK)
  68. if(NOT SECURITY_FRAMEWORK)
  69. message(FATAL_ERROR "Security framework not found")
  70. endif()
  71. list(APPEND RUSTLS_LIBRARIES "-framework Security")
  72. find_library(FOUNDATION_FRAMEWORK "Foundation")
  73. mark_as_advanced(FOUNDATION_FRAMEWORK)
  74. if(NOT FOUNDATION_FRAMEWORK)
  75. message(FATAL_ERROR "Foundation framework not found")
  76. endif()
  77. list(APPEND RUSTLS_LIBRARIES "-framework Foundation")
  78. elseif(NOT WIN32)
  79. find_library(_pthread_library "pthread")
  80. if(_pthread_library)
  81. list(APPEND RUSTLS_LIBRARIES "pthread")
  82. endif()
  83. mark_as_advanced(_pthread_library)
  84. find_library(_dl_library "dl")
  85. if(_dl_library)
  86. list(APPEND RUSTLS_LIBRARIES "dl")
  87. endif()
  88. mark_as_advanced(_dl_library)
  89. find_library(_math_library "m")
  90. if(_math_library)
  91. list(APPEND RUSTLS_LIBRARIES "m")
  92. endif()
  93. mark_as_advanced(_math_library)
  94. endif()