1
0
mirror of https://github.com/libssh2/libssh2.git synced 2025-10-29 00:54:50 +03:00

cmake: cleanup mbedTLS version detection more

- lowercase, underscored local variables.
- fix `find_library()` to use the multiple names passed.
- rely more on `find_package_handle_standard_args()`.
  Logic based on our `Findwolfssl.cmake`.
- delete ignored/unused `MBEDTLS_LIBRARY_DIR`.
- revert CI configuration to use `MBEDCRTYPO_LIBRARY`.
- clarify inputs/outputs in comment header.
- use variable for regex.
- formatting.

Follow-up to 4159467507 #1192

Closes #1196
This commit is contained in:
Viktor Szakats
2023-09-29 09:27:34 +00:00
parent 30eef0a630
commit 4c241d5c65
2 changed files with 19 additions and 32 deletions

View File

@@ -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 }}

View File

@@ -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)