Debian Codegraph @

mesonbuild/compilers/objc.py

raw
1 # SPDX-License-Identifier: Apache-2.0
2 # Copyright 2012-2017 The Meson development team
3
4 from __future__ import annotations
5
6 import typing as T
7
8 from ..options import OptionKey, UserStdOption
9
10 from .c import ALL_STDS
11 from .compilers import Compiler
12 from .mixins.apple import AppleCStdsMixin
13 from .mixins.clang import ClangCompiler, ClangCStds
14 from .mixins.clike import CLikeCompiler
15 from .mixins.gnu import GnuCompiler, GnuCStds, gnu_common_warning_args, gnu_objc_warning_args
16
17 if T.TYPE_CHECKING:
18 from ..environment import Environment
19 from ..linkers.linkers import DynamicLinker
20 from ..mesonlib import MachineChoice
21 from ..build import BuildTarget
22 from ..options import MutableKeyedOptionDictType
23
24
25 class ObjCCompiler(CLikeCompiler, Compiler):
26
27 language = 'objc'
28
29 def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice,
30 env: Environment,
31 linker: T.Optional['DynamicLinker'] = None,
32 full_version: T.Optional[str] = None):
33 Compiler.__init__(self, ccache, exelist, version, for_machine, env,
34 full_version=full_version,
35 linker=linker)
36 CLikeCompiler.__init__(self)
37
38 def get_options(self) -> MutableKeyedOptionDictType:
39 opts = super().get_options()
40 key = self.form_compileropt_key('std')
41 opts.update({
42 key: UserStdOption('c', ALL_STDS),
43 })
44 return opts
45
46 @staticmethod
47 def get_display_language() -> str:
48 return 'Objective-C'
49
50 def _sanity_check_source_code(self) -> str:
51 return '#import<stddef.h>\nint main(void) { return 0; }\n'
52
53 def form_compileropt_key(self, basename: str) -> OptionKey:
54 if basename == 'std':
55 return OptionKey(f'c_{basename}', machine=self.for_machine)
56 return super().form_compileropt_key(basename)
57
58
59 class GnuObjCCompiler(GnuCStds, GnuCompiler, ObjCCompiler):
60 def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice,
61 env: Environment,
62 defines: T.Optional[T.Dict[str, str]] = None,
63 linker: T.Optional['DynamicLinker'] = None,
64 full_version: T.Optional[str] = None):
65 ObjCCompiler.__init__(self, ccache, exelist, version, for_machine,
66 env, linker=linker, full_version=full_version)
67 GnuCompiler.__init__(self, defines)
68 default_warn_args = ['-Wall', '-Winvalid-pch']
69 self.warn_args = {'0': [],
70 '1': default_warn_args,
71 '2': default_warn_args + ['-Wextra'],
72 '3': default_warn_args + ['-Wextra', '-Wpedantic'],
73 'everything': (default_warn_args + ['-Wextra', '-Wpedantic'] +
74 self.supported_warn_args(gnu_common_warning_args) +
75 self.supported_warn_args(gnu_objc_warning_args))}
76
77 def get_option_std_args(self, target: BuildTarget, subproject: T.Optional[str] = None) -> T.List[str]:
78 args: T.List[str] = []
79 key = OptionKey('c_std', subproject=subproject, machine=self.for_machine)
80 if target:
81 std = self.environment.coredata.get_option_for_target(target, key)
82 else:
83 std = self.environment.coredata.optstore.get_value_for(key)
84 assert isinstance(std, str)
85 if std != 'none':
86 args.append('-std=' + std)
87 return args
88
89 class ClangObjCCompiler(ClangCStds, ClangCompiler, ObjCCompiler):
90 def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice,
91 env: Environment,
92 defines: T.Optional[T.Dict[str, str]] = None,
93 linker: T.Optional['DynamicLinker'] = None,
94 full_version: T.Optional[str] = None):
95 ObjCCompiler.__init__(self, ccache, exelist, version, for_machine,
96 env, linker=linker, full_version=full_version)
97 ClangCompiler.__init__(self, defines)
98 default_warn_args = ['-Wall', '-Winvalid-pch']
99 self.warn_args = {'0': [],
100 '1': default_warn_args,
101 '2': default_warn_args + ['-Wextra'],
102 '3': default_warn_args + ['-Wextra', '-Wpedantic'],
103 'everything': ['-Weverything']}
104
105 def form_compileropt_key(self, basename: str) -> OptionKey:
106 if basename == 'std':
107 return OptionKey('c_std', machine=self.for_machine)
108 return super().form_compileropt_key(basename)
109
110 def make_option_name(self, key: OptionKey) -> str:
111 if key.name == 'std':
112 return 'c_std'
113 return super().make_option_name(key)
114
115 def get_option_std_args(self, target: BuildTarget, subproject: T.Optional[str] = None) -> T.List[str]:
116 args = []
117 key = OptionKey('c_std', machine=self.for_machine)
118 std = self.get_compileropt_value(key, target, subproject)
119 assert isinstance(std, str)
120 if std != 'none':
121 args.append('-std=' + std)
122 return args
123
124 class AppleClangObjCCompiler(AppleCStdsMixin, ClangObjCCompiler):
125
126 """Handle the differences between Apple's clang and vanilla clang."""