summaryrefslogtreecommitdiffstats
path: root/meson.build
diff options
context:
space:
mode:
authorPaolo Bonzini2021-11-08 12:31:52 +0100
committerPaolo Bonzini2022-10-01 21:16:36 +0200
commitb485458e00dae4af5e2b7b1c17521e2885180544 (patch)
treea53770c1c583dc48a3844e83e1a3e2f0d97e2907 /meson.build
parentmeson: multiple names can be passed to dependency() (diff)
downloadqemu-b485458e00dae4af5e2b7b1c17521e2885180544.tar.gz
qemu-b485458e00dae4af5e2b7b1c17521e2885180544.tar.xz
qemu-b485458e00dae4af5e2b7b1c17521e2885180544.zip
configure, meson: move C++ compiler detection to meson.build
The test is slightly weaker than before, because it does not call an extern "C" function from a C source file. However, in practice what we seek to detect is ABI compatibility of the various sanitizer flags, and for that it is enough to compile anything with CC and link it with CXX. 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.build37
1 files changed, 26 insertions, 11 deletions
diff --git a/meson.build b/meson.build
index 780654b00c..9c57ebdfb9 100644
--- a/meson.build
+++ b/meson.build
@@ -180,7 +180,6 @@ endif
##################
qemu_cflags = config_host['QEMU_CFLAGS'].split()
-qemu_cxxflags = config_host['QEMU_CXXFLAGS'].split()
qemu_objcflags = config_host['QEMU_OBJCFLAGS'].split()
qemu_ldflags = config_host['QEMU_LDFLAGS'].split()
@@ -194,7 +193,6 @@ endif
if get_option('gprof')
qemu_cflags += ['-p']
- qemu_cxxflags += ['-p']
qemu_objcflags += ['-p']
qemu_ldflags += ['-p']
endif
@@ -240,8 +238,33 @@ if get_option('fuzzing')
endif
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'])
+
+# Check that the C++ compiler exists and works with the C compiler.
+link_language = 'c'
+linker = cc
+qemu_cxxflags = []
+if add_languages('cpp', required: false, native: false)
+ cxx = meson.get_compiler('cpp')
+ 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
+ add_global_arguments(qemu_cxxflags, native: false, language: 'cpp')
+
+ if cxx.links(files('scripts/main.c'), args: qemu_cflags)
+ link_language = 'cpp'
+ linker = cxx
+ else
+ message('C++ compiler does not work with C compiler')
+ message('Disabling C++-specific optional code')
+ endif
+endif
+
add_global_link_arguments(qemu_ldflags, native: false, language: ['c', 'cpp', 'objc'])
if targetos == 'linux'
@@ -255,14 +278,6 @@ add_project_arguments('-iquote', '.',
'-iquote', meson.current_source_dir() / 'include',
language: ['c', 'cpp', 'objc'])
-link_language = meson.get_external_property('link_language', 'cpp')
-if link_language == 'cpp'
- add_languages('cpp', required: true, native: false)
- cxx = meson.get_compiler('cpp')
- linker = cxx
-else
- linker = cc
-endif
if host_machine.system() == 'darwin'
add_languages('objc', required: false, native: false)
endif