[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 11/14] configure, meson: move C++ compiler detection to meson.buil
From: |
Paolo Bonzini |
Subject: |
[PULL 11/14] configure, meson: move C++ compiler detection to meson.build |
Date: |
Thu, 29 Sep 2022 18:30:11 +0200 |
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>
---
configure | 57 --------------------------------------------------
meson.build | 37 ++++++++++++++++++++++----------
scripts/main.c | 1 +
3 files changed, 27 insertions(+), 68 deletions(-)
create mode 100644 scripts/main.c
diff --git a/configure b/configure
index c5069775db..3e3c0f36c9 100755
--- a/configure
+++ b/configure
@@ -75,7 +75,6 @@ fi
TMPB="qemu-conf"
TMPC="${TMPDIR1}/${TMPB}.c"
TMPO="${TMPDIR1}/${TMPB}.o"
-TMPCXX="${TMPDIR1}/${TMPB}.cxx"
TMPM="${TMPDIR1}/${TMPB}.m"
TMPE="${TMPDIR1}/${TMPB}.exe"
@@ -158,10 +157,6 @@ do_cc() {
do_compiler_werror "$cc" $CPU_CFLAGS "$@"
}
-do_cxx() {
- do_compiler_werror "$cxx" $CPU_CFLAGS "$@"
-}
-
do_objc() {
do_compiler_werror "$objcc" $CPU_CFLAGS "$@"
}
@@ -171,24 +166,6 @@ add_to() {
eval $1=\${$1:+\"\$$1 \"}\$2
}
-update_cxxflags() {
- # Set QEMU_CXXFLAGS from QEMU_CFLAGS by filtering out those
- # options which some versions of GCC's C++ compiler complain about
- # because they only make sense for C programs.
- QEMU_CXXFLAGS="-D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS
-D__STDC_FORMAT_MACROS"
- CONFIGURE_CXXFLAGS=$(echo "$CONFIGURE_CFLAGS" | sed
s/-std=gnu11/-std=gnu++11/)
- for arg in $QEMU_CFLAGS; do
- case $arg in
- -Wstrict-prototypes|-Wmissing-prototypes|-Wnested-externs|\
- -Wold-style-declaration|-Wold-style-definition|-Wredundant-decls)
- ;;
- *)
- QEMU_CXXFLAGS=${QEMU_CXXFLAGS:+$QEMU_CXXFLAGS }$arg
- ;;
- esac
- done
-}
-
compile_object() {
local_cflags="$1"
do_cc $CFLAGS $EXTRA_CFLAGS $CONFIGURE_CFLAGS $QEMU_CFLAGS $local_cflags -c
-o $TMPO $TMPC
@@ -2362,38 +2339,6 @@ fi
#######################################
# generate config-host.mak
-# Check that the C++ compiler exists and works with the C compiler.
-# All the QEMU_CXXFLAGS are based on QEMU_CFLAGS. Keep this at the end to
don't miss any other that could be added.
-if has $cxx; then
- cat > $TMPC <<EOF
-int c_function(void);
-int main(void) { return c_function(); }
-EOF
-
- compile_object
-
- cat > $TMPCXX <<EOF
-extern "C" {
- int c_function(void);
-}
-int c_function(void) { return 42; }
-EOF
-
- update_cxxflags
-
- if do_cxx $CXXFLAGS $EXTRA_CXXFLAGS $CONFIGURE_CXXFLAGS $QEMU_CXXFLAGS -o
$TMPE $TMPCXX $TMPO $QEMU_LDFLAGS; then
- # C++ compiler $cxx works ok with C compiler $cc
- :
- else
- echo "C++ compiler $cxx does not work with C compiler $cc"
- echo "Disabling C++ specific optional code"
- cxx=
- fi
-else
- echo "No C++ compiler available; disabling C++ specific optional code"
- cxx=
-fi
-
if ! (GIT="$git" "$source_path/scripts/git-submodule.sh"
"$git_submodules_action" "$git_submodules"); then
exit 1
fi
@@ -2474,7 +2419,6 @@ echo "MESON=$meson" >> $config_host_mak
echo "NINJA=$ninja" >> $config_host_mak
echo "CC=$cc" >> $config_host_mak
echo "QEMU_CFLAGS=$QEMU_CFLAGS" >> $config_host_mak
-echo "QEMU_CXXFLAGS=$QEMU_CXXFLAGS" >> $config_host_mak
echo "QEMU_OBJCFLAGS=$QEMU_OBJCFLAGS" >> $config_host_mak
echo "GLIB_CFLAGS=$glib_cflags" >> $config_host_mak
echo "GLIB_LIBS=$glib_libs" >> $config_host_mak
@@ -2665,7 +2609,6 @@ if test "$skip_meson" = no; then
echo "${a}-softmmu = '$c'" >> $cross
done
- test -z "$cxx" && echo "link_language = 'c'" >> $cross
echo "[built-in options]" >> $cross
echo "c_args = [$(meson_quote $CFLAGS $EXTRA_CFLAGS)]" >> $cross
echo "cpp_args = [$(meson_quote $CXXFLAGS $EXTRA_CXXFLAGS)]" >> $cross
diff --git a/meson.build b/meson.build
index 48533ace7b..a1b265b133 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
diff --git a/scripts/main.c b/scripts/main.c
new file mode 100644
index 0000000000..b552c8e4ed
--- /dev/null
+++ b/scripts/main.c
@@ -0,0 +1 @@
+int main(void) {}
--
2.37.3
- [PULL 01/14] x86: return modified setup_data only if read as memory, not as file, (continued)
- [PULL 01/14] x86: return modified setup_data only if read as memory, not as file, Paolo Bonzini, 2022/09/29
- [PULL 06/14] configure: do not invoke as/ld directly for pc-bios/optionrom, Paolo Bonzini, 2022/09/29
- [PULL 07/14] watchdog: remove -watchdog option, Paolo Bonzini, 2022/09/29
- [PULL 05/14] qboot: rebuild based on latest commit, Paolo Bonzini, 2022/09/29
- [PULL 02/14] x86: use typedef for SetupData struct, Paolo Bonzini, 2022/09/29
- [PULL 03/14] x86: reinitialize RNG seed on system reboot, Paolo Bonzini, 2022/09/29
- [PULL 08/14] ui: fix path to dbus-display1.h, Paolo Bonzini, 2022/09/29
- [PULL 04/14] x86: re-enable rng seeding via SetupData, Paolo Bonzini, 2022/09/29
- [PULL 09/14] meson: require 0.61.3, Paolo Bonzini, 2022/09/29
- [PULL 10/14] meson: multiple names can be passed to dependency(), Paolo Bonzini, 2022/09/29
- [PULL 11/14] configure, meson: move C++ compiler detection to meson.build,
Paolo Bonzini <=
- [PULL 12/14] configure, meson: move linker flag detection to meson, Paolo Bonzini, 2022/09/29
- [PULL 13/14] target/i386/kvm: fix kvmclock_current_nsec: Assertion `time.tsc_timestamp <= migration_tsc' failed, Paolo Bonzini, 2022/09/29
- [PULL 14/14] x86: re-initialize RNG seed when selecting kernel, Paolo Bonzini, 2022/09/29
- Re: [PULL 00/14] x86 + misc changes for 2022-09-29, Stefan Hajnoczi, 2022/09/29