From 549f957696ecc0e93f9d6f377927001928b7225e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Cr=C3=AAte?= Date: Thu, 1 Aug 2019 18:57:43 -0400 Subject: meson: Add non-pkgconfig test for OpenSSL This makes it work with Windows MSVC builds of OpenSSL which don't include a pkg-config file. --- meson.build | 55 ++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 44 insertions(+), 11 deletions(-) diff --git a/meson.build b/meson.build index 20da9a3..42c0816 100644 --- a/meson.build +++ b/meson.build @@ -186,32 +186,65 @@ gthread_dep = dependency('gthread-2.0', # Cryto library opt_cryptolib = get_option('crypto-library') -message('Crypto library: ' + opt_cryptolib) +message('Crypto librar requested: ' + opt_cryptolib) if opt_cryptolib != 'openssl' crypto_dep = dependency('gnutls', version: gnutls_req, required: false) cdata.set('HAVE_GNUTLS', crypto_dep.found()) - if not crypto_dep.found() - if opt_cryptolib != 'auto' - error('GnuTLS requested as crypto library, but not found') - endif - crypto_dep = dependency('openssl', required: false, + if not crypto_dep.found() and opt_cryptolib == 'auto' + crypto_dep = dependency('openssl', required: false, fallback: ['openssl', 'openssl_dep']) cdata.set('HAVE_OPENSSL', crypto_dep.found()) endif else crypto_dep = dependency('openssl', required: false) cdata.set('HAVE_OPENSSL', crypto_dep.found()) - if not crypto_dep.found() - if opt_cryptolib != 'auto' - error('OpenSSL requested as crypto library, but not found') - endif + if not crypto_dep.found() and openssl == 'auto' crypto_dep = dependency('gnutls', version: gnutls_req, required: false) cdata.set('HAVE_GNUTLS', crypto_dep.found()) endif endif +if not crypto_dep.found() and opt_cryptolib != 'gnutls' + # MSVC builds of OpenSSL does not generate pkg-config files, + # so we check for it manually here in this case, if we can't find those files + # Based on the CMake check for OpenSSL in CURL's CMakeLists.txt, + # on which headers we should check for + openssl_headers = [] + foreach h : ['crypto.h', 'engine.h', 'err.h', 'pem.h', + 'rsa.h', 'ssl.h', 'x509.h', 'rand.h', 'tls1.h'] + openssl_headers += 'openssl/' + h + endforeach + + # OpenSSL 1.1.x and 1.0.x (or earlier) have different .lib names, + # so we need to look for the correct pair + + # Find either libcrypto.lib (1.1.x) or libeay32.lib (1.0.x or earlier) first + libcrypto_dep = cc.find_library('crypto', required: false) + if libcrypto_dep.found() + libssl = 'ssl' + else + libcrypto_dep = cc.find_library('eay32', required: false) + libssl = 'ssleay32' + endif + + if libcrypto_dep.found() + # Find the corresponding SSL library depending on which crypto .lib we found + libssl_dep = cc.find_library(libssl, required: false, has_headers: openssl_headers) + endif + + if libcrypto_dep.found() and libssl_dep.found() + crypto_dep = [libcrypto_dep, libssl_dep] + endif +endif + if not crypto_dep.found() - error('Either GnuTLS or OpenSSL is required as crypto library, but neither was found') + if opt_cryptolib == 'gnutls' + error('GnuTLS requested as crypto library, but not found') + elif opt_cryptolib == 'gnutls' + error('OpenSSL requested as crypto library, but not found') + else + error('Either GnuTLS or OpenSSL is required as crypto library, but neither was found') + endif endif # GStreamer -- cgit v1.2.1