[glib/atomic-older-cplusplus: 1/10] meson: Build C++ tests for the currently supported C++ standard versions




commit ce6afa14f543b6b0aea73e6c7a69be64e68ef74a
Author: Marco Trevisan (TreviƱo) <mail 3v1n0 net>
Date:   Tue Sep 13 18:26:40 2022 +0200

    meson: Build C++ tests for the currently supported C++ standard versions
    
    We've various macros definitions that are depending using C++ features
    that may not work in all the standard versions, so recompile the cxx
    tests that we have in all the ones we want to support.

 gio/tests/meson.build     | 14 ++++++++++++++
 glib/tests/meson.build    | 13 +++++++++++++
 gmodule/tests/meson.build | 13 +++++++++++++
 gobject/tests/meson.build | 13 +++++++++++++
 meson.build               |  8 ++++++++
 5 files changed, 61 insertions(+)
---
diff --git a/gio/tests/meson.build b/gio/tests/meson.build
index c3e4e4cb33..5658eff6f9 100644
--- a/gio/tests/meson.build
+++ b/gio/tests/meson.build
@@ -27,6 +27,8 @@ if cc.has_header('pty.h')
   endif
 endif
 
+test_cpp_args = test_c_args
+
 if host_machine.system() == 'windows'
   common_gio_tests_deps += [iphlpapi_dep, winsock2, cc.find_library ('secur32')]
 endif
@@ -130,8 +132,19 @@ if have_cxx
   gio_tests += {
     'cxx' : {
       'source' : ['cxx.cpp'],
+      'suite': ['C++'],
     },
   }
