Skip to content

Commit

Permalink
CMake: Switch to pkg_search_module for SSL library lookup
Browse files Browse the repository at this point in the history
OpenSSL comes with pkg-config information in all
supported versions. MbedTLS only has pkg-config since
version 3.0.

In any case pkg-config is usually the preferable way
to look up library information, since that gives us
a much more standardized lookup instead of find_package.

Fedora maintainer did go a special way by not letting
mbedtls 3.x conflict with mbedtls 2.x or even other
3.x versions, so this complicates the lookup further.

Signed-off-by: Frank Lichtenheld <[email protected]>
  • Loading branch information
flichtenheld authored and Jenkins-dev committed Feb 6, 2025
1 parent d6798c3 commit b130db4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
3 changes: 2 additions & 1 deletion CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"value": "ON",
"type": "BOOL"
},
"VCPKG_MANIFEST_DIR": "${sourceDir}/deps/vcpkg_manifests/windows"
"VCPKG_MANIFEST_DIR": "${sourceDir}/deps/vcpkg_manifests/windows",
"VCPKG_HOST_TRIPLET": "x64-windows"
},
"vendor": {
"microsoft.com/VisualStudioSettings/CMake/1.0": {
Expand Down
19 changes: 15 additions & 4 deletions cmake/findcoredeps.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,24 @@ else ()
endif ()

function(add_ssl_library target)
find_package(PkgConfig REQUIRED)
if (${USE_MBEDTLS})
find_package(mbedTLS REQUIRED)
set(SSL_LIBRARY mbedTLS::mbedTLS)
# mbedtls3.6 for Fedora 41+
pkg_search_module(mbedTLS IMPORTED_TARGET mbedtls3.6 mbedtls)
if (mbedTLS_FOUND)
# Only added as Requires.Private, so we need to look them up ourselves
pkg_search_module(mbedCrypto REQUIRED IMPORTED_TARGET mbedcrypto3.6 mbedcrypto)
pkg_search_module(mbedX509 REQUIRED IMPORTED_TARGET mbedx5093.6 mbedx509)
set(SSL_LIBRARY PkgConfig::mbedTLS PkgConfig::mbedCrypto PkgConfig::mbedX509)
else ()
# mbedTLS 2.x doesn't have pkg-config files
find_package(mbedTLS REQUIRED)
set(SSL_LIBRARY mbedTLS::mbedTLS)
endif ()
target_compile_definitions(${target} PRIVATE -DUSE_MBEDTLS)
else ()
find_package(OpenSSL REQUIRED)
SET(SSL_LIBRARY OpenSSL::SSL)
pkg_search_module(OpenSSL REQUIRED IMPORTED_TARGET openssl)
SET(SSL_LIBRARY PkgConfig::OpenSSL)
target_compile_definitions(${target} PRIVATE -DUSE_OPENSSL)
endif ()

Expand Down
6 changes: 5 additions & 1 deletion deps/vcpkg_manifests/windows/vcpkg.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
"lz4",
"openssl",
"tap-windows6",
"xxhash"
"xxhash",
{
"name": "pkgconf",
"host": true
}
]
}

0 comments on commit b130db4

Please sign in to comment.