summaryrefslogtreecommitdiff
path: root/meson.build
diff options
context:
space:
mode:
authorJon Turney <jon.turney@dronecode.org.uk>2019-10-26 17:12:26 +0100
committerAdam Jackson <ajax@nwnk.net>2019-10-30 16:58:39 +0000
commit622eea366aaf162479eaabd93c88fa04efe98bcc (patch)
treede58f08178e98c9f026adf4c3a27f83a4a1cde0d /meson.build
parent417e4553f143820acc33998898bbd5c3d4567bcd (diff)
meson: Add sha1 library options
v2: Set the define for xha1.c programatically, rather than using loads of conditionals.
Diffstat (limited to 'meson.build')
-rw-r--r--meson.build92
1 files changed, 89 insertions, 3 deletions
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')