diff options
| author | Dylan Baker <dylan@pnwbakers.com> | 2024-09-06 09:30:29 -0700 |
|---|---|---|
| committer | Dylan Baker <dylan@pnwbakers.com> | 2025-01-27 09:37:58 -0800 |
| commit | d309e8d5f7ef4503bc493f498cae46129323f93b (patch) | |
| tree | 929ab13ce9d694b7476fe7a8c5dc065b4dfab730 /mesonbuild/compilers | |
| parent | 82fbf07a44204cd84fd9341450b10e471cf18a39 (diff) | |
| download | meson-d309e8d5f7ef4503bc493f498cae46129323f93b.tar.gz | |
compilers/objc: Use shared C standards with clang C compiler
This means that the two compilers will update together, and that ObjC
has the list behavior that C does.
Diffstat (limited to 'mesonbuild/compilers')
| -rw-r--r-- | mesonbuild/compilers/c.py | 9 | ||||
| -rw-r--r-- | mesonbuild/compilers/objc.py | 37 |
2 files changed, 27 insertions, 19 deletions
diff --git a/mesonbuild/compilers/c.py b/mesonbuild/compilers/c.py index 33f313ed9..0cc980e42 100644 --- a/mesonbuild/compilers/c.py +++ b/mesonbuild/compilers/c.py @@ -1,5 +1,6 @@ # SPDX-License-Identifier: Apache-2.0 # Copyright 2012-2020 The Meson development team +# Copyright © 2024-2025 Intel Corporation from __future__ import annotations @@ -47,9 +48,9 @@ if T.TYPE_CHECKING: else: CompilerMixinBase = object -_ALL_STDS = ['c89', 'c9x', 'c90', 'c99', 'c1x', 'c11', 'c17', 'c18', 'c2x', 'c23', 'c2y'] -_ALL_STDS += [f'gnu{std[1:]}' for std in _ALL_STDS] -_ALL_STDS += ['iso9899:1990', 'iso9899:199409', 'iso9899:1999', 'iso9899:2011', 'iso9899:2017', 'iso9899:2018'] +ALL_STDS = ['c89', 'c9x', 'c90', 'c99', 'c1x', 'c11', 'c17', 'c18', 'c2x', 'c23', 'c2y'] +ALL_STDS += [f'gnu{std[1:]}' for std in ALL_STDS] +ALL_STDS += ['iso9899:1990', 'iso9899:199409', 'iso9899:1999', 'iso9899:2011', 'iso9899:2017', 'iso9899:2018'] class CCompiler(CLikeCompiler, Compiler): @@ -98,7 +99,7 @@ class CCompiler(CLikeCompiler, Compiler): opts = super().get_options() key = self.form_compileropt_key('std') opts.update({ - key: options.UserStdOption('C', _ALL_STDS), + key: options.UserStdOption('C', ALL_STDS), }) return opts diff --git a/mesonbuild/compilers/objc.py b/mesonbuild/compilers/objc.py index 97550c2ea..de23e70cf 100644 --- a/mesonbuild/compilers/objc.py +++ b/mesonbuild/compilers/objc.py @@ -5,13 +5,13 @@ from __future__ import annotations import typing as T -from .. import options -from ..options import OptionKey +from ..options import OptionKey, UserStdOption +from .c import ALL_STDS from .compilers import Compiler +from .mixins.clang import ClangCompiler, ClangCStds from .mixins.clike import CLikeCompiler from .mixins.gnu import GnuCompiler, gnu_common_warning_args, gnu_objc_warning_args -from .mixins.clang import ClangCompiler if T.TYPE_CHECKING: from .. import coredata @@ -34,6 +34,14 @@ class ObjCCompiler(CLikeCompiler, Compiler): linker=linker) CLikeCompiler.__init__(self) + def get_options(self) -> coredata.MutableKeyedOptionDictType: + opts = super().get_options() + key = self.form_compileropt_key('std') + opts.update({ + key: UserStdOption('c', ALL_STDS), + }) + return opts + @staticmethod def get_display_language() -> str: return 'Objective-C' @@ -42,6 +50,11 @@ class ObjCCompiler(CLikeCompiler, Compiler): code = '#import<stddef.h>\nint main(void) { return 0; }\n' return self._sanity_check_impl(work_dir, environment, 'sanitycheckobjc.m', code) + def form_compileropt_key(self, basename: str) -> OptionKey: + if basename == 'std': + return OptionKey(f'c_{basename}', machine=self.for_machine) + return super().form_compileropt_key(basename) + class GnuObjCCompiler(GnuCompiler, ObjCCompiler): def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, @@ -62,7 +75,7 @@ class GnuObjCCompiler(GnuCompiler, ObjCCompiler): self.supported_warn_args(gnu_objc_warning_args))} -class ClangObjCCompiler(ClangCompiler, ObjCCompiler): +class ClangObjCCompiler(ClangCStds, ClangCompiler, ObjCCompiler): def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool, info: 'MachineInfo', defines: T.Optional[T.Dict[str, str]] = None, @@ -78,19 +91,9 @@ class ClangObjCCompiler(ClangCompiler, ObjCCompiler): '3': default_warn_args + ['-Wextra', '-Wpedantic'], 'everything': ['-Weverything']} - def get_options(self) -> 'coredata.MutableKeyedOptionDictType': - return self.update_options( - super().get_options(), - self.create_option(options.UserComboOption, - OptionKey('c_std', machine=self.for_machine), - 'C language standard to use', - ['none', 'c89', 'c99', 'c11', 'c17', 'gnu89', 'gnu99', 'gnu11', 'gnu17'], - 'none'), - ) - def get_option_compile_args(self, options: 'coredata.KeyedOptionDictType') -> T.List[str]: args = [] - std = options.get_value(OptionKey('c_std', machine=self.for_machine)) + std = options.get_value(self.form_compileropt_key('std')) if std != 'none': args.append('-std=' + std) return args @@ -98,3 +101,7 @@ class ClangObjCCompiler(ClangCompiler, ObjCCompiler): class AppleClangObjCCompiler(ClangObjCCompiler): """Handle the differences between Apple's clang and vanilla clang.""" + + _C17_VERSION = '>=10.0.0' + _C18_VERSION = '>=11.0.0' + _C2X_VERSION = '>=11.0.0' |
