xref: /curl/CMake/FindWolfSSL.cmake (revision 3e60f174)
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
40if(DEFINED WolfSSL_INCLUDE_DIR AND NOT DEFINED WOLFSSL_INCLUDE_DIR)
41  message(WARNING "WolfSSL_INCLUDE_DIR is deprecated, use WOLFSSL_INCLUDE_DIR instead.")
42  set(WOLFSSL_INCLUDE_DIR "${WolfSSL_INCLUDE_DIR}")
43endif()
44if(DEFINED WolfSSL_LIBRARY AND NOT DEFINED WOLFSSL_LIBRARY)
45  message(WARNING "WolfSSL_LIBRARY is deprecated, use WOLFSSL_LIBRARY instead.")
46  set(WOLFSSL_LIBRARY "${WolfSSL_LIBRARY}")
47endif()
48
49if(CURL_USE_PKGCONFIG)
50  find_package(PkgConfig QUIET)
51  pkg_check_modules(PC_WOLFSSL "wolfssl")
52endif()
53
54find_path(WOLFSSL_INCLUDE_DIR NAMES "wolfssl/ssl.h"
55  HINTS
56    ${PC_WOLFSSL_INCLUDEDIR}
57    ${PC_WOLFSSL_INCLUDE_DIRS}
58)
59
60find_library(WOLFSSL_LIBRARY NAMES "wolfssl"
61  HINTS
62    ${PC_WOLFSSL_LIBDIR}
63    ${PC_WOLFSSL_LIBRARY_DIRS}
64)
65
66if(PC_WOLFSSL_VERSION)
67  set(WOLFSSL_VERSION ${PC_WOLFSSL_VERSION})
68elseif(WOLFSSL_INCLUDE_DIR AND EXISTS "${WOLFSSL_INCLUDE_DIR}/wolfssl/version.h")
69  set(_version_regex "#[\t ]*define[\t ]+LIBWOLFSSL_VERSION_STRING[\t ]+\"([^\"]*)\"")
70  file(STRINGS "${WOLFSSL_INCLUDE_DIR}/wolfssl/version.h" _version_str REGEX "${_version_regex}")
71  string(REGEX REPLACE "${_version_regex}" "\\1" _version_str "${_version_str}")
72  set(WOLFSSL_VERSION "${_version_str}")
73  unset(_version_regex)
74  unset(_version_str)
75endif()
76
77include(FindPackageHandleStandardArgs)
78find_package_handle_standard_args(WolfSSL
79  REQUIRED_VARS
80    WOLFSSL_INCLUDE_DIR
81    WOLFSSL_LIBRARY
82  VERSION_VAR
83    WOLFSSL_VERSION
84)
85
86if(WOLFSSL_FOUND)
87  set(WOLFSSL_INCLUDE_DIRS ${WOLFSSL_INCLUDE_DIR})
88  set(WOLFSSL_LIBRARIES    ${WOLFSSL_LIBRARY})
89
90  if(NOT WIN32)
91    find_library(_math_library "m")
92    if(_math_library)
93      list(APPEND WOLFSSL_LIBRARIES "m")  # for log and pow
94    endif()
95  endif()
96endif()
97
98mark_as_advanced(WOLFSSL_INCLUDE_DIR WOLFSSL_LIBRARY)
99