diff mbox series

[20/30] meson: prepare move of QEMU_CFLAGS to meson

Message ID 20221209112409.184703-21-pbonzini@redhat.com
State New
Headers show
Series Meson changes for QEMU 8.0 | expand

Commit Message

Paolo Bonzini Dec. 9, 2022, 11:23 a.m. UTC
Clean up the handling of compiler flags in meson.build, splitting
the general flags that should be included in subprojects as well,
from warning flags that only apply to QEMU itself.  The two were
mixed in both configure tests and meson tests.

This split makes it easier to move the compiler tests piecewise
from configure to Meson.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 meson.build | 53 +++++++++++++++++++++++++++++------------------------
 1 file changed, 29 insertions(+), 24 deletions(-)

Comments

Marc-André Lureau Dec. 12, 2022, 12:02 p.m. UTC | #1
On Fri, Dec 9, 2022 at 3:34 PM Paolo Bonzini <pbonzini@redhat.com> wrote:
>
> Clean up the handling of compiler flags in meson.build, splitting
> the general flags that should be included in subprojects as well,
> from warning flags that only apply to QEMU itself.  The two were
> mixed in both configure tests and meson tests.
>
> This split makes it easier to move the compiler tests piecewise
> from configure to Meson.
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>

> ---
>  meson.build | 53 +++++++++++++++++++++++++++++------------------------
>  1 file changed, 29 insertions(+), 24 deletions(-)
>
> diff --git a/meson.build b/meson.build
> index 99c1bde4d154..dac343d14797 100644
> --- a/meson.build
> +++ b/meson.build
> @@ -190,10 +190,23 @@ endif
>  # Compiler flags #
>  ##################
>
> -qemu_cflags = config_host['QEMU_CFLAGS'].split()
> +qemu_common_flags = []
> +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 = config_host['QEMU_LDFLAGS'].split()
>
> +if get_option('gprof')
> +  qemu_common_flags += ['-p']
> +  qemu_ldflags += ['-p']
> +endif
> +
>  if get_option('prefer_static')
>    qemu_ldflags += get_option('b_pie') ? '-static-pie' : '-static'
>  endif
> @@ -207,10 +220,9 @@ if targetos == 'windows'
>    qemu_ldflags += cc.get_supported_link_arguments('-Wl,--dynamicbase', '-Wl,--high-entropy-va')
>  endif
>
> -if get_option('gprof')
> -  qemu_cflags += ['-p']
> -  qemu_objcflags += ['-p']
> -  qemu_ldflags += ['-p']
> +# Exclude --warn-common with TSan to suppress warnings from the TSan libraries.
> +if targetos != 'sunos' and not config_host.has_key('CONFIG_TSAN')
> +  qemu_ldflags += cc.get_supported_link_arguments('-Wl,--warn-common')
>  endif
>
>  # Specify linker-script with add_project_link_arguments so that it is not placed
> @@ -230,8 +242,7 @@ if get_option('fuzzing')
>                    name: '-fsanitize-coverage-allowlist=/dev/null',
>                   args: ['-fsanitize-coverage-allowlist=/dev/null',
>                          '-fsanitize-coverage=trace-pc'] )
> -    add_global_arguments('-fsanitize-coverage-allowlist=instrumentation-filter',
> -                         native: false, language: all_languages)
> +    qemu_common_flags += ['-fsanitize-coverage-allowlist=instrumentation-filter']
>    endif
>
>    if get_option('fuzzing_engine') == ''
> @@ -239,10 +250,8 @@ if get_option('fuzzing')
>      # compiled code.  To build non-fuzzer binaries with --enable-fuzzing, link
>      # everything with fsanitize=fuzzer-no-link. Otherwise, the linker will be
>      # unable to bind the fuzzer-related callbacks added by instrumentation.
> -    add_global_arguments('-fsanitize=fuzzer-no-link',
> -                         native: false, language: all_languages)
> -    add_global_link_arguments('-fsanitize=fuzzer-no-link',
> -                              native: false, language: all_languages)
> +    qemu_common_flags += ['-fsanitize=fuzzer-no-link']
> +    qemu_ldflags += ['-fsanitize=fuzzer-no-link']
>      # For the actual fuzzer binaries, we need to link against the libfuzzer
>      # library. They need to be configurable, to support OSS-Fuzz
>      fuzz_exe_ldflags = ['-fsanitize=fuzzer']
> @@ -253,6 +262,9 @@ if get_option('fuzzing')
>    endif
>  endif
>
> +add_global_arguments(qemu_common_flags, native: false, language: all_languages)
> +add_global_link_arguments(qemu_ldflags, native: false, language: all_languages)
> +
>  # Check that the C++ compiler exists and works with the C compiler.
>  link_language = 'c'
>  linker = cc
> @@ -276,16 +288,9 @@ if 'cpp' in all_languages
>    endif
>  endif
>
> -# Exclude --warn-common with TSan to suppress warnings from the TSan libraries.
> -if targetos != 'sunos' and not config_host.has_key('CONFIG_TSAN')
> -  qemu_ldflags += linker.get_supported_link_arguments('-Wl,--warn-common')
> -endif
> -
> -add_global_link_arguments(qemu_ldflags, native: false, language: all_languages)
> -
> -add_global_arguments(qemu_cflags, native: false, language: 'c')
> -add_global_arguments(qemu_cxxflags, native: false, language: 'cpp')
> -add_global_arguments(qemu_objcflags, native: false, language: 'objc')
> +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')
>  if targetos == 'linux'
>    add_project_arguments('-isystem', meson.current_source_dir() / 'linux-headers',
>                          '-isystem', 'linux-headers',
> @@ -3778,12 +3783,12 @@ link_args = get_option(link_language + '_link_args')
>  if link_args.length() > 0
>    summary_info += {'LDFLAGS':         ' '.join(link_args)}
>  endif
> -summary_info += {'QEMU_CFLAGS':       ' '.join(qemu_cflags)}
> +summary_info += {'QEMU_CFLAGS':       ' '.join(qemu_common_flags + qemu_cflags)}
>  if 'cpp' in all_languages
> -  summary_info += {'QEMU_CXXFLAGS':     ' '.join(qemu_cxxflags)}
> +  summary_info += {'QEMU_CXXFLAGS':     ' '.join(qemu_common_flags + qemu_cxxflags)}
>  endif
>  if 'objc' in all_languages
> -  summary_info += {'QEMU_OBJCFLAGS':    ' '.join(qemu_objcflags)}
> +  summary_info += {'QEMU_OBJCFLAGS':    ' '.join(qemu_common_flags + qemu_objcflags)}
>  endif
>  summary_info += {'QEMU_LDFLAGS':      ' '.join(qemu_ldflags)}
>  summary_info += {'profiler':          get_option('profiler')}
> --
> 2.38.1
>
>
Daniel P. Berrangé Dec. 16, 2022, 3:11 p.m. UTC | #2
On Fri, Dec 09, 2022 at 12:23:59PM +0100, Paolo Bonzini wrote:
> Clean up the handling of compiler flags in meson.build, splitting
> the general flags that should be included in subprojects as well,
> from warning flags that only apply to QEMU itself.  The two were
> mixed in both configure tests and meson tests.
> 
> This split makes it easier to move the compiler tests piecewise
> from configure to Meson.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  meson.build | 53 +++++++++++++++++++++++++++++------------------------
>  1 file changed, 29 insertions(+), 24 deletions(-)

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>


With regards,
Daniel
diff mbox series

Patch

diff --git a/meson.build b/meson.build
index 99c1bde4d154..dac343d14797 100644
--- a/meson.build
+++ b/meson.build
@@ -190,10 +190,23 @@  endif
 # Compiler flags #
 ##################
 
-qemu_cflags = config_host['QEMU_CFLAGS'].split()
+qemu_common_flags = []
+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 = config_host['QEMU_LDFLAGS'].split()
 
+if get_option('gprof')
+  qemu_common_flags += ['-p']
+  qemu_ldflags += ['-p']
+endif
+
 if get_option('prefer_static')
   qemu_ldflags += get_option('b_pie') ? '-static-pie' : '-static'
 endif
@@ -207,10 +220,9 @@  if targetos == 'windows'
   qemu_ldflags += cc.get_supported_link_arguments('-Wl,--dynamicbase', '-Wl,--high-entropy-va')
 endif
 
-if get_option('gprof')
-  qemu_cflags += ['-p']
-  qemu_objcflags += ['-p']
-  qemu_ldflags += ['-p']
+# Exclude --warn-common with TSan to suppress warnings from the TSan libraries.
+if targetos != 'sunos' and not config_host.has_key('CONFIG_TSAN')
+  qemu_ldflags += cc.get_supported_link_arguments('-Wl,--warn-common')
 endif
 
 # Specify linker-script with add_project_link_arguments so that it is not placed
@@ -230,8 +242,7 @@  if get_option('fuzzing')
                   name: '-fsanitize-coverage-allowlist=/dev/null',
                  args: ['-fsanitize-coverage-allowlist=/dev/null',
                         '-fsanitize-coverage=trace-pc'] )
