diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0819234a..ec70b9ea 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -449,7 +449,7 @@ jobs: - name: 'mbedTLS' install: mbedtls configure: --with-crypto=mbedtls --with-libmbedcrypto-prefix=/usr/local/opt/mbedtls - cmake: -DCRYPTO_BACKEND=mbedTLS -DMBEDTLS_LIBRARY_DIR=/usr/local/opt/mbedtls/lib -DMBEDTLS_INCLUDE_DIR=/usr/local/opt/mbedtls/include + cmake: -DCRYPTO_BACKEND=mbedTLS -DMBEDTLS_INCLUDE_DIR=/usr/local/opt/mbedtls/include -DMBEDCRYPTO_LIBRARY=/usr/local/opt/mbedtls/lib/libmbedcrypto.a steps: - name: 'install packages' run: brew install automake ${{ matrix.crypto.install }} diff --git a/cmake/FindmbedTLS.cmake b/cmake/FindmbedTLS.cmake index 33da4546..18c9739d 100644 --- a/cmake/FindmbedTLS.cmake +++ b/cmake/FindmbedTLS.cmake @@ -2,46 +2,33 @@ # SPDX-License-Identifier: BSD-3-Clause # # - Try to find mbedTLS -# Once done this will define # -# Read-Only variables -# MBEDTLS_FOUND - system has mbedTLS +# Input variables: # MBEDTLS_INCLUDE_DIR - the mbedTLS include directory -# MBEDTLS_LIBRARY_DIR - the mbedTLS library directory -# MBEDTLS_LIBRARIES - Link these to use mbedTLS # MBEDCRYPTO_LIBRARY - path to mbedTLS Crypto library +# Output variables: +# MBEDTLS_FOUND - system has mbedTLS +# MBEDTLS_LIBRARIES - link these to use mbedTLS -find_path(MBEDTLS_INCLUDE_DIR mbedtls/version.h) -find_library(MBEDCRYPTO_LIBRARY mbedcrypto libmbedcrypto) +find_path(MBEDTLS_INCLUDE_DIR NAMES mbedtls/version.h) +find_library(MBEDCRYPTO_LIBRARY NAMES mbedcrypto libmbedcrypto) -if(MBEDTLS_INCLUDE_DIR AND MBEDTLS_LIBRARIES) - # Already in cache, be silent - set(MBEDTLS_FIND_QUIETLY TRUE) +if(MBEDTLS_INCLUDE_DIR) + file(READ "${MBEDTLS_INCLUDE_DIR}/mbedtls/build_info.h" _mbedtls_header_1) + file(READ "${MBEDTLS_INCLUDE_DIR}/mbedtls/version.h" _mbedtls_header_2) + set(_mbedtls_regex "MBEDTLS_VERSION_STRING +\"([0-9|.]+)\"") + string(REGEX MATCH "${_mbedtls_regex}" _mbedtls_match "${_mbedtls_header_1} ${_mbedtls_header_2}") + string(REGEX REPLACE "${_mbedtls_regex}" "\\1" MBEDTLS_VERSION "${_mbedtls_match}") endif() -set(MBEDTLS_LIBRARIES "${MBEDCRYPTO_LIBRARY}") - include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(mbedTLS DEFAULT_MSG - MBEDTLS_INCLUDE_DIR MBEDCRYPTO_LIBRARY) +find_package_handle_standard_args(mbedTLS + REQUIRED_VARS MBEDTLS_INCLUDE_DIR MBEDCRYPTO_LIBRARY + VERSION_VAR MBEDTLS_VERSION) if(MBEDTLS_FOUND) - if(NOT MBEDTLS_FIND_QUIETLY) - file(READ "${MBEDTLS_INCLUDE_DIR}/mbedtls/build_info.h" mbedtls_header_1) - file(READ "${MBEDTLS_INCLUDE_DIR}/mbedtls/version.h" mbedtls_header_2) - string(REGEX MATCH "MBEDTLS_VERSION_STRING +\"[0-9|.]+\"" MBEDTLSMATCH "${mbedtls_header_1} ${mbedtls_header_2}") - if(MBEDTLSMATCH) - string(REGEX REPLACE "MBEDTLS_VERSION_STRING +\"([0-9|.]+)\"" "\\1" MBEDTLS_VERSION ${MBEDTLSMATCH}) - endif() - message(STATUS "Found mbedTLS crypto: ${MBEDCRYPTO_LIBRARY} (version \"${MBEDTLS_VERSION}\")") - endif() -elseif(MBEDTLS_FIND_REQUIRED) - message(FATAL_ERROR "Could not find mbedTLS") + set(MBEDTLS_LIBRARIES "${MBEDCRYPTO_LIBRARY}") + message(STATUS "Found mbedTLS libraries: ${MBEDTLS_LIBRARIES}") endif() -mark_as_advanced( - MBEDTLS_INCLUDE_DIR - MBEDTLS_LIBRARY_DIR - MBEDTLS_LIBRARIES - MBEDCRYPTO_LIBRARY -) +mark_as_advanced(MBEDTLS_INCLUDE_DIR MBEDCRYPTO_LIBRARY MBEDTLS_LIBRARIES)