cmake: add missing version detection to Find modules

- use `pkg-config` version when available and where it wasn't yet used.

- add manual version detection for dependencies where this is possible
  (via a public header) and where it wasn't done yet.

Closes #14548
This commit is contained in:
Viktor Szakats 2024-08-13 22:59:50 +02:00
parent 2bea3892e7
commit 4e2f3641f8
No known key found for this signature in database
GPG key ID: B5ABD165E2AEF201
9 changed files with 57 additions and 4 deletions

View file

@ -65,6 +65,23 @@ find_library(MBEDCRYPTO_LIBRARY "mbedcrypto"
if(PC_MBEDTLS_VERSION)
set(MBEDTLS_VERSION ${PC_MBEDTLS_VERSION})
elseif(MBEDTLS_INCLUDE_DIR)
if(EXISTS "${MBEDTLS_INCLUDE_DIR}/mbedtls/build_info.h") # 3.x
set(_version_header "${MBEDTLS_INCLUDE_DIR}/mbedtls/build_info.h")
elseif(EXISTS "${MBEDTLS_INCLUDE_DIR}/mbedtls/version.h") # 2.x
set(_version_header "${MBEDTLS_INCLUDE_DIR}/mbedtls/version.h")
else()
unset(_version_header)
endif()
if(_version_header)
set(_version_regex "#[\t ]*define[\t ]+MBEDTLS_VERSION_STRING[\t ]+\"([0-9.]+)\"")
file(STRINGS "${_version_header}" _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)
unset(_version_header)
endif()
endif()
include(FindPackageHandleStandardArgs)