diff --git a/meson.build b/meson.build index 5b97168..0a11c6b 100644 --- a/meson.build +++ b/meson.build @@ -39,11 +39,29 @@ endif deps = [dependency('threads')] args = [] -openssl_dep = dependency('openssl', version: '>=3.0.0', required: get_option('openssl')) -if openssl_dep.found() - deps += openssl_dep - args += '-DCPPHTTPLIB_OPENSSL_SUPPORT' - if host_machine.system() == 'darwin' +if get_option('tls').allowed() + tls_found = false + if get_option('tls_backend') == 'openssl' + openssl_dep = dependency('openssl', version: '>=3.0.0', required: get_option('tls')) + if openssl_dep.found() + deps += openssl_dep + args += '-DCPPHTTPLIB_OPENSSL_SUPPORT' + tls_found = true + endif + else + mbedtls_dep = dependency('mbedtls', required: get_option('tls')) + mbedtlsx509_dep = dependency('mbedx509', required: get_option('tls')) + mbedtlscrypto_dep = dependency('mbedcrypto', required: get_option('tls')) + if mbedtls_dep.found() and mbedtlsx509_dep.found() and mbedtlscrypto_dep.found() + deps += mbedtls_dep + deps += mbedtlsx509_dep + deps += mbedtlscrypto_dep + args += '-DCPPHTTPLIB_MBEDTLS_SUPPORT' + tls_found = true + endif + endif + + if tls_found and host_machine.system() == 'darwin' macosx_keychain_dep = dependency('appleframeworks', modules: ['CFNetwork', 'CoreFoundation', 'Security'], required: get_option('macosx_keychain')) if macosx_keychain_dep.found() deps += macosx_keychain_dep diff --git a/meson_options.txt b/meson_options.txt index 7447d8d..05c4e19 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -2,7 +2,8 @@ # # SPDX-License-Identifier: MIT -option('openssl', type: 'feature', value: 'auto', description: 'Enable OpenSSL support') +option('tls', type: 'feature', description: 'Enable TLS support') +option('tls_backend', type: 'combo', choices: ['openssl', 'mbedtls'], value: 'openssl', description: 'Which TLS library to use') option('zlib', type: 'feature', value: 'auto', description: 'Enable zlib support') option('brotli', type: 'feature', value: 'auto', description: 'Enable Brotli support') option('zstd', type: 'feature', value: 'auto', description: 'Enable zstd support') @@ -12,6 +13,7 @@ option('compile', type: 'boolean', value: false, description: 'Split the header option('test', type: 'boolean', value: false, description: 'Build tests') # Old option names +option('openssl', type: 'feature', deprecated: 'tls') option('cpp-httplib_openssl', type: 'feature', deprecated: 'openssl') option('cpp-httplib_zlib', type: 'feature', deprecated: 'zlib') option('cpp-httplib_brotli', type: 'feature', deprecated: 'brotli')