From cb2a50691fb0cddb64e1b5a9ed242a6a0b42d503 Mon Sep 17 00:00:00 2001 From: Hristo Venev Date: Mon, 22 Jun 2020 12:32:11 +0300 Subject: Initial commit. --- meson.build | 138 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 138 insertions(+) create mode 100644 meson.build (limited to 'meson.build') diff --git a/meson.build b/meson.build new file mode 100644 index 0000000..8c64ffe --- /dev/null +++ b/meson.build @@ -0,0 +1,138 @@ +project( + 'hkvs', 'c', + default_options: [ + 'warning_level=3', + 'c_std=gnu18', + ], +) + +cc = meson.get_compiler('c') + +fuzz = get_option('fuzz') + +if fuzz == 'none' + fuzz_deps = [] +elif fuzz == 'libFuzzer' + fuzz_deps = [declare_dependency( + link_args: ['-fsanitize=fuzzer'], + )] + add_project_arguments(['-fsanitize=fuzzer-no-link', '-DFUZZING'], language: 'c') + add_project_link_arguments(['-fsanitize=fuzzer-no-link'], language: 'c') +endif + +warning_flags = [ + '-Werror=conversion', + '-Werror=sign-conversion', + '-Werror=float-conversion', + '-Werror=old-style-definition', + '-Werror=strict-prototypes', + '-Werror=missing-prototypes', + '-Werror=implicit-function-declaration', + '-Werror=missing-declarations', + '-Werror=return-type', + '-Werror=pointer-arith', + '-Werror=vla', + '-Werror=incompatible-pointer-types', + '-Werror=int-conversion', + '-Werror=int-conversion', + '-Werror=format=2', + '-Werror=overflow', + '-Werror=shift-count-overflow', + '-Werror=init-self', + '-Werror=shadow', + '-Werror=redundant-decls', + '-Werror=missing-field-initializers', + '-Werror=write-strings', + '-Werror=date-time', + '-Werror=nested-externs', + '-Werror=endif-labels', + '-Werror=undef', + '-Wmissing-include-dirs', + '-Wfloat-equal', + '-Winline', + '-Wmissing-noreturn', +] + +if cc.get_id() == 'gcc' + warning_flags += [ + '-Werror=implicit-fallthrough=5', + '-Werror=strict-aliasing=3', + '-Werror=old-style-declaration', + '-Werror=shift-overflow=2', + '-Wlogical-op', + '-Wsuggest-attribute=noreturn', + '-Wsuggest-attribute=const', + '-Wsuggest-attribute=pure', + '-Wsuggest-attribute=malloc', + '-Wsuggest-attribute=format', + '-Wmissing-format-attribute', + '-Wsuggest-attribute=cold', + ] +elif cc.get_id() == 'clang' + warning_flags += [ + '-Werror=missing-variable-declarations', + '-Werror=implicit-fallthrough', + '-Werror=shift-overflow', + ] +else + warning('Unknown C compiler') +endif + +add_project_arguments(warning_flags, language : 'c') + +hkvs_include = include_directories('include') + +hkvs_lib = library( + 'hkvs', + [ + 'lib/die.c', + 'lib/db.c', + 'lib/table.c', + 'lib/slab.c', + 'lib/extfile.c', + 'lib/hash.c', + 'lib/ix.c', + 'lib/record.c', + 'lib/util.c', + 'lib/iter.c', + 'lib/io_mem.c', + 'lib/io_dirfd.c', + ], + implicit_include_directories: false, + include_directories: hkvs_include, +) + +hkvs = declare_dependency( + include_directories: hkvs_include, + link_with: hkvs_lib +) + +examples = [ + 'write', 'print', +] + +tests_fuzz = [ + 'simple_ops', +] + +foreach i: examples + executable( + 'example-' + i, + 'examples/' + i + '.c', + implicit_include_directories: false, + dependencies: [hkvs], + install: false, + ) +endforeach + +if fuzz != 'none' + foreach i: tests_fuzz + executable( + 'fuzz-' + i, + 'fuzz/' + i + '.c', + implicit_include_directories: false, + dependencies: [hkvs] + fuzz_deps, + install: false, + ) + endforeach +endif -- cgit