+
+  foreach std, arg: cxx_standards
+    gio_tests += {
+      'cxx-@0@'.format(std) : {
+        'source' : ['cxx.cpp'],
+        'suite' : ['cpp'],
+        'cpp_args' : [arg],
+      },
+    }
+  endforeach
 endif
 
 test_extra_programs = {
@@ -853,6 +866,7 @@ foreach test_name, extra_args : gio_tests
 
   exe = executable(test_name, [source, extra_sources],
     c_args : test_c_args + extra_args.get('c_args', []),
+    cpp_args : test_cpp_args + extra_args.get('cpp_args', []),
     dependencies : common_gio_tests_deps + extra_args.get('dependencies', []),
     install_rpath : extra_args.get('install_rpath', ''),
     install_dir: installed_tests_execdir,
diff --git a/glib/tests/meson.build b/glib/tests/meson.build
index d746178233..5bdef1b1ee 100644
--- a/glib/tests/meson.build
+++ b/glib/tests/meson.build
@@ -159,8 +159,19 @@ if have_cxx
   glib_tests += {
     'cxx' : {
       'source' : ['cxx.cpp'],
+      'suite': ['C++'],
     }
   }
+
+  foreach std, arg: cxx_standards
+    glib_tests += {
+      'cxx-@0@'.format(std) : {
+        'source' : ['cxx.cpp'],
+        'suite' : ['cpp'],
+        'cpp_args' : [arg],
+      },
+    }
+  endforeach
 endif
 
 if cc.get_id() != 'msvc'
@@ -244,6 +255,7 @@ test_env.set('MALLOC_CHECK_', '2')
 
 test_deps = [libm, thread_dep, libglib_dep]
 test_cargs = ['-DG_LOG_DOMAIN="GLib"', '-UG_DISABLE_ASSERT']
+test_cpp_args = test_cargs
 
 foreach test_name, extra_args : glib_tests
   source = extra_args.get('source', test_name + '.c')
@@ -264,6 +276,7 @@ foreach test_name, extra_args : glib_tests
 
   exe = executable(test_name, source,
     c_args : test_cargs + extra_args.get('c_args', []),
+    cpp_args : test_cpp_args + extra_args.get('cpp_args', []),
     link_args : extra_args.get('link_args', []),
     dependencies : test_deps + extra_args.get('dependencies', []),
     install_dir: installed_tests_execdir,
diff --git a/gmodule/tests/meson.build b/gmodule/tests/meson.build
index cc8125eda4..fd2257c1ad 100644
--- a/gmodule/tests/meson.build
+++ b/gmodule/tests/meson.build
@@ -15,8 +15,19 @@ if have_cxx
   gmodule_tests += {
     'cxx' : {
       'source' : ['cxx.cpp'],
+      'suite' : ['cpp'],
     }
   }
+
+  foreach std, arg: cxx_standards
+    gmodule_tests += {
+      'cxx-@0@'.format(std) : {
+        'source' : ['cxx.cpp'],
+        'suite' : ['cpp'],
+        'cpp_args' : [arg],
+      },
+    }
+  endforeach
 endif
 
 module_suffix = []
@@ -49,6 +60,7 @@ test_env.set('MALLOC_CHECK_', '2')
 
 test_deps = [libm, thread_dep, libglib_dep, libgmodule_dep]
 test_cargs = ['-DG_LOG_DOMAIN="GModule"', '-UG_DISABLE_ASSERT']
+test_cpp_args = test_cargs
 
 foreach test_name, extra_args : gmodule_tests
   source = extra_args.get('source', test_name + '.c')
@@ -69,6 +81,7 @@ foreach test_name, extra_args : gmodule_tests
 
   exe = executable(test_name, source,
     c_args : test_cargs + extra_args.get('c_args', []),
+    cpp_args : test_cpp_args + extra_args.get('cpp_args', []),
     link_args : extra_args.get('link_args', []),
     dependencies : test_deps + extra_args.get('dependencies', []),
     export_dynamic : extra_args.get('export_dynamic', false),
diff --git a/gobject/tests/meson.build b/gobject/tests/meson.build
index 58cf4ab1f7..94eae7527e 100644
--- a/gobject/tests/meson.build
+++ b/gobject/tests/meson.build
@@ -102,8 +102,19 @@ if have_cxx
   gobject_tests += {
     'cxx' : {
       'source' : ['cxx.cpp'],
+      'suite' : ['cpp'],
     },
   }
+
+  foreach std, arg: cxx_standards
+    gobject_tests += {
+      'cxx-@0@'.format(std) : {
+        'source' : ['cxx.cpp'],
+        'suite' : ['cpp'],
+        'cpp_args' : [arg],
+      },
+    }
+  endforeach
 endif
 
 if cc.get_id() != 'msvc'
@@ -125,6 +136,7 @@ test_env.set('MALLOC_CHECK_', '2')
 
 test_deps = [libm, thread_dep, libglib_dep, libgobject_dep]
 test_cargs = ['-DG_LOG_DOMAIN="GLib-GObject"', '-UG_DISABLE_ASSERT']
+test_cpp_args = test_cargs
 
 foreach test_name, extra_args : gobject_tests
   source = extra_args.get('source', test_name + '.c')
@@ -145,6 +157,7 @@ foreach test_name, extra_args : gobject_tests
 
   exe = executable(test_name, source,
     c_args : test_cargs + extra_args.get('c_args', []),
+    cpp_args : test_cpp_args + extra_args.get('cpp_args', []),
     dependencies : test_deps + extra_args.get('dependencies', []),
     install_dir: installed_tests_execdir,
     install: install,
diff --git a/meson.build b/meson.build
index f44fa2d4e7..56592e4917 100644
--- a/meson.build
+++ b/meson.build
@@ -13,6 +13,14 @@ cc = meson.get_compiler('c')
 have_cxx = add_languages('cpp', native: false, required: get_option('oss_fuzz').enabled())
 if have_cxx
   cxx = meson.get_compiler('cpp')
+  cxx_standards = {}
+
+  foreach std : ['98', '03', '11', '14', '17', '20', '2b', 'latest']
+    arg = (cxx.get_id() == 'msvc' ? '/std:' : '-std=') + 'c++' + std
+    if cxx.has_argument(arg)
+      cxx_standards += { std: arg }
+    endif
+  endforeach
 endif
 
 cc_can_run = meson.can_run_host_binaries()


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]