commit f01e01026405973e6eca581d76e580e0c913f60c
parent 6ad98aa699ad8f265234ad727b7eda9fd9cbaa3d
Author: Florian Dold <florian@dold.me>
Date: Wed, 21 Dec 2022 14:03:58 +0100
build system
Diffstat:
1 file changed, 110 insertions(+), 3 deletions(-)
diff --git a/subprojects/libsodium/meson.build b/subprojects/libsodium/meson.build
@@ -1,18 +1,100 @@
project('libsodium', 'c',
default_options : [
- 'warning_level=0']
+ 'warning_level=0',
+ 'optimization=3',
+ ]
)
+fs = import('fs')
+
+c_compiler = meson.get_compiler('c')
+
+compile_args = []
+
+# passed to (some) compiler checks
+check_args = []
+
add_project_arguments('-D_GNU_SOURCE', language: 'c')
if host_machine.endian() == 'little'
add_project_arguments('-DNATIVE_LITTLE_ENDIAN', language: 'c')
+ check_args += '-DNATIVE_LITTLE_ENDIAN'
else
add_project_arguments('-DNATIVE_BIG_ENDIAN', language: 'c')
+ check_args += '-DNATIVE_BIG_ENDIAN'
+endif
+
+message('check args', check_args)
+
+add_project_arguments('-DHAVE_PTHREADS', language: 'c')
+
+add_project_arguments('-DFORTIFY_SOURCE=2', language: 'c')
+
+if get_option('arch_opt')
+ compile_args += c_compiler.get_supported_arguments(
+ '-Ofast',
+ '-ftree-vectorize',
+ '-ftree-slp-vectorize',
+ '-fomit-frame-pointer',
+ '-march=native',
+ )
+endif
+
+have_rdrand = c_compiler.compiles(fs.read('checkprogs/rdrand.c'), args : ['-mrdrnd'])
+message('have_rdrand:', have_rdrand)
+if have_rdrand
+ compile_args += '-mrdrnd'
+ add_project_arguments('-DHAVE_RDRAND', language: 'c')
+endif
+
+have_mmx = c_compiler.compiles(fs.read('checkprogs/mmx.c'), args : ['-mmmx'])
+message('have_mmx:', have_mmx)
+if have_mmx
+ compile_args += '-mmmx'
+ add_project_arguments('-DHAVE_MMX', language: 'c')
+endif
+
+if c_compiler.compiles('checkprogs/inline_asm.c')
+ add_project_arguments('-DHAVE_INLINE_ASM', language: 'c')
+endif
+
+have_ti_mode = c_compiler.compiles(fs.read('checkprogs/ti_mode.c'), args : check_args)
+message('have TI mode:', have_ti_mode)
+if have_ti_mode
+ add_project_arguments('-DHAVE_TI_MODE', language: 'c')
endif
+have_cpuid = c_compiler.compiles(fs.read('checkprogs/cpuid.c'))
+message('have cpuid:', have_cpuid)
+
+if have_cpuid
+ add_project_arguments('-DHAVE_CPUID', language: 'c')
+endif
+
+have_avx_asm = c_compiler.compiles(fs.read('checkprogs/avx_asm.c'))
+message('have_avx_asm:', have_avx_asm)
+if have_avx_asm
+ add_project_arguments('-DHAVE_AVX_ASM', language: 'c')
+endif
+
+have_xgetbv = c_compiler.compiles(fs.read('checkprogs/xgetbv.c'))
+message('have_xgetbv', have_xgetbv)
+if have_xgetbv
+ add_project_arguments('-DHAVE__XGETBV', language: 'c')
+endif
+
+
+compile_args += c_compiler.get_supported_arguments(
+ '-fno-strict-aliasing',
+ '-fno-strict-overflow',
+ '-fwrapv',
+)
+
+add_project_arguments(compile_args, language: 'c')
+
add_project_arguments('-DCONFIGURED', language: 'c')
+
conf_data = configuration_data()
conf_data.set('VERSION', '1.0.18')
conf_data.set('SODIUM_LIBRARY_VERSION_MAJOR', 10)
@@ -20,7 +102,7 @@ conf_data.set('SODIUM_LIBRARY_VERSION_MINOR', 3)
conf_data.set('SODIUM_LIBRARY_MINIMAL_DEF', '')
subdir('src/libsodium/include/sodium')
-libsodium = static_library('sodium', [
+libsodium_base_src = [
'src/libsodium/crypto_aead/chacha20poly1305/sodium/aead_chacha20poly1305.c',
'src/libsodium/crypto_aead/xchacha20poly1305/sodium/aead_xchacha20poly1305.c',
'src/libsodium/crypto_auth/crypto_auth.c',
@@ -89,7 +171,32 @@ libsodium = static_library('sodium', [
'src/libsodium/sodium/runtime.c',
'src/libsodium/sodium/utils.c',
'src/libsodium/sodium/version.c',
- ],
+]
+
+libsodium_avx_src = [
+ 'src/libsodium/crypto_scalarmult/curve25519/sandy2x/consts_namespace.h',
+ 'src/libsodium/crypto_scalarmult/curve25519/sandy2x/curve25519_sandy2x.c',
+ 'src/libsodium/crypto_scalarmult/curve25519/sandy2x/curve25519_sandy2x.h',
+ 'src/libsodium/crypto_scalarmult/curve25519/sandy2x/fe.h',
+ 'src/libsodium/crypto_scalarmult/curve25519/sandy2x/fe51.h',
+ 'src/libsodium/crypto_scalarmult/curve25519/sandy2x/fe51_invert.c',
+ 'src/libsodium/crypto_scalarmult/curve25519/sandy2x/fe51_namespace.h',
+ 'src/libsodium/crypto_scalarmult/curve25519/sandy2x/fe_frombytes_sandy2x.c',
+ 'src/libsodium/crypto_scalarmult/curve25519/sandy2x/ladder.h',
+ 'src/libsodium/crypto_scalarmult/curve25519/sandy2x/ladder_base.h',
+ 'src/libsodium/crypto_scalarmult/curve25519/sandy2x/ladder_base_namespace.h',
+ 'src/libsodium/crypto_scalarmult/curve25519/sandy2x/ladder_namespace.h',
+ 'src/libsodium/crypto_scalarmult/curve25519/sandy2x/sandy2x.S',
+]
+
+libsodium_all_src = []
+libsodium_all_src += libsodium_base_src
+
+if have_avx_asm
+ libsodium_all_src += libsodium_avx_src
+endif
+
+libsodium = static_library('sodium', libsodium_all_src,
include_directories:['src/libsodium/include/sodium'])
sodium_dep = declare_dependency(