-    add_global_arguments('-fsanitize-coverage-allowlist=instrumentation-filter',
-                         native: false, language: all_languages)
+    qemu_common_flags += ['-fsanitize-coverage-allowlist=instrumentation-filter']
   endif
 
   if get_option('fuzzing_engine') == ''
@@ -239,10 +250,8 @@  if get_option('fuzzing')
     # compiled code.  To build non-fuzzer binaries with --enable-fuzzing, link
     # everything with fsanitize=fuzzer-no-link. Otherwise, the linker will be
     # unable to bind the fuzzer-related callbacks added by instrumentation.
-    add_global_arguments('-fsanitize=fuzzer-no-link',
-                         native: false, language: all_languages)
-    add_global_link_arguments('-fsanitize=fuzzer-no-link',
-                              native: false, language: all_languages)
+    qemu_common_flags += ['-fsanitize=fuzzer-no-link']
+    qemu_ldflags += ['-fsanitize=fuzzer-no-link']
     # For the actual fuzzer binaries, we need to link against the libfuzzer
     # library. They need to be configurable, to support OSS-Fuzz
     fuzz_exe_ldflags = ['-fsanitize=fuzzer']
@@ -253,6 +262,9 @@  if get_option('fuzzing')
   endif
 endif
 
+add_global_arguments(qemu_common_flags, native: false, language: all_languages)
+add_global_link_arguments(qemu_ldflags, native: false, language: all_languages)
+
 # Check that the C++ compiler exists and works with the C compiler.
 link_language = 'c'
 linker = cc
