qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] meson.build: Remove the logic to link C code with the C++ linker
@ 2023-07-06  6:47 Thomas Huth
  2023-07-06  8:35 ` Paolo Bonzini
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Thomas Huth @ 2023-07-06  6:47 UTC (permalink / raw)
  To: Paolo Bonzini, qemu-devel
  Cc: Marc-André Lureau, Daniel P. Berrangé,
	Philippe Mathieu-Daudé, Michael Roth, Konstantin Kostiuk,
	Markus Armbruster

We are not mixing C++ with C code anymore, the only remaining
C++ code in qga/vss-win32/ is used for a plain C++ executable.
Thus we can remove the hacks for linking C code with the C++ linker
now to simplify meson.build a little bit, and also to avoid that
some C++ code sneaks in by accident again.

Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 meson.build     | 24 ++++++------------------
 scripts/main.c  |  1 -
 qga/meson.build |  2 +-
 3 files changed, 7 insertions(+), 20 deletions(-)
 delete mode 100644 scripts/main.c

diff --git a/meson.build b/meson.build
index 5559b36859..620457bb95 100644
--- a/meson.build
+++ b/meson.build
@@ -473,19 +473,10 @@ 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
+# Set up C++ compiler flags
 qemu_cxxflags = []
 if 'cpp' in all_languages
   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
-  else
-    message('C++ compiler does not work with C compiler')
-    message('Disabling C++-specific optional code')
-  endif
 endif
 
 # clang does not support glibc + FORTIFY_SOURCE (is it still true?)
@@ -1600,7 +1591,7 @@ if not get_option('snappy').auto() or have_system
   snappy = cc.find_library('snappy', has_headers: ['snappy-c.h'],
                            required: get_option('snappy'))
 endif
-if snappy.found() and not linker.links('''
+if snappy.found() and not cc.links('''
    #include <snappy-c.h>
    int main(void) { snappy_max_compressed_length(4096); return 0; }''', dependencies: snappy)
   snappy = not_found
@@ -2746,7 +2737,7 @@ config_host_data.set('CONFIG_AF_VSOCK', cc.has_header_symbol(
 
 have_vss = false
 have_vss_sdk = false # old xp/2003 SDK
-if targetos == 'windows' and link_language == 'cpp'
+if targetos == 'windows' and 'cpp' in all_languages
   have_vss = cxx.compiles('''
     #define __MIDL_user_allocate_free_DEFINED__
     #include <vss.h>
@@ -3827,7 +3818,6 @@ foreach target : target_dirs
                c_args: c_args,
                dependencies: arch_deps + deps + exe['dependencies'],
                objects: lib.extract_all_objects(recursive: true),
-               link_language: link_language,
                link_depends: [block_syms, qemu_syms] + exe.get('link_depends', []),
                link_args: link_args,
                win_subsystem: exe['win_subsystem'])
@@ -4061,10 +4051,8 @@ summary_info += {'host CPU':          cpu}
 summary_info += {'host endianness':   build_machine.endian()}
 summary_info += {'C compiler':        ' '.join(meson.get_compiler('c').cmd_array())}
 summary_info += {'Host C compiler':   ' '.join(meson.get_compiler('c', native: true).cmd_array())}
-if link_language == 'cpp'
+if 'cpp' in all_languages
   summary_info += {'C++ compiler':    ' '.join(meson.get_compiler('cpp').cmd_array())}
-else
-  summary_info += {'C++ compiler':      false}
 endif
 if targetos == 'darwin'
   summary_info += {'Objective-C compiler': ' '.join(meson.get_compiler('objc').cmd_array())}
@@ -4074,13 +4062,13 @@ if get_option('optimization') != 'plain'
   option_cflags += ['-O' + get_option('optimization')]
 endif
 summary_info += {'CFLAGS':            ' '.join(get_option('c_args') + option_cflags)}
-if link_language == 'cpp'
+if 'cpp' in all_languages
   summary_info += {'CXXFLAGS':        ' '.join(get_option('cpp_args') + option_cflags)}
 endif
 if targetos == 'darwin'
   summary_info += {'OBJCFLAGS':       ' '.join(get_option('objc_args') + option_cflags)}
 endif
-link_args = get_option(link_language + '_link_args')
+link_args = get_option('c_link_args')
 if link_args.length() > 0
   summary_info += {'LDFLAGS':         ' '.join(link_args)}
 endif
diff --git a/scripts/main.c b/scripts/main.c
deleted file mode 100644
index b552c8e4ed..0000000000
--- a/scripts/main.c
+++ /dev/null
@@ -1 +0,0 @@
-int main(void) {}
diff --git a/qga/meson.build b/qga/meson.build
index d3291b4376..dd18092f56 100644
--- a/qga/meson.build
+++ b/qga/meson.build
@@ -9,7 +9,7 @@ endif
 have_qga_vss = get_option('qga_vss') \
   .require(targetos == 'windows',
            error_message: 'VSS support requires Windows') \
-  .require(link_language == 'cpp',
+  .require('cpp' in all_languages,
            error_message: 'VSS support requires a C++ compiler') \
   .require(have_vss, error_message: '''VSS support requires VSS headers.
     If your Visual Studio installation doesn't have the VSS headers,
-- 
2.39.3



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] meson.build: Remove the logic to link C code with the C++ linker
  2023-07-06  6:47 [PATCH] meson.build: Remove the logic to link C code with the C++ linker Thomas Huth
@ 2023-07-06  8:35 ` Paolo Bonzini
  2023-07-06  8:50 ` Philippe Mathieu-Daudé
  2023-07-06  9:03 ` Konstantin Kostiuk
  2 siblings, 0 replies; 4+ messages in thread
