aboutsummaryrefslogtreecommitdiff
path: root/meson.build
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2022-10-20 14:20:30 +0200
committerPaolo Bonzini <pbonzini@redhat.com>2023-05-18 13:35:28 +0200
commita988b4c56143d90f98034daf176e416b08dddf36 (patch)
tree5affc6f3beee483682117c53c13145d0cca42faa /meson.build
parent95caf1fb4230d64f7b5e117c6ea988ae38f76aa0 (diff)
downloadqemu-a988b4c56143d90f98034daf176e416b08dddf36.zip
qemu-a988b4c56143d90f98034daf176e416b08dddf36.tar.gz
qemu-a988b4c56143d90f98034daf176e416b08dddf36.tar.bz2
build: move remaining compiler flag tests to meson
Remove the only remaining uses of QEMU_CFLAGS. Now that no feature tests are done in configure, it is possible to remove CONFIGURE_CFLAGS and CONFIGURE_LDFLAGS as well. 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.build52
1 files changed, 51 insertions, 1 deletions
diff --git a/meson.build b/meson.build
index 515e319..2d3e468 100644
--- a/meson.build
+++ b/meson.build
@@ -190,10 +190,50 @@ endif
# Compiler flags #
##################
-qemu_common_flags = config_host['QEMU_CFLAGS'].split()
+# default flags for all hosts
+# We use -fwrapv to tell the compiler that we require a C dialect where
+# left shift of signed integers is well defined and has the expected
+# 2s-complement style results. (Both clang and gcc agree that it
+# provides these semantics.)
+
+qemu_common_flags = [
+ '-D_GNU_SOURCE', '-D_FILE_OFFSET_BITS=64', '-D_LARGEFILE_SOURCE',
+ '-fno-strict-aliasing', '-fno-common', '-fwrapv' ]
qemu_cflags = []
qemu_ldflags = []
+if targetos == 'darwin'
+ # Disable attempts to use ObjectiveC features in os/object.h since they
+ # won't work when we're compiling with gcc as a C compiler.
+ qemu_common_flags += '-DOS_OBJECT_USE_OBJC=0'
+elif targetos == 'solaris'
+ # needed for CMSG_ macros in sys/socket.h
+ qemu_common_flags += '-D_XOPEN_SOURCE=600'
+ # needed for TIOCWIN* defines in termios.h
+ qemu_common_flags += '-D__EXTENSIONS__'
+elif targetos == 'haiku'
+ qemu_common_flags += ['-DB_USE_POSITIVE_POSIX_ERRORS', '-D_BSD_SOURCE', '-fPIC']
+endif
+
+# __sync_fetch_and_and requires at least -march=i486. Many toolchains
+# use i686 as default anyway, but for those that don't, an explicit
+# specification is necessary
+if host_arch == 'i386' and not cc.links('''
+ static int sfaa(int *ptr)
+ {
+ return __sync_fetch_and_and(ptr, 0);
+ }
+
+ int main(void)
+ {
+ int val = 42;
+ val = __sync_val_compare_and_swap(&val, 0, 1);
+ sfaa(&val);
+ return val;
+ }''')
+ qemu_common_flags = ['-march=i486'] + qemu_common_flags
+endif
+
if get_option('gprof')
qemu_common_flags += ['-p']
qemu_ldflags += ['-p']
@@ -203,6 +243,16 @@ if get_option('prefer_static')
qemu_ldflags += get_option('b_pie') ? '-static-pie' : '-static'
endif
+# Meson currently only handles pie as a boolean for now, so if the user
+# has explicitly disabled PIE we need to extend our cflags.
+if not get_option('b_pie')
+ qemu_common_flags += cc.get_supported_arguments('-fno-pie')
+ if not get_option('prefer_static')
+ # No PIE is implied by -static which we added above.
+ qemu_ldflags += cc.get_supported_link_arguments('-no-pie')
+ endif
+endif
+
if not get_option('stack_protector').disabled()
stack_protector_probe = '''
int main(int argc, char *argv[])