From 622eea366aaf162479eaabd93c88fa04efe98bcc Mon Sep 17 00:00:00 2001 From: Jon Turney Date: Sat, 26 Oct 2019 17:12:26 +0100 Subject: [PATCH] meson: Add sha1 library options v2: Set the define for xha1.c programatically, rather than using loads of conditionals. --- include/meson.build | 2 +- meson.build | 92 +++++++++++++++++++++++++++++++++++++++++++-- meson_options.txt | 2 + 3 files changed, 92 insertions(+), 4 deletions(-) diff --git a/include/meson.build b/include/meson.build index 9ecfd15a4..ddac43473 100644 --- a/include/meson.build +++ b/include/meson.build @@ -229,7 +229,7 @@ conf_data.set('XV', build_xv) conf_data.set('XvExtension', build_xv) conf_data.set('XvMCExtension', build_xvmc) -conf_data.set('HAVE_SHA1_IN_LIBNETTLE', '1') # XXX +conf_data.set('HAVE_SHA1_IN_' + sha1.to_upper(), '1', description: 'Use @0@ SHA1 functions'.format(sha1)) conf_data.set('HAVE_APM', build_apm or build_acpi) conf_data.set('HAVE_ACPI', build_acpi) diff --git a/meson.build b/meson.build index 2eca5c295..7b14e2807 100644 --- a/meson.build +++ b/meson.build @@ -98,7 +98,6 @@ libbsd_dep = dependency('libbsd', required: false) xkbcomp_dep = dependency('xkbcomp', required: false) xkbfile_dep = dependency('xkbfile') xfont2_dep = dependency('xfont2', version: '>= 2.0') -nettle_dep = dependency('nettle') dbus_required = get_option('systemd_logind') == 'true' dbus_dep = dependency('dbus-1', version: '>= 1.0', required: dbus_required) @@ -343,8 +342,95 @@ else build_eglstream = false endif -# XXX: Add more sha1 options, because Linux is about choice -sha1_dep = nettle_dep +# Lots of sha1 options, because Linux is about choice :) + +# The idea behind the ordering here is that we should first prefer system +# builtin providers, and then smaller implementations of over larger ones. +test_sha1 = [ + 'libc', # libmd API is in libc on some BSDs + 'CommonCrypto', # darwin API + 'CryptoAPI', # windows API + 'libmd', # other BSDs & Solaris + 'libsha1', # "a tiny library providing a SHA1 implementation, created for facilitating X server compilation on embedded devices where larger libraries containing SHA1 implementations are not needed" + 'libnettle', + 'libgcrypt', # in debian base system + 'libcrypto', +] + +if get_option('sha1') != 'auto' + test_sha1 = [get_option('sha1')] +endif + +sha1_found = false +foreach t : test_sha1 + if t == 'libc' + if cc.has_function('SHA1Init') + sha1_found = true + sha1_dep = dependency('', required: false) + endif + elif t == 'CommonCrypto' + if cc.has_function('CC_SHA1_Init') + sha1_found = true + sha1_dep = dependency('', required: false) + endif + elif t == 'CryptoAPI' + if cc.has_header('wincrypt.h') + sha1_found = true + sha1_dep = dependency('', required: false) + endif + elif t == 'libmd' + md_dep = cc.find_library('md', required: false) + if md_dep.found() + sha1_found = true + sha1_dep = md_dep + endif + elif t == 'libsha1' + libsha1_dep = dependency('libsha1', required: false) + if libsha1_dep.found() + sha1_found = true + sha1_dep = libsha1_dep + endif + elif t == 'libnettle' + nettle_dep = dependency('nettle', required: false) + if nettle_dep.found() + sha1_found = true + sha1_dep = nettle_dep + endif + elif t == 'libgcrypt' + gcrypt_dep = dependency('libgcrypt', required: false) + if gcrypt_dep.found() + sha1_found = true + sha1_dep = gcrypt_dep + endif + elif t == 'libcrypto' + # we don't need all of OpenSSL, just libcrypto + libcrypto_dep = cc.find_library('crypto', required: false) + openssl_dep = dependency('openssl', required: false) + if libcrypto_dep.found() or openssl_dep.found() + sha1_found = true + if libcrypto_dep.found() + sha1_dep = libcrypto_dep + else + sha1_dep = openssl_dep + endif + endif + endif + + if sha1_found + sha1 = t + break + endif +endforeach + +if sha1_found + message('Using @0@ SHA1 functions'.format(sha1)) +else + if get_option('sha1') != 'auto' + error('@0@ SHA1 requested, but not found'.format(get_option('sha1'))) + else + error('No suitable SHA1 implementation found') + endif +endif xdmcp_dep = dependency('', required : false) if get_option('xdmcp') diff --git a/meson_options.txt b/meson_options.txt index 209587cd0..0f38fca8e 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -104,6 +104,8 @@ option('mitshm', type: 'combo', choices: ['true', 'false', 'auto'], value: 'auto description: 'SHM extension') option('agp', type: 'combo', choices: ['true', 'false', 'auto'], value: 'auto', description: 'AGP support') +option('sha1', type: 'combo', choices: ['libc', 'CommonCrypto', 'CryptoAPI', 'libmd', 'libsha1', 'libnettle', 'libgcrypt', 'libcrypto', 'auto'], value: 'auto', + description: 'SHA1 implementation') option('dri1', type: 'combo', choices: ['true', 'false', 'auto'], value: 'auto', description: 'Build DRI1 extension (default: auto)') option('dri2', type: 'combo', choices: ['true', 'false', 'auto'], value: 'auto', description: 'Build DRI2 extension (default: auto)')