From: Paolo Bonzini @ 2023-07-06  8:35 UTC (permalink / raw)
  To: Thomas Huth, qemu-devel
  Cc: Marc-André Lureau, Daniel P. Berrangé,
	Philippe Mathieu-Daudé, Michael Roth, Konstantin Kostiuk,
	Markus Armbruster

On 7/6/23 08:47, Thomas Huth wrote:
> We are not mixing C++ with C code anymore, the only remaining
> C++ code in qga/vss-win32/ is used for a plain C++ executable.
> Thus we can remove the hacks for linking C code with the C++ linker
> now to simplify meson.build a little bit, and also to avoid that
> some C++ code sneaks in by accident again.

Queued, thanks.  However I think these two lines are worth keeping:

> +if 'cpp' in all_languages
>     summary_info += {'C++ compiler':    ' '.join(meson.get_compiler('cpp').cmd_array())}
> -else
> -  summary_info += {'C++ compiler':      false}
>   endif

Perhaps we could also make the whole if...endif conditional on Windows, 
but an extra line in the summary won't hurt.

Paolo



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] meson.build: Remove the logic to link C code with the C++ linker
  2023-07-06  6:47 [PATCH] meson.build: Remove the logic to link C code with the C++ linker Thomas Huth
  2023-07-06  8:35 ` Paolo Bonzini
@ 2023-07-06  8:50 ` Philippe Mathieu-Daudé
  2023-07-06  9:03 ` Konstantin Kostiuk
  2 siblings, 0 replies; 4+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-07-06  8:50 UTC (permalink / raw)
  To: Thomas Huth, Paolo Bonzini, qemu-devel
  Cc: Marc-André Lureau, Daniel P. Berrangé, Michael Roth,
	Konstantin Kostiuk, Markus Armbruster

On 6/7/23 08:47, Thomas Huth wrote:
> We are not mixing C++ with C code anymore, the only remaining
> C++ code in qga/vss-win32/ is used for a plain C++ executable.
> Thus we can remove the hacks for linking C code with the C++ linker
> now to simplify meson.build a little bit, and also to avoid that
> some C++ code sneaks in by accident again.
> 
> Signed-off-by: Thomas Huth <thuth@redhat.com>
> ---
>   meson.build     | 24 ++++++------------------
>   scripts/main.c  |  1 -
>   qga/meson.build |  2 +-
>   3 files changed, 7 insertions(+), 20 deletions(-)
>   delete mode 100644 scripts/main.c

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] meson.build: Remove the logic to link C code with the C++ linker
  2023-07-06  6:47 [PATCH] meson.build: Remove the logic to link C code with the C++ linker Thomas Huth
  2023-07-06  8:35 ` Paolo Bonzini
  2023-07-06  8:50 ` Philippe Mathieu-Daudé
@ 2023-07-06  9:03 ` Konstantin Kostiuk
  2 siblings, 0 replies; 4+ messages in thread
From: Konstantin Kostiuk @ 2023-07-06  9:03 UTC (permalink / raw)
  To: Thomas Huth
  Cc: Paolo Bonzini, qemu-devel, Marc-André Lureau,
	Daniel P. Berrangé, Philippe Mathieu-Daudé,
	Michael Roth, Markus Armbruster

