aboutsummaryrefslogtreecommitdiff
path: root/cmake/FindwolfSSL.cmake
blob: c15b3abf41c3e31882524893b77956c91dfce72d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#
# Copyright 2024 Staysail Systems, Inc. <info@staysail.tech>
#
# This software is supplied under the terms of the MIT License, a
# copy of which should be located in the distribution where this
# file was obtained (LICENSE.txt).  A copy of the license may also be
# found online at https://opensource.org/licenses/MIT.
#

#
# Try to find the wolfSSL library.  We only support modern wolfSSL,
# not the older CyaSSL.
#
# Sets the following:
#
#  WOLFSSL_INCLUDE_DIR  - Where to find wolfssl/ssl.h, etc.
#  WOLFSSL_FOUND        - True if we found wolfSSL.
#  WOLFSSL_LIBRARIES    - The wolfSSL library (libwolfssl).
#  WOLFSSL_LIBRARY      - The wolfSSL library (libwolfssl).
#  WOLFSSL_VERSION      - $major.$minor.$revision (e.g. ``3.13.0``).
#
# Adds wolfSSL::wolfssl target for the library.
#
# Hints:
#
# Set ``WOLFSSL_ROOT_DIR`` to the root directory of wolfSSL installation.
#

set(_WOLFSSL_ROOT_HINTS ${WOLFSSL_ROOT_DIR} ENV WOLFSSL_ROOT_DIR)

include(FindPackageHandleStandardArgs)
include(CMakePushCheckState)

find_path(WOLFSSL_INCLUDE_DIR
    NAMES wolfssl/ssl.h
    HINTS ${_WOLFSSL_ROOT_HINTS}
    PATHS /usr/local
    PATH_SUFFIXES include)

find_library(WOLFSSL_LIBRARY
    NAMES wolfssl
    HINTS ${_WOLFSSL_ROOT_HINTS}
    PATHS /usr/local
    PATH_SUFFIXES lib)

set(WOLFSSL_LIBRARIES ${WOLFSSL_LIBRARY})
if (${WOLFSSL_LIBRARY-NOTFOUND})
    message(FATAL_ERROR "Failed to find wolfSSL library")
endif()

mark_as_advanced(WOLFSSL_INCLUDE_DIR WOLFSSL_LIBRARY)

# Extract the version from the header... hopefully it matches the library.
file(STRINGS ${WOLFSSL_INCLUDE_DIR}/wolfssl/version.h _WOLFSSL_VERLINE
    REGEX "^#define[ \t]+LIBWOLFSSL_VERSION_STRING[\t ].*")
string(REGEX REPLACE ".*WOLFSSL_VERSION_STRING[\t ]+\"(.*)\"" "\\1" WOLFSSL_VERSION ${_WOLFSSL_VERLINE})

add_library(wolfSSL::wolfssl UNKNOWN IMPORTED)

set_target_properties(wolfSSL::wolfssl PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${WOLFSSL_INCLUDE_DIR}")
set_target_properties(wolfSSL::wolfssl PROPERTIES IMPORTED_LOCATION "${WOLFSSL_LIBRARY}")

set(wolfSSL_TARGET wolfssl::wolfssl)

find_package_handle_standard_args(wolfSSL
    REQUIRED_VARS WOLFSSL_LIBRARY WOLFSSL_INCLUDE_DIR VERSION_VAR WOLFSSL_VERSION)