mirror of
https://github.com/libssh2/libssh2.git
synced 2025-10-30 12:05:34 +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:
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
@@ -449,7 +449,7 @@ jobs:
|
|||||||
- name: 'mbedTLS'
|
- name: 'mbedTLS'
|
||||||
install: mbedtls
|
install: mbedtls
|
||||||
configure: --with-crypto=mbedtls --with-libmbedcrypto-prefix=/usr/local/opt/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:
|
steps:
|
||||||
- name: 'install packages'
|
- name: 'install packages'
|
||||||
run: brew install automake ${{ matrix.crypto.install }}
|
run: brew install automake ${{ matrix.crypto.install }}
|
||||||
|
|||||||
@@ -2,46 +2,33 @@
|
|||||||
# SPDX-License-Identifier: BSD-3-Clause
|
# SPDX-License-Identifier: BSD-3-Clause
|
||||||
#
|
#
|
||||||
# - Try to find mbedTLS
|
# - Try to find mbedTLS
|
||||||
# Once done this will define
|
|
||||||
#
|
#
|
||||||
# Read-Only variables
|
# Input variables:
|
||||||
# MBEDTLS_FOUND - system has mbedTLS
|
|
||||||
# MBEDTLS_INCLUDE_DIR - the mbedTLS include directory
|
# 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
|
# 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_path(MBEDTLS_INCLUDE_DIR NAMES mbedtls/version.h)
|
||||||
find_library(MBEDCRYPTO_LIBRARY mbedcrypto libmbedcrypto)
|
find_library(MBEDCRYPTO_LIBRARY NAMES mbedcrypto libmbedcrypto)
|
||||||
|
|
||||||
if(MBEDTLS_INCLUDE_DIR AND MBEDTLS_LIBRARIES)
|
if(MBEDTLS_INCLUDE_DIR)
|
||||||
# Already in cache, be silent
|
file(READ "${MBEDTLS_INCLUDE_DIR}/mbedtls/build_info.h" _mbedtls_header_1)
|
||||||
set(MBEDTLS_FIND_QUIETLY TRUE)
|
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()
|
endif()
|
||||||
|
|
||||||
set(MBEDTLS_LIBRARIES "${MBEDCRYPTO_LIBRARY}")
|
|
||||||
|
|
||||||
include(FindPackageHandleStandardArgs)
|
include(FindPackageHandleStandardArgs)
|
||||||
find_package_handle_standard_args(mbedTLS DEFAULT_MSG
|
find_package_handle_standard_args(mbedTLS
|
||||||
MBEDTLS_INCLUDE_DIR MBEDCRYPTO_LIBRARY)
|
REQUIRED_VARS MBEDTLS_INCLUDE_DIR MBEDCRYPTO_LIBRARY
|
||||||
|
VERSION_VAR MBEDTLS_VERSION)
|
||||||
|
|
||||||
if(MBEDTLS_FOUND)
|
if(MBEDTLS_FOUND)
|
||||||
if(NOT MBEDTLS_FIND_QUIETLY)
|
set(MBEDTLS_LIBRARIES "${MBEDCRYPTO_LIBRARY}")
|
||||||
file(READ "${MBEDTLS_INCLUDE_DIR}/mbedtls/build_info.h" mbedtls_header_1)
|
message(STATUS "Found mbedTLS libraries: ${MBEDTLS_LIBRARIES}")
|
||||||
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")
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
mark_as_advanced(
|
mark_as_advanced(MBEDTLS_INCLUDE_DIR MBEDCRYPTO_LIBRARY MBEDTLS_LIBRARIES)
|
||||||
MBEDTLS_INCLUDE_DIR
|
|
||||||
MBEDTLS_LIBRARY_DIR
|
|
||||||
MBEDTLS_LIBRARIES
|
|
||||||
MBEDCRYPTO_LIBRARY
|
|
||||||
)
|
|
||||||
|
|||||||
Reference in New Issue
Block a user