[-- Attachment #1: Type: text/plain, Size: 5133 bytes --]

Reviewed-by: Konstantin Kostiuk <kkostiuk@redhat.com>

On Thu, Jul 6, 2023 at 9:47 AM Thomas Huth <thuth@redhat.com> wrote:

> We are not mixing C++ with C code anymore, the only remaining
> C++ code in qga/vss-win32/ is used for a plain C++ executable.
> Thus we can remove the hacks for linking C code with the C++ linker
> now to simplify meson.build a little bit, and also to avoid that
> some C++ code sneaks in by accident again.
>
> Signed-off-by: Thomas Huth <thuth@redhat.com>
> ---
>  meson.build     | 24 ++++++------------------
>  scripts/main.c  |  1 -
>  qga/meson.build |  2 +-
>  3 files changed, 7 insertions(+), 20 deletions(-)
>  delete mode 100644 scripts/main.c
>
> diff --git a/meson.build b/meson.build
> index 5559b36859..620457bb95 100644
> --- a/meson.build
> +++ b/meson.build
> @@ -473,19 +473,10 @@ 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
> +# Set up C++ compiler flags
>  qemu_cxxflags = []
>  if 'cpp' in all_languages
>    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
> -  else
> -    message('C++ compiler does not work with C compiler')
> -    message('Disabling C++-specific optional code')
> -  endif
>  endif
>
>  # clang does not support glibc + FORTIFY_SOURCE (is it still true?)
> @@ -1600,7 +1591,7 @@ if not get_option('snappy').auto() or have_system
>    snappy = cc.find_library('snappy', has_headers: ['snappy-c.h'],
>                             required: get_option('snappy'))
>  endif
> -if snappy.found() and not linker.links('''
> +if snappy.found() and not cc.links('''
>     #include <snappy-c.h>
>     int main(void) { snappy_max_compressed_length(4096); return 0; }''',
> dependencies: snappy)
>    snappy = not_found
> @@ -2746,7 +2737,7 @@ config_host_data.set('CONFIG_AF_VSOCK',
> cc.has_header_symbol(
>
>  have_vss = false
>  have_vss_sdk = false # old xp/2003 SDK
> -if targetos == 'windows' and link_language == 'cpp'
> +if targetos == 'windows' and 'cpp' in all_languages
>    have_vss = cxx.compiles('''
>      #define __MIDL_user_allocate_free_DEFINED__
>      #include <vss.h>
> @@ -3827,7 +3818,6 @@ foreach target : target_dirs
>                 c_args: c_args,
>                 dependencies: arch_deps + deps + exe['dependencies'],
>                 objects: lib.extract_all_objects(recursive: true),
> -               link_language: link_language,
>                 link_depends: [block_syms, qemu_syms] +
> exe.get('link_depends', []),
>                 link_args: link_args,
>                 win_subsystem: exe['win_subsystem'])
> @@ -4061,10 +4051,8 @@ summary_info += {'host CPU':          cpu}
>  summary_info += {'host endianness':   build_machine.endian()}
>  summary_info += {'C compiler':        '
> '.join(meson.get_compiler('c').cmd_array())}
>  summary_info += {'Host C compiler':   ' '.join(meson.get_compiler('c',
> native: true).cmd_array())}
> -if link_language == 'cpp'
> +if 'cpp' in all_languages
>    summary_info += {'C++ compiler':    '
> '.join(meson.get_compiler('cpp').cmd_array())}
> -else
> -  summary_info += {'C++ compiler':      false}
>  endif
>  if targetos == 'darwin'
>    summary_info += {'Objective-C compiler': '
> '.join(meson.get_compiler('objc').cmd_array())}
> @@ -4074,13 +4062,13 @@ if get_option('optimization') != 'plain'
>    option_cflags += ['-O' + get_option('optimization')]
>  endif
>  summary_info += {'CFLAGS':            ' '.join(get_option('c_args') +
> option_cflags)}
> -if link_language == 'cpp'
> +if 'cpp' in all_languages
>    summary_info += {'CXXFLAGS':        ' '.join(get_option('cpp_args') +
> option_cflags)}
>  endif
>  if targetos == 'darwin'
>    summary_info += {'OBJCFLAGS':       ' '.join(get_option('objc_args') +
> option_cflags)}
>  endif
> -link_args = get_option(link_language + '_link_args')
> +link_args = get_option('c_link_args')
>  if link_args.length() > 0
>    summary_info += {'LDFLAGS':         ' '.join(link_args)}
>  endif
> diff --git a/scripts/main.c b/scripts/main.c
> deleted file mode 100644
> index b552c8e4ed..0000000000
> --- a/scripts/main.c
> +++ /dev/null
> @@ -1 +0,0 @@
> -int main(void) {}
> diff --git a/qga/meson.build b/qga/meson.build
> index d3291b4376..dd18092f56 100644
> --- a/qga/meson.build
> +++ b/qga/meson.build
> @@ -9,7 +9,7 @@ endif
>  have_qga_vss = get_option('qga_vss') \
>    .require(targetos == 'windows',
>             error_message: 'VSS support requires Windows') \
> -  .require(link_language == 'cpp',
> +  .require('cpp' in all_languages,
>             error_message: 'VSS support requires a C++ compiler') \
>    .require(have_vss, error_message: '''VSS support requires VSS headers.
>      If your Visual Studio installation doesn't have the VSS headers,
> --
> 2.39.3
>
>

[-- Attachment #2: Type: text/html, Size: 6550 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-07-06  9:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-06  6:47 [PATCH] meson.build: Remove the logic to link C code with the C++ linker Thomas Huth
2023-07-06  8:35 ` Paolo Bonzini
2023-07-06  8:50 ` Philippe Mathieu-Daudé
2023-07-06  9:03 ` Konstantin Kostiuk

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).