/
niceSOFT
/
libssh2
Обзор
Документация
Войти
/
niceSOFT
/
libssh2
Код
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
cmake/FindMbedTLS.cmake
101 строка
4 KB
Viktor Szakats
cmake: add CMake Config-based dependency detection for mbedTLS, wolfSSL
09 июл 2026, 15:47
09 июл 2026, 15:47
86dcc0a
Код
Авторство
О чём код?
# Copyright (C) The libssh2 project and its contributors. # SPDX-License-Identifier: BSD-3-Clause # ########################################################################### # Find the mbedTLS library # # Input variables: # # - `MBEDTLS_INCLUDE_DIR`: Absolute path to mbedTLS include directory. # - `MBEDCRYPTO_LIBRARY`: Absolute path to `mbedcrypto` library. # - `MBEDTLS_USE_STATIC_LIBS`: Configure for static mbedTLS libraries. # # Defines: # # - `MBEDTLS_FOUND`: System has mbedTLS. # - `MBEDTLS_VERSION`: Version of mbedTLS. # - `libssh2::mbedcrypto`: mbedcrypto library target. set(_mbedtls_pc_requires "mbedcrypto") if(NOT DEFINED MBEDTLS_INCLUDE_DIR AND NOT DEFINED MBEDCRYPTO_LIBRARY) if(LIBSSH2_USE_PKGCONFIG) find_package(PkgConfig QUIET) pkg_check_modules(_mbedtls ${_mbedtls_pc_requires}) endif() if(NOT _mbedtls_FOUND AND LIBSSH2_USE_CMAKECONFIG) find_package(MbedTLS CONFIG QUIET) endif() endif() if(_mbedtls_FOUND) set(MbedTLS_FOUND TRUE) set(MBEDTLS_FOUND TRUE) set(MBEDTLS_VERSION ${_mbedtls_VERSION}) if(MBEDTLS_USE_STATIC_LIBS) set(_mbedtls_CFLAGS "${_mbedtls_STATIC_CFLAGS}") set(_mbedtls_INCLUDE_DIRS "${_mbedtls_STATIC_INCLUDE_DIRS}") set(_mbedtls_LIBRARY_DIRS "${_mbedtls_STATIC_LIBRARY_DIRS}") set(_mbedtls_LIBRARIES "${_mbedtls_STATIC_LIBRARIES}") endif() message(STATUS "Found MbedTLS (via pkg-config): ${_mbedtls_INCLUDE_DIRS} (found version \"${MBEDTLS_VERSION}\")") elseif(MbedTLS_CONFIG) set(MbedTLS_FOUND TRUE) set(MBEDTLS_FOUND TRUE) set(MBEDTLS_VERSION ${MbedTLS_VERSION}) if(MBEDTLS_VERSION GREATER_EQUAL 4.0.0) set(_mbedtls_LIBRARIES MbedTLS::tfpsacrypto) else() set(_mbedtls_LIBRARIES MbedTLS::mbedcrypto) endif() list(APPEND _mbedtls_LIBRARIES MbedTLS::mbedx509 MbedTLS::mbedtls) message(STATUS "Found MbedTLS (via CMake Config): ${MbedTLS_CONFIG} (found version \"${MBEDTLS_VERSION}\")") else() set(_mbedtls_pc_requires "") find_path(MBEDTLS_INCLUDE_DIR NAMES "mbedtls/version.h") if(MBEDTLS_USE_STATIC_LIBS) find_library(MBEDCRYPTO_LIBRARY NAMES "mbedcrypto_static" "libmbedcrypto_static" "mbedcrypto" "libmbedcrypto") else() find_library(MBEDCRYPTO_LIBRARY NAMES "mbedcrypto" "libmbedcrypto") endif() unset(MBEDTLS_VERSION CACHE) if(MBEDTLS_INCLUDE_DIR AND EXISTS "${MBEDTLS_INCLUDE_DIR}/mbedtls/build_info.h") set(_version_regex "#[\t ]*define[\t ]+MBEDTLS_VERSION_STRING[\t ]+\"([0-9.]+)\"") file(STRINGS "${MBEDTLS_INCLUDE_DIR}/mbedtls/build_info.h" _version_str REGEX "${_version_regex}") string(REGEX REPLACE "${_version_regex}" "\\1" _version_str "${_version_str}") set(MBEDTLS_VERSION "${_version_str}") unset(_version_regex) unset(_version_str) endif() include(FindPackageHandleStandardArgs) find_package_handle_standard_args(MbedTLS REQUIRED_VARS MBEDTLS_INCLUDE_DIR MBEDCRYPTO_LIBRARY VERSION_VAR MBEDTLS_VERSION ) if(MBEDTLS_FOUND) set(_mbedtls_INCLUDE_DIRS ${MBEDTLS_INCLUDE_DIR}) set(_mbedtls_LIBRARIES ${MBEDCRYPTO_LIBRARY}) endif() mark_as_advanced(MBEDTLS_INCLUDE_DIR MBEDCRYPTO_LIBRARY) endif() if(MBEDTLS_FOUND) if(NOT TARGET libssh2::mbedcrypto) add_library(libssh2::mbedcrypto INTERFACE IMPORTED) set_target_properties(libssh2::mbedcrypto PROPERTIES INTERFACE_LIBSSH2_PC_MODULES "${_mbedtls_pc_requires}" INTERFACE_COMPILE_OPTIONS "${_mbedtls_CFLAGS}" INTERFACE_INCLUDE_DIRECTORIES "${_mbedtls_INCLUDE_DIRS}" INTERFACE_LINK_DIRECTORIES "${_mbedtls_LIBRARY_DIRS}" INTERFACE_LINK_LIBRARIES "${_mbedtls_LIBRARIES}") endif() endif()