From ea50418006886cac96513167af6d7f954ca0ccc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20Andr=C3=A9=20Vadla=20Ravn=C3=A5s?= Date: Tue, 5 Mar 2024 13:50:21 +0100 Subject: [PATCH] objc: Fix handling of `c_std` option with fallback This is only a stopgap, as a clean solution would require some refactoring. --- mesonbuild/compilers/objc.py | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/mesonbuild/compilers/objc.py b/mesonbuild/compilers/objc.py index 23008e62cae8..82a11b4e9e20 100644 --- a/mesonbuild/compilers/objc.py +++ b/mesonbuild/compilers/objc.py @@ -9,6 +9,7 @@ from ..mesonlib import OptionKey from .compilers import Compiler +from .c import _ALL_STDS, _ClangCStds from .mixins.clike import CLikeCompiler from .mixins.gnu import GnuCompiler, gnu_common_warning_args, gnu_objc_warning_args from .mixins.clang import ClangCompiler @@ -74,6 +75,7 @@ def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_ ObjCCompiler.__init__(self, ccache, exelist, version, for_machine, is_cross, info, exe_wrapper, linker=linker, full_version=full_version) ClangCompiler.__init__(self, defines) + self._clang_objcstds = _ClangObjCStds(version, for_machine) default_warn_args = ['-Wall', '-Winvalid-pch'] self.warn_args = {'0': [], '1': default_warn_args, @@ -83,13 +85,7 @@ def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_ def get_options(self) -> 'coredata.MutableKeyedOptionDictType': opts = super().get_options() - opts.update({ - OptionKey('std', machine=self.for_machine, lang='c'): coredata.UserComboOption( - 'C language standard to use', - ['none', 'c89', 'c99', 'c11', 'c17', 'gnu89', 'gnu99', 'gnu11', 'gnu17'], - 'none', - ) - }) + opts.update(self._clang_objcstds.get_options()) return opts def get_option_compile_args(self, options: 'coredata.KeyedOptionDictType') -> T.List[str]: @@ -99,6 +95,30 @@ def get_option_compile_args(self, options: 'coredata.KeyedOptionDictType') -> T. args.append('-std=' + std.value) return args +class _ClangObjCStdsBase: + language = 'c' + + def __init__(self, version: str, for_machine: MachineChoice): + self.version = version + self.for_machine = for_machine + + def get_options(self) -> 'coredata.MutableKeyedOptionDictType': + key = OptionKey('std', machine=self.for_machine, lang=self.language) + return {key: coredata.UserStdOption('C', _ALL_STDS)} + +class _ClangObjCStds(_ClangCStds, _ClangObjCStdsBase): + def __init__(self, version: str, for_machine: MachineChoice): + _ClangObjCStdsBase.__init__(self, version, for_machine) + + def get_output_args(self, outputname: str) -> T.List[str]: + pass + + def get_optimization_args(self, optimization_level: str) -> T.List[str]: + return [] + + def sanity_check(self, work_dir: str, environment: 'Environment') -> None: + pass + class AppleClangObjCCompiler(ClangObjCCompiler): """Handle the differences between Apple's clang and vanilla clang."""