[glib/c-cxx-std-versions: 5/7] meson: Compile some tests with multiple C standards




commit de1e0036c8734e1f65d8c2e20ea9ed66b2eb292c
Author: Marco Trevisan (TreviƱo) <mail 3v1n0 net>
Date:   Wed Sep 14 04:15:58 2022 +0200

    meson: Compile some tests with multiple C standards
    
    We need to ensure that all the expected macros and utilities are working
    with all the supported C standards, so just repeat the tests with all
    the ones the compiler supports.

 glib/tests/meson.build | 23 +++++++++++++++++++++--
 meson.build            |  9 +++++++++
 2 files changed, 30 insertions(+), 2 deletions(-)
---
diff --git a/glib/tests/meson.build b/glib/tests/meson.build
index 429218cf54..5108944c19 100644
--- a/glib/tests/meson.build
+++ b/glib/tests/meson.build
@@ -3,6 +3,7 @@ glib_tests = {
   'asyncqueue' : {},
   'atomic' : {
     'c_args' : cc.get_id() == 'gcc' ? ['-Wstrict-aliasing=2'] : [],
+    'c_standards': c_standards.keys(),
   },
   'base64' : {},
   'bitlock' : {},
@@ -47,7 +48,9 @@ glib_tests = {
   'keyfile' : {},
   'list' : {},
   'logging' : {},
-  'macros' : {},
+  'macros' : {
+    'c_standards': c_standards.keys(),
+  },
   'mainloop' : {},
   'mappedfile' : {},
   'mapping' : {},
@@ -133,7 +136,9 @@ glib_tests = {
   'utf8-pointer' : {},
   'utf8-validate' : {},
   'utf8-misc' : {},
-  'utils' : {},
+  'utils' : {
+    'c_standards': c_standards.keys(),
+  },
   'unicode' : {},
   'unicode-encoding' : {},
   'unicode-normalize': {},
@@ -258,6 +263,20 @@ if installed_tests_enabled
   )
 endif
 
+foreach test_name, extra_args : glib_tests
+  foreach std: extra_args.get('c_standards', [])
+    if c_standards.has_key(std)
+      glib_tests += {
+        '@0@-c-@1@'.format(test_name, std) : extra_args + {
+          'source' : extra_args.get('source', test_name + '.c'),
+          'suite' : ['cc'] + extra_args.get('suite', []),
+          'c_args' : [c_standards.get(std)] + extra_args.get('c_args', []),
+        }
+      }
+    endif
+  endforeach
+endforeach
+
 test_env = environment(common_test_env)
 test_env.set('G_TEST_SRCDIR', meson.current_source_dir())
 test_env.set('G_TEST_BUILDDIR', meson.current_build_dir())
diff --git a/meson.build b/meson.build
index 54445db691..cb06af6e9d 100644
--- a/meson.build
+++ b/meson.build
@@ -10,6 +10,15 @@ project('glib', 'c',
 )
 
 cc = meson.get_compiler('c')
+c_standards = {}
+
+foreach std : ['90', '99', '11', '17']
+  arg = (cc.get_id() == 'msvc' ? '/std:' : '-std=') + 'c' + std
+  if cc.has_argument(arg)
+    c_standards += { std: arg }
+  endif
+endforeach
+
 have_cxx = add_languages('cpp', native: false, required: get_option('oss_fuzz').enabled())
 if have_cxx
   cxx = meson.get_compiler('cpp')


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