aboutsummaryrefslogtreecommitdiff
path: root/src/supplemental/tls/wolfssl/CMakeLists.txt
blob: 7b129d9c52ee83d06301ec04e73d115d089e3c29 (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
67
68
69
70
71
72
73
74
75
76
#
# Copyright 2025 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.
#
include(FindThreads)

if (NNG_TLS_ENGINE STREQUAL "wolf")
    message(NOTICE "
        ************************************************************
        Linking against WolfSSL may change license terms.
        Consult a lawyer and the license files for details.
        ************************************************************")
    nng_sources(wolfssl.c)

    # If wolfSSL was added by a consuming project, then we should use that
    # instance of it, instead of configuring our own.
    if (TARGET wolfssl)
        nng_link_libraries(wolfssl)
    else()
        # We want to prefer config mode over our local find package.
        if (NOT (DEFINED CMAKE_FIND_PACKAGE_PREFER_CONFIG))
            set(CMAKE_FIND_PACKAGE_PREFER_CONFIG TRUE)
            nng_find_package(wolfSSL)
            unset(CMAKE_FIND_PACKAGE_PREFER_CONFIG)
        else()
            nng_find_package(wolfSSL)
        endif()
        nng_link_libraries_public(wolfssl::wolfssl)
    endif()

    check_library_exists(wolfssl::wolfssl wolfSSL_CTX_LoadCRLBuffer "" NNG_WOLFSSL_HAVE_CRL)
    check_library_exists(wolfssl::wolfssl wolfSSL_get_verify_result "" NNG_WOLFSSL_HAVE_VERIFY)
    check_library_exists(wolfssl::wolfssl wolfSSL_CTX_set_default_passwd_cb "" NNG_WOLFSSL_HAVE_PASSWORD)
    check_library_exists(wolfssl::wolfssl wolfSSL_get_peer_certificate "" NNG_WOLFSSL_HAVE_PEER_CERT)
    check_library_exists(wolfssl::wolfssl wolfSSL_CTX_SetTmpDH "" NNG_WOLFSSL_HAVE_DH)
    check_library_exists(wolfssl::wolfssl wolfSSL_CTX_set_psk_client_callback "" NNG_WOLFSSL_HAVE_PSK)

    if (NNG_WOLFSSL_HAVE_DH)
        nng_defines(NNG_WOLFSSL_HAVE_DH)
    else ()
        message(STATUS "wolfSSL configured without DH support.")
    endif ()

    if (NNG_WOLFSSL_HAVE_CRL)
        nng_defines(NNG_WOLFSSL_HAVE_CRL)
    else ()
        message(STATUS "wolfSSL configured without CRL support.")
    endif ()

    if (NNG_WOLFSSL_HAVE_PASSWORD)
        nng_defines(NNG_WOLFSSL_HAVE_PASSWORD)
    else ()
        message(STATUS "wolfSSL configured without password support.")
    endif ()

    if (NNG_WOLFSSL_HAVE_PEER_CERT)
        nng_defines(NNG_WOLFSSL_HAVE_PEER_CERT)
    else ()
        message(STATUS "wolfSSL configured without peer cert chain support.")
    endif ()

    if (NNG_WOLFSSL_HAVE_PSK)
        nng_defines(NNG_SUPP_TLS_PSK)
    else ()
        message(STATUS "wolfSSL configured without pre-shared key (PSK) support.")
    endif()

    nng_defines(NNG_TLS_ENGINE_INIT=nng_tls_engine_init_wolf)
    nng_defines(NNG_TLS_ENGINE_FINI=nng_tls_engine_fini_wolf)
    nng_defines(NNG_SUPP_TLS)
    nng_defines(NNG_TLS_ENGINE_WOLFSSL)
endif ()