From 0057e49a0d724c1abbe628145c470c55c361f955 Mon Sep 17 00:00:00 2001 From: Martchus Date: Wed, 7 Jun 2023 23:35:33 +0200 Subject: [PATCH] Fix linking against static OpenSSL on GNU/Linux Judging by the code the CMake find module actually attempts to cover this case but it doesn't seem to work in practice - at least not when there are only static libs and thus we find those static libs without explicitly specifying `OPENSSL_USE_STATIC_LIBS`. --- cmake/modules/3rdParty.cmake | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/cmake/modules/3rdParty.cmake b/cmake/modules/3rdParty.cmake index 92c31a9..b975368 100644 --- a/cmake/modules/3rdParty.cmake +++ b/cmake/modules/3rdParty.cmake @@ -157,6 +157,10 @@ macro (_cpp_utilities_use_openssl OPENSSL_TARGETS) message(STATUS "Unable to find OpenSSL") return() endif () + set(OPENSSL_IS_STATIC FALSE) + if (OPENSSL_CRYPTO_LIBRARY MATCHES ".*\\.a" OR OPENSSL_SSL_LIBRARY MATCHES ".*\\.a") + set(OPENSSL_IS_STATIC TRUE) + endif () foreach (OPENSSL_TARGET ${OPENSSL_TARGETS}) if (TARGET "${OPENSSL_TARGET}") continue() @@ -174,9 +178,14 @@ macro (_cpp_utilities_use_openssl OPENSSL_TARGETS) message(STATUS "Found required OpenSSL targets (${OPENSSL_TARGETS})") set("${ARGS_LIBRARIES_VARIABLE}" "${${ARGS_LIBRARIES_VARIABLE}};${OPENSSL_TARGETS}") - if (WIN32 AND OPENSSL_USE_STATIC_LIBS) - # FIXME: preferably use pkg-config to cover this case without hardcoding OpenSSL's dependencies under Windows - set("${ARGS_LIBRARIES_VARIABLE}" "${${ARGS_LIBRARIES_VARIABLE}};-lws2_32;-lgdi32;-lcrypt32") + + # add transitive dependencies for static OpenSSL libs as the CMake find module does not do a good job + if (OPENSSL_USE_STATIC_LIBS OR OPENSSL_IS_STATIC) + if (WIN32) + set("${ARGS_LIBRARIES_VARIABLE}" "${${ARGS_LIBRARIES_VARIABLE}};-lws2_32;-lgdi32;-lcrypt32") + elseif (LINUX) + set("${ARGS_LIBRARIES_VARIABLE}" "${${ARGS_LIBRARIES_VARIABLE}};-ldl") + endif () endif () set("${ARGS_PACKAGES_VARIABLE}" "${${ARGS_PACKAGES_VARIABLE}};OpenSSL"