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

@ -49,6 +49,13 @@ find_library(CARES_LIBRARY NAMES ${CARES_NAMES} "cares"
if(PC_CARES_VERSION)
set(CARES_VERSION ${PC_CARES_VERSION})
elseif(CARES_INCLUDE_DIR AND EXISTS "${CARES_INCLUDE_DIR}/ares_version.h")
set(_version_regex "#[\t ]*define[\t ]+ARES_VERSION_STR[\t ]+\"([^\"]*)\"")
file(STRINGS "${CARES_INCLUDE_DIR}/ares_version.h" _version_str REGEX "${_version_regex}")
string(REGEX REPLACE "${_version_regex}" "\\1" _version_str "${_version_str}")
set(CARES_VERSION "${_version_str}")
unset(_version_regex)
unset(_version_str)
endif()
include(FindPackageHandleStandardArgs)

View File

@ -47,7 +47,9 @@ find_library(LIBPSL_LIBRARY NAMES "psl" "libpsl"
${PC_LIBPSL_LIBRARY_DIRS}
)
if(LIBPSL_INCLUDE_DIR)
if(PC_LIBPSL_VERSION)
set(LIBPSL_VERSION ${PC_LIBPSL_VERSION})
elseif(LIBPSL_INCLUDE_DIR)
file(STRINGS "${LIBPSL_INCLUDE_DIR}/libpsl.h" _libpsl_version_str REGEX "^#define[\t ]+PSL_VERSION[\t ]+\"(.*)\"")
string(REGEX REPLACE "^.*\"([^\"]+)\"" "\\1" LIBPSL_VERSION "${_libpsl_version_str}")
unset(_libpsl_version_str)

View File

@ -47,7 +47,9 @@ find_library(LIBSSH2_LIBRARY NAMES "ssh2" "libssh2"
${PC_LIBSSH2_LIBRARY_DIRS}
)
if(LIBSSH2_INCLUDE_DIR)
if(PC_LIBSSH2_VERSION)
set(LIBSSH2_VERSION ${PC_LIBSSH2_VERSION})
elseif(LIBSSH2_INCLUDE_DIR)
file(STRINGS "${LIBSSH2_INCLUDE_DIR}/libssh2.h" _libssh2_version_str REGEX "^#define[\t ]+LIBSSH2_VERSION[\t ]+\"(.*)\"")
string(REGEX REPLACE "^.*\"([^\"]+)\"" "\\1" LIBSSH2_VERSION "${_libssh2_version_str}")
unset(_libssh2_version_str)

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)

View File

@ -49,6 +49,13 @@ find_library(NGHTTP2_LIBRARY NAMES "nghttp2" "nghttp2_static"
if(PC_NGHTTP2_VERSION)
set(NGHTTP2_VERSION ${PC_NGHTTP2_VERSION})
elseif(NGHTTP2_INCLUDE_DIR AND EXISTS "${NGHTTP2_INCLUDE_DIR}/nghttp2/nghttp2ver.h")
set(_version_regex "#[\t ]*define[\t ]+NGHTTP2_VERSION[\t ]+\"([^\"]*)\"")
file(STRINGS "${NGHTTP2_INCLUDE_DIR}/nghttp2/nghttp2ver.h" _version_str REGEX "${_version_regex}")
string(REGEX REPLACE "${_version_regex}" "\\1" _version_str "${_version_str}")
set(NGHTTP2_VERSION "${_version_str}")
unset(_version_regex)
unset(_version_str)
endif()
include(FindPackageHandleStandardArgs)

View File

@ -49,6 +49,13 @@ find_library(NGHTTP3_LIBRARY NAMES "nghttp3"
if(PC_NGHTTP3_VERSION)
set(NGHTTP3_VERSION ${PC_NGHTTP3_VERSION})
elseif(NGHTTP3_INCLUDE_DIR AND EXISTS "${NGHTTP3_INCLUDE_DIR}/nghttp3/version.h")
set(_version_regex "#[\t ]*define[\t ]+NGHTTP3_VERSION[\t ]+\"([^\"]*)\"")
file(STRINGS "${NGHTTP3_INCLUDE_DIR}/nghttp3/version.h" _version_str REGEX "${_version_regex}")
string(REGEX REPLACE "${_version_regex}" "\\1" _version_str "${_version_str}")
set(NGHTTP3_VERSION "${_version_str}")
unset(_version_regex)
unset(_version_str)
endif()
include(FindPackageHandleStandardArgs)

View File

@ -57,6 +57,13 @@ find_library(NGTCP2_LIBRARY NAMES "ngtcp2"
if(PC_NGTCP2_VERSION)
set(NGTCP2_VERSION ${PC_NGTCP2_VERSION})
elseif(NGTCP2_INCLUDE_DIR AND EXISTS "${NGTCP2_INCLUDE_DIR}/ngtcp2/version.h")
set(_version_regex "#[\t ]*define[\t ]+NGTCP2_VERSION[\t ]+\"([^\"]*)\"")
file(STRINGS "${NGTCP2_INCLUDE_DIR}/ngtcp2/version.h" _version_str REGEX "${_version_regex}")
string(REGEX REPLACE "${_version_regex}" "\\1" _version_str "${_version_str}")
set(NGTCP2_VERSION "${_version_str}")
unset(_version_regex)
unset(_version_str)
endif()
if(NGTCP2_FIND_COMPONENTS)

View File

@ -47,7 +47,9 @@ find_library(WolfSSL_LIBRARY NAMES "wolfssl"
${PC_WOLFSSL_LIBRARY_DIRS}
)
if(WolfSSL_INCLUDE_DIR)
if(PC_WOLFSSL_VERSION)
set(WolfSSL_VERSION ${PC_WOLFSSL_VERSION})
elseif(WolfSSL_INCLUDE_DIR)
set(_version_regex "^#define[ \t]+LIBWOLFSSL_VERSION_STRING[ \t]+\"([^\"]+)\".*")
file(STRINGS "${WolfSSL_INCLUDE_DIR}/wolfssl/version.h" WolfSSL_VERSION REGEX "${_version_regex}")
string(REGEX REPLACE "${_version_regex}" "\\1" WolfSSL_VERSION "${WolfSSL_VERSION}")

View File

@ -47,7 +47,9 @@ find_library(Zstd_LIBRARY NAMES "zstd"
${PC_Zstd_LIBRARY_DIRS}
)
if(Zstd_INCLUDE_DIR)
if(PC_ZSTD_VERSION)
set(Zstd_VERSION ${PC_ZSTD_VERSION})
elseif(Zstd_INCLUDE_DIR)
file(READ "${Zstd_INCLUDE_DIR}/zstd.h" _zstd_header)
string(REGEX MATCH ".*define ZSTD_VERSION_MAJOR *([0-9]+).*define ZSTD_VERSION_MINOR *([0-9]+).*define ZSTD_VERSION_RELEASE *([0-9]+)" _zstd_ver "${_zstd_header}")
set(Zstd_VERSION "${CMAKE_MATCH_1}.${CMAKE_MATCH_2}.${CMAKE_MATCH_3}")