From 805c9fa8d439a37d16d5fef6dee8fb83648eb074 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 23 Nov 2020 18:47:54 +0100 Subject: [PATCH] build/meson: fix build to always set "-W" compiler flags We must set these compiler flags independent as to whether this is a release build or a debug build. In most cases, we don't differentiate between release and debug build anyway. Granted, we have "-D more_asserts=100" and set "-O" CFLAGS, but that is more granular and not a simple "buildtype". In particular, these compiler flags apply to all kinds of builds. This is important, because otherwise we get build failures, because also in release build we want to build with `-Werror` and `-Wall`. https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/692 (cherry picked from commit c0c6470e4d21cc7dfa6db27bb78b316304ff0756) (cherry picked from commit 6b316a1991e28430e551269affaac1508904cfcf) --- meson.build | 117 +++++++++++++++++++++++++--------------------------- 1 file changed, 56 insertions(+), 61 deletions(-) diff --git a/meson.build b/meson.build index 18a22bc7a7..dee72a372d 100644 --- a/meson.build +++ b/meson.build @@ -65,8 +65,6 @@ libnm_version = '@0@.@1@.@2@'.format(current - age, age, revision) libnm_pkgincludedir = join_paths(nm_includedir, libnm_name) -nm_debug = get_option('buildtype').contains('debug') - gnome = import('gnome') i18n = import('i18n') pkg = import('pkgconfig') @@ -173,67 +171,64 @@ if enable_lto common_ldflags += lto_flag endif -if nm_debug - common_flags += cc.get_supported_arguments([ - '-Wall', - '-Wextra', - '-Wdeclaration-after-statement', - '-Wfloat-equal', - '-Wformat-nonliteral', - '-Wformat-security', - '-Wimplicit-function-declaration', - '-Winit-self', - '-Wlogical-op', - '-Wmissing-declarations', - '-Wmissing-include-dirs', - '-Wmissing-prototypes', - '-Wpointer-arith', - '-Wshadow', - '-Wshift-negative-value', - '-Wstrict-prototypes', - '-Wundef', - '-Wvla', - '-Wno-duplicate-decl-specifier', - '-Wno-format-truncation', - '-Wno-format-y2k', - '-Wno-gnu-variable-sized-type-not-at-end', - '-Wno-missing-field-initializers', - '-Wno-pragmas', - '-Wno-sign-compare', - '-Wno-tautological-constant-out-of-range-compare', - '-Wno-unknown-pragmas', - '-Wno-unused-parameter', - '-Wparentheses-equality', - '-Wpointer-arith', - '-Wshadow', - '-Wstrict-prototypes', - '-Wtypedef-redefinition', - '-Wundef', - '-Wunknown-attributes', - '-fno-strict-aliasing', - ]) +common_flags += cc.get_supported_arguments([ + '-Wall', + '-Wextra', + '-Wdeclaration-after-statement', + '-Wfloat-equal', + '-Wformat-nonliteral', + '-Wformat-security', + '-Wimplicit-function-declaration', + '-Winit-self', + '-Wlogical-op', + '-Wmissing-declarations', + '-Wmissing-include-dirs', + '-Wmissing-prototypes', + '-Wpointer-arith', + '-Wshadow', + '-Wshift-negative-value', + '-Wstrict-prototypes', + '-Wundef', + '-Wvla', + '-Wno-duplicate-decl-specifier', + '-Wno-format-truncation', + '-Wno-format-y2k', + '-Wno-gnu-variable-sized-type-not-at-end', + '-Wno-missing-field-initializers', + '-Wno-pragmas', + '-Wno-sign-compare', + '-Wno-tautological-constant-out-of-range-compare', + '-Wno-unknown-pragmas', + '-Wno-unused-parameter', + '-Wparentheses-equality', + '-Wpointer-arith', + '-Wshadow', + '-Wstrict-prototypes', + '-Wtypedef-redefinition', + '-Wundef', + '-Wunknown-attributes', + '-fno-strict-aliasing', +]) - if cc.has_argument('-Wimplicit-fallthrough') - if cc.compiles(''' - int main(int argc, char **argv) { - int r = 0; - switch (argc) { - case 0: - r++; - /* fall-through */ - case 1: - r++; - break; - } - return r; - } - ''', - args: '-Werror=implicit-fallthrough', - name: '-Werror=implicit-fallthrough') - common_flags += '-Wimplicit-fallthrough' - endif +if cc.has_argument('-Wimplicit-fallthrough') + if cc.compiles(''' + int main(int argc, char **argv) { + int r = 0; + switch (argc) { + case 0: + r++; + /* fall-through */ + case 1: + r++; + break; + } + return r; + } + ''', + args: '-Werror=implicit-fallthrough', + name: '-Werror=implicit-fallthrough') + common_flags += '-Wimplicit-fallthrough' endif - endif add_project_arguments(common_flags, language: 'c')