diff options
author | Paolo Bonzini <pbonzini@redhat.com> | 2022-12-22 09:28:56 +0100 |
---|---|---|
committer | Paolo Bonzini <pbonzini@redhat.com> | 2023-05-18 13:35:28 +0200 |
commit | 95caf1fb4230d64f7b5e117c6ea988ae38f76aa0 (patch) | |
tree | b7af154ba26faf01e773ac4ce50f6052019324cb /meson.build | |
parent | 911d4caaa267c43a5aa727f5a100e9122158e989 (diff) | |
download | qemu-95caf1fb4230d64f7b5e117c6ea988ae38f76aa0.zip qemu-95caf1fb4230d64f7b5e117c6ea988ae38f76aa0.tar.gz qemu-95caf1fb4230d64f7b5e117c6ea988ae38f76aa0.tar.bz2 |
build: move warning flag selection to meson
Meson already knows to test with the positive form of the flag, which
simplifies the test. Warnings are now tested explicitly for the C++
compiler, instead of hardcoding those that are only available for
the C language.
At this point all compiler flags in QEMU_CFLAGS are global and only
depend on the OS. No feature tests are performed in configure.
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'meson.build')
-rw-r--r-- | meson.build | 68 |
1 files changed, 47 insertions, 21 deletions
diff --git a/meson.build b/meson.build index 252082c..515e319 100644 --- a/meson.build +++ b/meson.build @@ -190,16 +190,8 @@ endif # Compiler flags # ################## -qemu_common_flags = [] +qemu_common_flags = config_host['QEMU_CFLAGS'].split() qemu_cflags = [] -foreach arg : config_host['QEMU_CFLAGS'].split() - if arg.startswith('-W') - qemu_cflags += arg - else - qemu_common_flags += arg - endif -endforeach -qemu_objcflags = config_host['QEMU_OBJCFLAGS'].split() qemu_ldflags = [] if get_option('gprof') @@ -369,20 +361,47 @@ endif add_global_arguments(qemu_common_flags, native: false, language: all_languages) add_global_link_arguments(qemu_ldflags, native: false, language: all_languages) +# Collect warnings that we want to enable + +warn_flags = [ + '-Wundef', + '-Wwrite-strings', + '-Wmissing-prototypes', + '-Wstrict-prototypes', + '-Wredundant-decls', + '-Wold-style-declaration', + '-Wold-style-definition', + '-Wtype-limits', + '-Wformat-security', + '-Wformat-y2k', + '-Winit-self', + '-Wignored-qualifiers', + '-Wempty-body', + '-Wnested-externs', + '-Wendif-labels', + '-Wexpansion-to-defined', + '-Wimplicit-fallthrough=2', + '-Wmissing-format-attribute', + '-Wno-initializer-overrides', + '-Wno-missing-include-dirs', + '-Wno-shift-negative-value', + '-Wno-string-plus-int', + '-Wno-typedef-redefinition', + '-Wno-tautological-type-limit-compare', + '-Wno-psabi', + '-Wno-gnu-variable-sized-type-not-at-end', +] + +if targetos != 'darwin' + warn_flags += ['-Wthread-safety'] +endif + # Check that the C++ compiler exists and works with the C compiler. link_language = 'c' linker = cc qemu_cxxflags = [] if 'cpp' in all_languages - add_global_arguments(['-D__STDC_LIMIT_MACROS', '-D__STDC_CONSTANT_MACROS', '-D__STDC_FORMAT_MACROS'], - native: false, language: 'cpp') - foreach k: qemu_cflags - if k not in ['-Wstrict-prototypes', '-Wmissing-prototypes', '-Wnested-externs', - '-Wold-style-declaration', '-Wold-style-definition', '-Wredundant-decls'] - qemu_cxxflags += [k] - endif - endforeach - + qemu_cxxflags = ['-D__STDC_LIMIT_MACROS', '-D__STDC_CONSTANT_MACROS', '-D__STDC_FORMAT_MACROS'] + qemu_cflags if cxx.links(files('scripts/main.c'), args: qemu_cflags) link_language = 'cpp' linker = cxx @@ -403,8 +422,15 @@ if get_option('optimization') != '0' and targetos == 'linux' endif add_project_arguments(qemu_cflags, native: false, language: 'c') -add_project_arguments(qemu_cxxflags, native: false, language: 'cpp') -add_project_arguments(qemu_objcflags, native: false, language: 'objc') +add_project_arguments(cc.get_supported_arguments(warn_flags), native: false, language: 'c') +if 'cpp' in all_languages + add_project_arguments(qemu_cxxflags, native: false, language: 'cpp') + add_project_arguments(cxx.get_supported_arguments(warn_flags), native: false, language: 'cpp') +endif +if 'objc' in all_languages + # Note sanitizer flags are not applied to Objective-C sources! + add_project_arguments(objc.get_supported_arguments(warn_flags), native: false, language: 'objc') +endif if targetos == 'linux' add_project_arguments('-isystem', meson.current_source_dir() / 'linux-headers', '-isystem', 'linux-headers', @@ -4007,7 +4033,7 @@ if 'cpp' in all_languages summary_info += {'QEMU_CXXFLAGS': ' '.join(qemu_common_flags + qemu_cxxflags)} endif if 'objc' in all_languages - summary_info += {'QEMU_OBJCFLAGS': ' '.join(qemu_common_flags + qemu_objcflags)} + summary_info += {'QEMU_OBJCFLAGS': ' '.join(qemu_common_flags)} endif summary_info += {'QEMU_LDFLAGS': ' '.join(qemu_ldflags)} summary_info += {'profiler': get_option('profiler')} |