@@ -276,16 +288,9 @@  if 'cpp' in all_languages
   endif
 endif
 
-# Exclude --warn-common with TSan to suppress warnings from the TSan libraries.
-if targetos != 'sunos' and not config_host.has_key('CONFIG_TSAN')
-  qemu_ldflags += linker.get_supported_link_arguments('-Wl,--warn-common')
-endif
-
-add_global_link_arguments(qemu_ldflags, native: false, language: all_languages)
-
-add_global_arguments(qemu_cflags, native: false, language: 'c')
-add_global_arguments(qemu_cxxflags, native: false, language: 'cpp')
-add_global_arguments(qemu_objcflags, native: false, language: 'objc')
+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')
 if targetos == 'linux'
   add_project_arguments('-isystem', meson.current_source_dir() / 'linux-headers',
                         '-isystem', 'linux-headers',
@@ -3778,12 +3783,12 @@  link_args = get_option(link_language + '_link_args')
 if link_args.length() > 0
   summary_info += {'LDFLAGS':         ' '.join(link_args)}
 endif
-summary_info += {'QEMU_CFLAGS':       ' '.join(qemu_cflags)}
+summary_info += {'QEMU_CFLAGS':       ' '.join(qemu_common_flags + qemu_cflags)}
 if 'cpp' in all_languages
-  summary_info += {'QEMU_CXXFLAGS':     ' '.join(qemu_cxxflags)}
+  summary_info += {'QEMU_CXXFLAGS':     ' '.join(qemu_common_flags + qemu_cxxflags)}
 endif
 if 'objc' in all_languages
-  summary_info += {'QEMU_OBJCFLAGS':    ' '.join(qemu_objcflags)}
+  summary_info += {'QEMU_OBJCFLAGS':    ' '.join(qemu_common_flags + qemu_objcflags)}
 endif
 summary_info += {'QEMU_LDFLAGS':      ' '.join(qemu_ldflags)}
 summary_info += {'profiler':          get_option('profiler')}