FindWolfSSL.cmake 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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_INCLUDE_DIR The wolfssl include directory (deprecated)
  30. # WOLFSSL_LIBRARY Path to wolfssl library
  31. # WolfSSL_LIBRARY Path to wolfssl library (deprecated)
  32. #
  33. # Result variables:
  34. #
  35. # WOLFSSL_FOUND System has wolfssl
  36. # WOLFSSL_INCLUDE_DIRS The wolfssl include directories
  37. # WOLFSSL_LIBRARIES The wolfssl library names
  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)
  48. find_package(PkgConfig QUIET)
  49. pkg_check_modules(PC_WOLFSSL "wolfssl")
  50. endif()
  51. find_path(WOLFSSL_INCLUDE_DIR NAMES "wolfssl/ssl.h"
  52. HINTS
  53. ${PC_WOLFSSL_INCLUDEDIR}
  54. ${PC_WOLFSSL_INCLUDE_DIRS}
  55. )
  56. find_library(WOLFSSL_LIBRARY NAMES "wolfssl"
  57. HINTS
  58. ${PC_WOLFSSL_LIBDIR}
  59. ${PC_WOLFSSL_LIBRARY_DIRS}
  60. )
  61. if(PC_WOLFSSL_VERSION)
  62. set(WOLFSSL_VERSION ${PC_WOLFSSL_VERSION})
  63. elseif(WOLFSSL_INCLUDE_DIR AND EXISTS "${WOLFSSL_INCLUDE_DIR}/wolfssl/version.h")
  64. set(_version_regex "#[\t ]*define[\t ]+LIBWOLFSSL_VERSION_STRING[\t ]+\"([^\"]*)\"")
  65. file(STRINGS "${WOLFSSL_INCLUDE_DIR}/wolfssl/version.h" _version_str REGEX "${_version_regex}")
  66. string(REGEX REPLACE "${_version_regex}" "\\1" _version_str "${_version_str}")
  67. set(WOLFSSL_VERSION "${_version_str}")
  68. unset(_version_regex)
  69. unset(_version_str)
  70. endif()
  71. include(FindPackageHandleStandardArgs)
  72. find_package_handle_standard_args(WolfSSL
  73. REQUIRED_VARS
  74. WOLFSSL_INCLUDE_DIR
  75. WOLFSSL_LIBRARY
  76. VERSION_VAR
  77. WOLFSSL_VERSION
  78. )
  79. if(WOLFSSL_FOUND)
  80. set(WOLFSSL_INCLUDE_DIRS ${WOLFSSL_INCLUDE_DIR})
  81. set(WOLFSSL_LIBRARIES ${WOLFSSL_LIBRARY})
  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. endif()
  88. endif()
  89. mark_as_advanced(WOLFSSL_INCLUDE_DIR WOLFSSL_LIBRARY)