From 4fcdbd6f840892a810d4caea4e60a64787a0f495 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Thu, 16 May 2024 14:23:12 +0100 Subject: [PATCH 1/2] build: Use C89 for the standard version check The '90' version is for ISO C90, but Meson does not understand it. As far as GCC and Clang are concerned, `-std=c89` is exactly the same as `-std=c90`. As of VS 2017, MSVC supports `/std:c11` as the minimum version of the C standard, with C89 (plus Microsoft extensions) being the default. See: - GCC: https://gcc.gnu.org/onlinedocs/gcc-14.1.0/gcc/C-Dialect-Options.html - MSVC: https://learn.microsoft.com/en-us/cpp/build/reference/std-specify-language-standard-version?view=msvc-170#c-standards-support-1 --- meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meson.build b/meson.build index 25dc0f2bc..1326c76b6 100644 --- a/meson.build +++ b/meson.build @@ -14,7 +14,7 @@ fs = import('fs') cc = meson.get_compiler('c') c_standards = {} -foreach std : ['90', '99', '11', '17'] +foreach std : ['89', '99', '11', '17'] arg = (cc.get_id() == 'msvc' ? '/std:' : '-std=') + 'c' + std if cc.has_argument(arg) c_standards += { std: arg } From 11157ca93618ebbd6bbfe6f9c5d66f9ddd5b9be5 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Thu, 16 May 2024 14:27:42 +0100 Subject: [PATCH 2/2] build: Use override_options for C standard selection Do not try to inject the C standard into `c_args`: Meson already generates a compiler command line with the appropriate C standard, and adding another one into it at a random position is either potentially undefined behaviour, or it's going to break the build because the compiler does not accept more than one switch. Meson has an `override_options` argument for the executable() object, and we are already using it in places. --- glib/tests/meson.build | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/glib/tests/meson.build b/glib/tests/meson.build index 5fbaa854b..4d5667fcd 100644 --- a/glib/tests/meson.build +++ b/glib/tests/meson.build @@ -372,10 +372,12 @@ foreach test_name, extra_args : 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), - '-D_G_EXPECTED_C_STANDARD="@0@"'.format(std) - ] + extra_args.get('c_args', []), + 'override_options' : extra_args.get('override_options', []) + [ + 'c_std=c@0@'.format(std), + ], + 'c_args' : extra_args.get('c_args', []) + [ + '-D_G_EXPECTED_C_STANDARD="@0@"'.format(std), + ], } } endif