From f48959f1347d97a9bf4d5edb4eb0c46e4101d356 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Sat, 27 Jan 2024 14:22:36 -0800 Subject: Mbed TLS CMake improvements. Try to use the Mbed TLS cmake configuration data if present, and refactor our FindModule to adhere to the same basic API. --- src/supplemental/tls/mbedtls/CMakeLists.txt | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'src/supplemental') diff --git a/src/supplemental/tls/mbedtls/CMakeLists.txt b/src/supplemental/tls/mbedtls/CMakeLists.txt index 2d639efa..fda226e5 100644 --- a/src/supplemental/tls/mbedtls/CMakeLists.txt +++ b/src/supplemental/tls/mbedtls/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright 2020 Staysail Systems, Inc. +# Copyright 2024 Staysail Systems, Inc. # # This software is supplied under the terms of the MIT License, a # copy of which should be located in the distribution where this @@ -10,7 +10,7 @@ if (NNG_TLS_ENGINE STREQUAL "mbed") message(WARNING " ************************************************************ - Linking against Mbed TLS changes license terms (Apache 2.0). + Linking against Mbed TLS may change license terms. Consult a lawyer and the license files for details. ************************************************************") nng_sources(tls.c) @@ -23,8 +23,17 @@ if (NNG_TLS_ENGINE STREQUAL "mbed") if (TARGET mbedtls) nng_link_libraries(mbedtls) else() - nng_find_package(mbedTLS) - nng_link_libraries(${MBEDTLS_LIBRARIES}) - nng_include_directories(${MBEDTLS_INCLUDE_DIR}) + # We want to prefer config mode over our local find package. + # mbedTLS v3 has a config file, which should work better than + # what we do here. We do restore the setting though because + # user applications might not expect this. + if (NOT CMAKE_FIND_PAKCAGE_PREFER_CONFIG) + set(CMAKE_FIND_PACKAGE_PREFER_CONFIG TRUE) + find_package(MbedTLS REQUIRED) + set(CMAKE_FIND_PACKAGE_PREFER_CONFIG FALSE) + else() + find_package(MbedTLS REQUIRED) + endif() + nng_link_libraries_public(MbedTLS::mbedtls MbedTLS::mbedcrypto MbedTLS::mbedx509) endif() endif() -- cgit v1.2.3-70-g09d2