From e5b6639624894d5e4411caf4c40f527db86151ae Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 13 Apr 2022 12:49:04 +0200 Subject: [PATCH] Squashed 'src/c-stdaux/' changes from 9582a563c25e..f20e1cf2dfb1 f20e1cf2dfb1 build: verify cflags do not contain spaces 5333735eeb74 build: export cflags via declare_dependency() d050374b1c1a build: export basic CFLAGS git-subtree-dir: src/c-stdaux git-subtree-split: f20e1cf2dfb177e77cc946331ed2d2a83169d8b9 --- meson.build | 69 ++++++++++++++++++++++++++++++++++++++++++++++++- src/meson.build | 1 + 2 files changed, 69 insertions(+), 1 deletion(-) diff --git a/meson.build b/meson.build index 367d8b5fe..abc30255d 100644 --- a/meson.build +++ b/meson.build @@ -10,9 +10,76 @@ project( major = meson.project_version().split('.')[0] project_description = 'Auxiliary macros and functions for the C standard library' -add_project_arguments('-D_GNU_SOURCE', language: 'c') mod_pkgconfig = import('pkgconfig') +# +# CFLAGS +# +# We have a set of compiler flags for GCC and CLANG which adjust their warnings +# and behavior to our coding-style. +# +# This variable is exported to dependent projects via meson for them to use as +# well. Since these exports are limited to strings, we need to be careful that +# the individual entries do not contain spaces (see the assertion below). +# +cflags = meson.get_compiler('c').get_supported_arguments( + # Enable GNU features of our dependencies. See feature_test_macros(7). + '-D_GNU_SOURCE', + + # Prevent CLANG from complaining that alignof-expressions are GNU-only. + '-Wno-gnu-alignof-expression', + # Never complain about *MAYBE* uninit variables. This is very flaky and + # produces bogus results with LTO. + '-Wno-maybe-uninitialized', + # Do not complain about unknown GCC/CLANG warnings. + '-Wno-unknown-warning-option', + # There is no standardized way to mark unused arguments, so never + # complain about them. + '-Wno-unused-parameter', + + # Preprocessor evaluations often lead to warnings about comparisons + # that are always true/false. Make sure they do not break a build but + # keep them on for diagnostics. + '-Wno-error=type-limits', + # As we use designated field-initializers, this warning should never + # trigger, but still does on GCC in combination with some other + # preprocessor checks. Lets just make sure it does not break builds. + '-Wno-error=missing-field-initializers', + + # Warn if we ever use `__DATE__` and similar in our build. We want + # reproducible builds. + '-Wdate-time', + # We strictly follow decl-before-statements, so check it. + '-Wdeclaration-after-statement', + # More strict logical-op sanity checks. + '-Wlogical-op', + # Loudly complain about missing include-directories. + '-Wmissing-include-dirs', + # We want hints about noreturn functions, so warn about them. + '-Wmissing-noreturn', + # Warn if an extern-decl is inside a function. We want imports as + # global attributes, never as local ones. + '-Wnested-externs', + # Warn about redundant declarations. We want declarations in headers + # and want them to be unique. + '-Wredundant-decls', + # Warn about shadowed variables so we do not accidentally override + # variables of parent scopes and thus confuse macros. + '-Wshadow', + # Warn about aliasing violations. Level-3 produces the least false + # positives, but is the slowest. Force it to avoid breaking -Werror + # builds. + '-Wstrict-aliasing=3', + # Suggest 'noreturn' attributes. They are useful, we want them! + '-Wsuggest-attribute=noreturn', + # Warn about undefined identifiers in preprocessor conditionals. + '-Wundef', + # Make sure literal strings are considered 'const'. + '-Wwrite-strings', +) +assert(not ''.join(cflags).contains(' '), 'Malformed compiler flags.') +add_project_arguments(cflags, language: 'c') + subdir('src') meson.override_dependency('libcstdaux-'+major, libcstdaux_dep, static: true) diff --git a/src/meson.build b/src/meson.build index 7c2e3a13c..a9322d4da 100644 --- a/src/meson.build +++ b/src/meson.build @@ -6,6 +6,7 @@ libcstdaux_dep = declare_dependency( include_directories: include_directories('.'), + variables: { 'cflags': ' '.join(cflags) }, version: meson.project_version(), )