FindWolfSSL.cmake 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 wolfSSL library
  25. #
  26. # Input variables:
  27. #
  28. # - `WOLFSSL_INCLUDE_DIR`: The wolfSSL include directory.
  29. # - `WOLFSSL_LIBRARY`: Path to `wolfssl` library.
  30. #
  31. # Result variables:
  32. #
  33. # - `WOLFSSL_FOUND`: System has wolfSSL.
  34. # - `WOLFSSL_INCLUDE_DIRS`: The wolfSSL include directories.
  35. # - `WOLFSSL_LIBRARIES`: The wolfSSL library names.
  36. # - `WOLFSSL_LIBRARY_DIRS`: The wolfSSL library directories.
  37. # - `WOLFSSL_CFLAGS`: Required compiler flags.
  38. # - `WOLFSSL_VERSION`: Version of wolfSSL.
  39. if(DEFINED WolfSSL_INCLUDE_DIR AND NOT DEFINED WOLFSSL_INCLUDE_DIR)
  40. message(WARNING "WolfSSL_INCLUDE_DIR is deprecated, use WOLFSSL_INCLUDE_DIR instead.")
  41. set(WOLFSSL_INCLUDE_DIR "${WolfSSL_INCLUDE_DIR}")
  42. endif()
  43. if(DEFINED WolfSSL_LIBRARY AND NOT DEFINED WOLFSSL_LIBRARY)
  44. message(WARNING "WolfSSL_LIBRARY is deprecated, use WOLFSSL_LIBRARY instead.")
  45. set(WOLFSSL_LIBRARY "${WolfSSL_LIBRARY}")
  46. endif()
  47. if(CURL_USE_PKGCONFIG AND
  48. NOT DEFINED WOLFSSL_INCLUDE_DIR AND
  49. NOT DEFINED WOLFSSL_LIBRARY)
  50. find_package(PkgConfig QUIET)
  51. pkg_check_modules(WOLFSSL "wolfssl")
  52. endif()
  53. if(WOLFSSL_FOUND)
  54. string(REPLACE ";" " " WOLFSSL_CFLAGS "${WOLFSSL_CFLAGS}")
  55. message(STATUS "Found WolfSSL (via pkg-config): ${WOLFSSL_INCLUDE_DIRS} (found version \"${WOLFSSL_VERSION}\")")
  56. else()
  57. find_path(WOLFSSL_INCLUDE_DIR NAMES "wolfssl/ssl.h")
  58. find_library(WOLFSSL_LIBRARY NAMES "wolfssl")
  59. unset(WOLFSSL_VERSION CACHE)
  60. if(WOLFSSL_INCLUDE_DIR AND EXISTS "${WOLFSSL_INCLUDE_DIR}/wolfssl/version.h")
  61. set(_version_regex "#[\t ]*define[\t ]+LIBWOLFSSL_VERSION_STRING[\t ]+\"([^\"]*)\"")
  62. file(STRINGS "${WOLFSSL_INCLUDE_DIR}/wolfssl/version.h" _version_str REGEX "${_version_regex}")
  63. string(REGEX REPLACE "${_version_regex}" "\\1" _version_str "${_version_str}")
  64. set(WOLFSSL_VERSION "${_version_str}")
  65. unset(_version_regex)
  66. unset(_version_str)
  67. endif()
  68. include(FindPackageHandleStandardArgs)
  69. find_package_handle_standard_args(WolfSSL
  70. REQUIRED_VARS
  71. WOLFSSL_INCLUDE_DIR
  72. WOLFSSL_LIBRARY
  73. VERSION_VAR
  74. WOLFSSL_VERSION
  75. )
  76. if(WOLFSSL_FOUND)
  77. set(WOLFSSL_INCLUDE_DIRS ${WOLFSSL_INCLUDE_DIR})
  78. set(WOLFSSL_LIBRARIES ${WOLFSSL_LIBRARY})
  79. endif()
  80. mark_as_advanced(WOLFSSL_INCLUDE_DIR WOLFSSL_LIBRARY)
  81. endif()
  82. if(NOT WIN32)
  83. find_library(_math_library "m")
  84. if(_math_library)
  85. list(APPEND WOLFSSL_LIBRARIES "m") # for log and pow
  86. endif()
  87. mark_as_advanced(_math_library)
  88. endif()