From a441b13b89b528e90576ea5fe0f881998b6b11f7 Mon Sep 17 00:00:00 2001 From: jpark37 Date: Fri, 13 Nov 2020 16:11:03 -0800 Subject: [PATCH 1/2] Use c99 instead of c11 for buildoptions test Older verisons of MSVC do not support C11 properly. --- test cases/unit/59 introspect buildoptions/meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test cases/unit/59 introspect buildoptions/meson.build b/test cases/unit/59 introspect buildoptions/meson.build index 16df028e3..9cfdc2c96 100644 --- a/test cases/unit/59 introspect buildoptions/meson.build +++ b/test cases/unit/59 introspect buildoptions/meson.build @@ -1,4 +1,4 @@ -project('introspect buildargs', ['c'], default_options: ['c_std=c11', 'cpp_std=c++14', 'buildtype=release']) +project('introspect buildargs', ['c'], default_options: ['c_std=c99', 'cpp_std=c++14', 'buildtype=release']) subA = subproject('projectA') From 2748c9fb3d6e3195f5cb8adb31f0565f8b49436d Mon Sep 17 00:00:00 2001 From: jpark37 Date: Tue, 10 Nov 2020 20:32:23 -0800 Subject: [PATCH 2/2] msvc: enable /std:c17 flag Increase allowed c_std options, and check compiler version. Also update mlog pattern to not crash. --- mesonbuild/compilers/c.py | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/mesonbuild/compilers/c.py b/mesonbuild/compilers/c.py index 49008768a..985f6f3ae 100644 --- a/mesonbuild/compilers/c.py +++ b/mesonbuild/compilers/c.py @@ -410,6 +410,9 @@ class VisualStudioLikeCCompilerMixin(CompilerMixinBase): class VisualStudioCCompiler(MSVCCompiler, VisualStudioLikeCCompilerMixin, CCompiler): + _C11_VERSION = '>=19.28' + _C17_VERSION = '>=19.28' + def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool, info: 'MachineInfo', target: str, exe_wrapper: T.Optional['ExternalProgram'] = None, @@ -422,25 +425,33 @@ class VisualStudioCCompiler(MSVCCompiler, VisualStudioLikeCCompilerMixin, CCompi def get_options(self) -> 'OptionDictType': opts = super().get_options() - c_stds = ['none', 'c89', 'c99', 'c11', + c_stds = ['c89', 'c99'] # Need to have these to be compatible with projects # that set c_std to e.g. gnu99. # https://github.com/mesonbuild/meson/issues/7611 - 'gnu89', 'gnu90', 'gnu9x', 'gnu99', 'gnu1x', 'gnu11'] - opts['std'].choices = c_stds # type: ignore + g_stds = ['gnu89', 'gnu90', 'gnu9x', 'gnu99'] + if version_compare(self.version, self._C11_VERSION): + c_stds += ['c11'] + g_stds += ['gnu1x', 'gnu11'] + if version_compare(self.version, self._C17_VERSION): + c_stds += ['c17', 'c18'] + g_stds += ['gnu17', 'gnu18'] + opts['std'].choices = ['none'] + c_stds + g_stds # type: ignore return opts def get_option_compile_args(self, options: 'OptionDictType') -> T.List[str]: args = [] std = options['std'] if std.value.startswith('gnu'): - mlog.log( + mlog.log_once( 'cl.exe does not actually support gnu standards, and meson ' 'will instead demote to the nearest ISO C standard. This ' - 'may cause compilation to fail.', once=True) - # As of MVSC 16.7, /std:c11 is the only valid C standard option. - if std.value in {'c11', 'gnu11'}: + 'may cause compilation to fail.') + # As of MVSC 16.8, /std:c11 and /std:c17 are the only valid C standard options. + if std.value in {'c11', 'gnu1x', 'gnu11'}: args.append('/std:c11') + elif std.value in {'c17', 'c18', 'gnu17', 'gnu18'}: + args.append('/std:c17') return args @@ -485,7 +496,7 @@ class IntelClCCompiler(IntelVisualStudioLikeCompiler, VisualStudioLikeCCompilerM args = [] std = options['std'] if std.value == 'c89': - mlog.log("ICL doesn't explicitly implement c89, setting the standard to 'none', which is close.", once=True) + mlog.log_once("ICL doesn't explicitly implement c89, setting the standard to 'none', which is close.") elif std.value != 'none': args.append('/Qstd:' + std.value) return args