Debian Codegraph @

mesonbuild/compilers/cpp.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 functools
7 import os.path
8 import typing as T
9
10 from .. import options
11 from .. import mlog
12 from ..mesonlib import MesonException, version_compare, lazy_property
13
14 from .compilers import (
15 gnu_winlibs,
16 msvc_winlibs,
17 Compiler,
18 CompileCheckMode,
19 )
20 from .c_function_attributes import CXX_FUNC_ATTRIBUTES, C_FUNC_ATTRIBUTES
21 from .mixins.apple import AppleCompilerMixin, AppleCPPStdsMixin
22 from .mixins.clike import CLikeCompiler
23 from .mixins.ccrx import CcrxCompiler
24 from .mixins.ti import TICompiler
25 from .mixins.arm import ArmCompiler, ArmclangCompiler
26 from .mixins.visualstudio import MSVCCompiler, ClangClCompiler
27 from .mixins.gnu import GnuCompiler, GnuCPPStds, gnu_common_warning_args, gnu_cpp_warning_args
28 from .mixins.intel import IntelGnuLikeCompiler, IntelLLVMLikeCompiler, IntelVisualStudioLikeCompiler
29 from .mixins.clang import ClangCompiler, ClangCPPStds
30 from .mixins.elbrus import ElbrusCompiler
31 from .mixins.pgi import PGICompiler
32 from .mixins.emscripten import EmscriptenMixin
33 from .mixins.metrowerks import MetrowerksCompiler
34 from .mixins.metrowerks import mwccarm_instruction_set_args, mwcceppc_instruction_set_args
35 from .mixins.microchip import Xc32Compiler, Xc32CPPStds
36
37 if T.TYPE_CHECKING:
38 from ..options import MutableKeyedOptionDictType
39 from ..dependencies import Dependency
40 from ..environment import Environment
41 from ..linkers.linkers import DynamicLinker
42 from ..mesonlib import MachineChoice
43 from ..build import BuildTarget
44 CompilerMixinBase = CLikeCompiler
45 else:
46 CompilerMixinBase = object
47
48 ALL_STDS = ['c++98', 'c++0x', 'c++03', 'c++1y', 'c++1z', 'c++11', 'c++14', 'c++17']
49 ALL_STDS += ['c++2a', 'c++2b', 'c++2c', 'c++20', 'c++23', 'c++26']
50 ALL_STDS += [f'gnu{std[1:]}' for std in ALL_STDS]
51 ALL_STDS += ['vc++11', 'vc++14', 'vc++17', 'vc++20', 'vc++23', 'vc++latest', 'c++latest']
52
53
54 def non_msvc_eh_options(eh: str, args: T.List[str]) -> None:
55 if eh == 'none':
56 args.append('-fno-exceptions')
57 elif eh in {'s', 'c'}:
58 mlog.warning(f'non-MSVC compilers do not support {eh} exception handling. '
59 'You may want to set eh to \'default\'.', fatal=False)
60
61 class CPPCompiler(CLikeCompiler, Compiler):
62 def attribute_check_func(self, name: str) -> str:
63 try:
64 return CXX_FUNC_ATTRIBUTES.get(name, C_FUNC_ATTRIBUTES[name])
65 except KeyError:
66 raise MesonException(f'Unknown function attribute "{name}"')
67
68 language = 'cpp'
69
70 def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice,
71 env: Environment, linker: T.Optional['DynamicLinker'] = None,
72 full_version: T.Optional[str] = None):
73 # If a child ObjCPP class has already set it, don't set it ourselves
74 Compiler.__init__(self, ccache, exelist, version, for_machine, env,
75 linker=linker, full_version=full_version)
76 CLikeCompiler.__init__(self)
77
78 @classmethod
79 def get_display_language(cls) -> str:
80 return 'C++'
81
82 def get_no_stdinc_args(self) -> T.List[str]:
83 return ['-nostdinc++']
84
85 def get_no_stdlib_link_args(self) -> T.List[str]:
86 return ['-nostdlib++']
87
88 def get_cpp_modules_args(self) -> T.List[str]:
89 return []
90
91 def _sanity_check_source_code(self) -> str:
92 return '#include <stddef.h>\nclass breakCCompiler;int main(void) { return 0; }\n'
93
94 def get_cpp_permissive_args(self) -> T.List[str]:
95 return []
96
97 def get_compiler_check_args(self, mode: CompileCheckMode) -> T.List[str]:
98 # Compiler checks must accept non-conforming code. Particularly, the
99 # has_header_symbol check is too strict without this and always fails.
100 return super().get_compiler_check_args(mode) + self.get_cpp_permissive_args()
101
102 def has_header_symbol(self, hname: str, symbol: str, prefix: str, *,
103 extra_args: T.Union[None, T.List[str], T.Callable[[CompileCheckMode], T.List[str]]] = None,
104 dependencies: T.Optional[T.List['Dependency']] = None) -> T.Tuple[bool, bool]:
105 # Check if it's a C-like symbol
106 found, cached = super().has_header_symbol(hname, symbol, prefix,
107 extra_args=extra_args,
108 dependencies=dependencies)
109 if found:
110 return True, cached
111 # Check if it's a class or a template
112 if extra_args is None:
113 extra_args = []
114 t = f'''{prefix}
115 #include <{hname}>
116 using {symbol};
117 int main(void) {{ return 0; }}'''
118 return self.compiles(t, extra_args=extra_args,
119 dependencies=dependencies)
120
121 def _test_cpp_std_arg(self, cpp_std_value: str) -> bool:
122 # Test whether the compiler understands a -std=XY argument
123 assert cpp_std_value.startswith('-std=')
124
125 # This test does not use has_multi_arguments() for two reasons:
126 # 1. has_multi_arguments() requires an env argument, which the compiler
127 # object does not have at this point.
128 # 2. even if it did have an env object, that might contain another more
129 # recent -std= argument, which might lead to a cascaded failure.
130 CPP_TEST = 'int i = static_cast<int>(0);'
131 with self.compile(CPP_TEST, extra_args=[cpp_std_value], mode=CompileCheckMode.COMPILE) as p:
132 if p.returncode == 0:
133 mlog.debug(f'Compiler accepts {cpp_std_value}:', 'YES')
134 return True
135 else:
136 mlog.debug(f'Compiler accepts {cpp_std_value}:', 'NO')
137 return False
138
139 @functools.lru_cache()
140 def _find_best_cpp_std(self, cpp_std: str) -> str:
141 # The initial version mapping approach to make falling back
142 # from '-std=c++14' to '-std=c++1y' was too brittle. For instance,
143 # Apple's Clang uses a different versioning scheme to upstream LLVM,
144 # making the whole detection logic awfully brittle. Instead, let's
145 # just see if feeding GCC or Clang our '-std=' setting works, and
146 # if not, try the fallback argument.
147 CPP_FALLBACKS = {
148 'c++11': 'c++0x',
149 'gnu++11': 'gnu++0x',
150 'c++14': 'c++1y',
151 'gnu++14': 'gnu++1y',
152 'c++17': 'c++1z',
153 'gnu++17': 'gnu++1z',
154 'c++20': 'c++2a',
155 'gnu++20': 'gnu++2a',
156 'c++23': 'c++2b',
157 'gnu++23': 'gnu++2b',
158 'c++26': 'c++2c',
159 'gnu++26': 'gnu++2c',
160 }
161
162 # Currently, remapping is only supported for Clang, Elbrus and GCC
163 assert self.id in frozenset(['clang', 'lcc', 'gcc', 'emscripten', 'armltdclang', 'intel-llvm', 'nvidia_hpc', 'xc32-gcc'])
164
165 if cpp_std not in CPP_FALLBACKS:
166 # 'c++03' and 'c++98' don't have fallback types
167 return '-std=' + cpp_std
168
169 for i in (cpp_std, CPP_FALLBACKS[cpp_std]):
170 cpp_std_value = '-std=' + i
171 if self._test_cpp_std_arg(cpp_std_value):
172 return cpp_std_value
173
174 raise MesonException(f'C++ Compiler does not support -std={cpp_std}')
175
176 def get_options(self) -> 'MutableKeyedOptionDictType':
177 opts = super().get_options()
178 key = self.form_compileropt_key('std')
179 opts.update({
180 key: options.UserStdOption('cpp', ALL_STDS),
181 })
182 return opts
183
184
185 class _StdCPPLibMixin(CompilerMixinBase):
186
187 """Detect whether to use libc++ or libstdc++."""
188
189 @lazy_property
190 def language_stdlib_provider(self) -> str:
191 # https://stackoverflow.com/a/31658120
192 header = 'version' if self.has_header('version', '')[0] else 'ciso646'
193 is_libcxx = self.has_header_symbol(header, '_LIBCPP_VERSION', '')[0]
194 lib = 'c++' if is_libcxx else 'stdc++'
195 return lib
196
197 @functools.lru_cache(None)
198 def language_stdlib_only_link_flags(self) -> T.List[str]:
199 """Detect the C++ stdlib and default search dirs
200
201 As an optimization, this method will cache the value, to avoid building the same values over and over
202
203 :raises MesonException: If a stdlib cannot be determined
204 """
205
206 # We need to apply the search prefix here, as these link arguments may
207 # be passed to a different compiler with a different set of default
208 # search paths, such as when using Clang for C/C++ and gfortran for
209 # fortran.
210 search_dirs = [f'-L{d}' for d in self.get_compiler_dirs('libraries')]
211
212 lib = self.language_stdlib_provider
213 if self.find_library(lib, []) is not None:
214 return search_dirs + [f'-l{lib}']
215
216 # TODO: maybe a bug exception?
217 raise MesonException('Could not detect either libc++ or libstdc++ as your C++ stdlib implementation.')
218
219
220 class ClangCPPCompiler(_StdCPPLibMixin, ClangCPPStds, ClangCompiler, CPPCompiler):
221
222 def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice,
223 env: Environment, linker: T.Optional['DynamicLinker'] = None,
224 defines: T.Optional[T.Dict[str, str]] = None,
225 full_version: T.Optional[str] = None):
226 CPPCompiler.__init__(self, ccache, exelist, version, for_machine,
227 env, linker=linker, full_version=full_version)
228 ClangCompiler.__init__(self, defines)
229 default_warn_args = ['-Wall', '-Winvalid-pch']
230 self.warn_args = {'0': [],
231 '1': default_warn_args,
232 '2': default_warn_args + ['-Wextra'],
233 '3': default_warn_args + ['-Wextra', '-Wpedantic'],
234 'everything': ['-Weverything']}
235
236 def get_options(self) -> 'MutableKeyedOptionDictType':
237 opts = super().get_options()
238
239 key = self.form_compileropt_key('eh')
240 opts[key] = options.UserComboOption(
241 self.make_option_name(key),
242 'C++ exception handling type.',
243 'default',
244 choices=['none', 'default', 'a', 's', 'sc'])
245
246 key = self.form_compileropt_key('rtti')
247 opts[key] = options.UserBooleanOption(
248 self.make_option_name(key),
249 'Enable RTTI',
250 True)
251
252 key = self.form_compileropt_key('debugstl')
253 opts[key] = options.UserBooleanOption(
254 self.make_option_name(key),
255 'STL debug mode',
256 False)
257
258 if self.info.is_windows() or self.info.is_cygwin():
259 key = self.form_compileropt_key('winlibs')
260 opts[key] = options.UserStringArrayOption(
261 self.make_option_name(key),
262 'Standard Win libraries to link against',
263 gnu_winlibs)
264 return opts
265
266 def get_option_compile_args(self, target: 'BuildTarget', subproject: T.Optional[str] = None) -> T.List[str]:
267 args: T.List[str] = []
268
269 rtti = self.get_compileropt_value('rtti', target, subproject)
270 debugstl = self.get_compileropt_value('debugstl', target, subproject)
271 eh = self.get_compileropt_value('eh', target, subproject)
272
273 assert isinstance(rtti, bool)
274 assert isinstance(eh, str)
275 assert isinstance(debugstl, bool)
276
277 non_msvc_eh_options(eh, args)
278
279 if debugstl:
280 args.append('-D_GLIBCXX_DEBUG=1')
281
282 # We can't do _LIBCPP_DEBUG because it's unreliable unless libc++ was built with it too:
283 # https://discourse.llvm.org/t/building-a-program-with-d-libcpp-debug-1-against-a-libc-that-is-not-itself-built-with-that-define/59176/3
284 # Note that unlike _GLIBCXX_DEBUG, _MODE_DEBUG doesn't break ABI. It's just slow.
285 if version_compare(self.version, '>=18'):
286 args.append('-U_LIBCPP_HARDENING_MODE')
287 args.append('-D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_DEBUG')
288
289 if not rtti:
290 args.append('-fno-rtti')
291
292 return args
293
294 def get_option_std_args(self, target: BuildTarget, subproject: T.Optional[str] = None) -> T.List[str]:
295 args: T.List[str] = []
296 std = self.get_compileropt_value('std', target, subproject)
297 assert isinstance(std, str)
298 if std != 'none':
299 args.append(self._find_best_cpp_std(std))
300 return args
301
302 def get_option_link_args(self, target: 'BuildTarget', subproject: T.Optional[str] = None) -> T.List[str]:
303 if self.info.is_windows() or self.info.is_cygwin():
304 # without a typedict mypy can't understand this.
305 retval = self.get_compileropt_value('winlibs', target, subproject)
306 assert isinstance(retval, list)
307 libs = retval[:]
308 for l in libs:
309 assert isinstance(l, str)
310 return libs
311 return []
312
313 def get_assert_args(self, disable: bool) -> T.List[str]:
314 if disable:
315 return ['-DNDEBUG']
316
317 # Don't inject the macro if the compiler already has it pre-defined.
318 for macro in ['_GLIBCXX_ASSERTIONS', '_LIBCPP_HARDENING_MODE', '_LIBCPP_ENABLE_ASSERTIONS']:
319 if self.defines.get(macro) is not None:
320 return []
321
322 if self.language_stdlib_provider == 'stdc++':
323 return ['-D_GLIBCXX_ASSERTIONS=1']
324
325 return ['-D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_FAST']
326
327 def get_pch_use_args(self, pch_dir: str, header: str) -> T.List[str]:
328 args = super().get_pch_use_args(pch_dir, header)
329 if version_compare(self.version, '>=11'):
330 return ['-fpch-instantiate-templates'] + args
331 return args
332
333 def get_cpp_modules_args(self) -> T.List[str]:
334 # Although -fmodules-ts is removed in LLVM 17, we keep this in for compatibility with old compilers.
335 return ['-fmodules', '-fmodules-ts']
336
337
338 class ArmLtdClangCPPCompiler(ClangCPPCompiler):
339
340 id = 'armltdclang'
341
342
343 class AppleClangCPPCompiler(AppleCompilerMixin, AppleCPPStdsMixin, ClangCPPCompiler):
344 pass
345
346
347 class EmscriptenCPPCompiler(EmscriptenMixin, ClangCPPCompiler):
348
349 id = 'emscripten'
350
351 # Emscripten uses different version numbers than Clang; `emcc -v` will show
352 # the Clang version number used as well (but `emcc --version` does not).
353 # See https://github.com/pyodide/pyodide/discussions/4762 for more on
354 # emcc <--> clang versions. Note, although earlier versions claim to be the
355 # Clang versions 12.0.0 and 17.0.0 required for these C++ standards, they
356 # only accept the flags in the later versions below.
357 _CPP23_VERSION = '>=2.0.10'
358 _CPP26_VERSION = '>=3.1.39'
359
360 def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice,
361 env: Environment, linker: T.Optional['DynamicLinker'] = None,
362 defines: T.Optional[T.Dict[str, str]] = None,
363 full_version: T.Optional[str] = None):
364 if not env.is_cross_build(for_machine):
365 raise MesonException('Emscripten compiler can only be used for cross compilation.')
366 if not version_compare(version, '>=1.39.19'):
367 raise MesonException('Meson requires Emscripten >= 1.39.19')
368 ClangCPPCompiler.__init__(self, ccache, exelist, version, for_machine, env,
369 linker=linker, defines=defines, full_version=full_version)
370
371 def get_option_std_args(self, target: BuildTarget, subproject: T.Optional[str] = None) -> T.List[str]:
372 args: T.List[str] = []
373 std = self.get_compileropt_value('std', target, subproject)
374 assert isinstance(std, str)
375 if std != 'none':
376 args.append(self._find_best_cpp_std(std))
377 return args
378
379
380 class ArmclangCPPCompiler(ArmclangCompiler, CPPCompiler):
381 '''
382 Keil armclang
383 '''
384
385 def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice,
386 env: Environment, linker: T.Optional['DynamicLinker'] = None,
387 full_version: T.Optional[str] = None):
388 CPPCompiler.__init__(self, ccache, exelist, version, for_machine,
389 env, linker=linker, full_version=full_version)
390 ArmclangCompiler.__init__(self)
391 default_warn_args = ['-Wall', '-Winvalid-pch']
392 self.warn_args = {'0': [],
393 '1': default_warn_args,
394 '2': default_warn_args + ['-Wextra'],
395 '3': default_warn_args + ['-Wextra', '-Wpedantic'],
396 'everything': ['-Weverything']}
397
398 def get_options(self) -> 'MutableKeyedOptionDictType':
399 opts = super().get_options()
400
401 key = self.form_compileropt_key('eh')
402 opts[key] = options.UserComboOption(
403 self.make_option_name(key),
404 'C++ exception handling type.',
405 'default',
406 choices=['none', 'default', 'a', 's', 'sc'])
407
408 key = self.form_compileropt_key('std')
409 std_opt = opts[key]
410 assert isinstance(std_opt, options.UserStdOption), 'for mypy'
411 std_opt.set_versions(['c++98', 'c++03', 'c++11', 'c++14', 'c++17'], gnu=True)
412 return opts
413
414 def get_option_std_args(self, target: BuildTarget, subproject: T.Optional[str] = None) -> T.List[str]:
415 args: T.List[str] = []
416 std = self.get_compileropt_value('std', target, subproject)
417 assert isinstance(std, str)
418 if std != 'none':
419 args.append('-std=' + std)
420
421 eh = self.get_compileropt_value('eh', target, subproject)
422 assert isinstance(eh, str)
423 non_msvc_eh_options(eh, args)
424
425 return args
426
427 def get_option_link_args(self, target: 'BuildTarget', subproject: T.Optional[str] = None) -> T.List[str]:
428 return []
429
430
431 class GnuCPPCompiler(_StdCPPLibMixin, GnuCPPStds, GnuCompiler, CPPCompiler):
432 def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice,
433 env: Environment, linker: T.Optional['DynamicLinker'] = None,
434 defines: T.Optional[T.Dict[str, str]] = None,
435 full_version: T.Optional[str] = None):
436 CPPCompiler.__init__(self, ccache, exelist, version, for_machine,
437 env, linker=linker, full_version=full_version)
438 GnuCompiler.__init__(self, defines)
439 default_warn_args = ['-Wall', '-Winvalid-pch']
440 self.warn_args = {'0': [],
441 '1': default_warn_args,
442 '2': default_warn_args + ['-Wextra'],
443 '3': default_warn_args + ['-Wextra', '-Wpedantic'],
444 'everything': (default_warn_args + ['-Wextra', '-Wpedantic'] +
445 self.supported_warn_args(gnu_common_warning_args) +
446 self.supported_warn_args(gnu_cpp_warning_args))}
447
448 def get_options(self) -> 'MutableKeyedOptionDictType':
449 opts = super().get_options()
450
451 key = self.form_compileropt_key('eh')
452 opts[key] = options.UserComboOption(
453 self.make_option_name(key),
454 'C++ exception handling type.',
455 'default',
456 choices=['none', 'default', 'a', 's', 'sc'])
457
458 key = self.form_compileropt_key('rtti')
459 opts[key] = options.UserBooleanOption(
460 self.make_option_name(key),
461 'Enable RTTI',
462 True)
463
464 key = self.form_compileropt_key('debugstl')
465 opts[key] = options.UserBooleanOption(
466 self.make_option_name(key),
467 'STL debug mode',
468 False)
469
470 if self.info.is_windows() or self.info.is_cygwin():
471 key = key.evolve(name='cpp_winlibs')
472 opts[key] = options.UserStringArrayOption(
473 self.make_option_name(key),
474 'Standard Win libraries to link against',
475 gnu_winlibs)
476
477 if version_compare(self.version, '>=15.1'):
478 key = key.evolve(name='cpp_importstd')
479 opts[key] = options.UserComboOption(self.make_option_name(key),
480 'Use #import std.',
481 'false',
482 choices=['false', 'true'])
483
484 return opts
485
486 def get_option_compile_args(self, target: 'BuildTarget', subproject: T.Optional[str] = None) -> T.List[str]:
487 args: T.List[str] = []
488
489 rtti = self.get_compileropt_value('rtti', target, subproject)
490 debugstl = self.get_compileropt_value('debugstl', target, subproject)
491 eh = self.get_compileropt_value('eh', target, subproject)
492
493 assert isinstance(rtti, bool)
494 assert isinstance(eh, str)
495 assert isinstance(debugstl, bool)
496
497 non_msvc_eh_options(eh, args)
498
499 if not rtti:
500 args.append('-fno-rtti')
501
502 # We may want to handle libc++'s debugstl mode here too
503 if debugstl:
504 args.append('-D_GLIBCXX_DEBUG=1')
505 return args
506
507 def get_option_std_args(self, target: BuildTarget, subproject: T.Optional[str] = None) -> T.List[str]:
508 args: T.List[str] = []
509 std = self.get_compileropt_value('std', target, subproject)
510 assert isinstance(std, str)
511 if std != 'none':
512 args.append(self._find_best_cpp_std(std))
513 return args
514
515 def get_option_link_args(self, target: 'BuildTarget', subproject: T.Optional[str] = None) -> T.List[str]:
516 if self.info.is_windows() or self.info.is_cygwin():
517 # without a typedict mypy can't understand this.
518 retval = self.get_compileropt_value('winlibs', target, subproject)
519 assert isinstance(retval, list)
520 libs: T.List[str] = retval[:]
521 for l in libs:
522 assert isinstance(l, str)
523 return libs
524 return []
525
526 def get_assert_args(self, disable: bool) -> T.List[str]:
527 if disable:
528 return ['-DNDEBUG']
529
530 # Don't inject the macro if the compiler already has it pre-defined.
531 for macro in ['_GLIBCXX_ASSERTIONS', '_LIBCPP_HARDENING_MODE', '_LIBCPP_ENABLE_ASSERTIONS']:
532 if self.defines.get(macro) is not None:
533 return []
534
535 # For GCC, we can assume that the libstdc++ version is the same as
536 # the compiler itself. Anything else isn't supported.
537 if self.language_stdlib_provider == 'stdc++':
538 return ['-D_GLIBCXX_ASSERTIONS=1']
539 else:
540 # One can use -stdlib=libc++ with GCC, it just (as of 2025) requires
541 # an experimental configure arg to expose that. libc++ supports "multiple"
542 # versions of GCC (only ever one version of GCC per libc++ version), but
543 # that is "multiple" for our purposes as we can't assume a mapping.
544 if version_compare(self.version, '>=18'):
545 return ['-D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_FAST']
546
547 return []
548
549 def get_pch_use_args(self, pch_dir: str, header: str) -> T.List[str]:
550 return ['-fpch-preprocess', '-include', os.path.basename(header)]
551
552 def get_cpp_modules_args(self) -> T.List[str]:
553 return ['-fmodules', '-fmodules-ts']
554
555
556 class PGICPPCompiler(PGICompiler, CPPCompiler):
557 def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice,
558 env: Environment, linker: T.Optional['DynamicLinker'] = None,
559 full_version: T.Optional[str] = None):
560 CPPCompiler.__init__(self, ccache, exelist, version, for_machine,
561 env, linker=linker, full_version=full_version)
562 PGICompiler.__init__(self)
563
564
565 class NvidiaHPC_CPPCompiler(PGICompiler, CPPCompiler):
566
567 id = 'nvidia_hpc'
568
569 def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice,
570 env: Environment, linker: T.Optional['DynamicLinker'] = None,
571 full_version: T.Optional[str] = None):
572 CPPCompiler.__init__(self, ccache, exelist, version, for_machine,
573 env, linker=linker, full_version=full_version)
574 PGICompiler.__init__(self)
575
576 def get_options(self) -> 'MutableKeyedOptionDictType':
577 opts = super().get_options()
578 cppstd_choices = [
579 'c++98', 'c++03', 'c++11', 'c++14', 'c++17', 'c++20', 'c++23',
580 'gnu++98', 'gnu++03', 'gnu++11', 'gnu++14', 'gnu++17', 'gnu++20'
581 ]
582 std_opt = opts[self.form_compileropt_key('std')]
583 assert isinstance(std_opt, options.UserStdOption), 'for mypy'
584 std_opt.set_versions(cppstd_choices)
585 return opts
586
587 def get_option_std_args(self, target: BuildTarget, subproject: T.Optional[str] = None) -> T.List[str]:
588 args: T.List[str] = []
589 std = self.get_compileropt_value('std', target, subproject)
590 assert isinstance(std, str)
591 if std != 'none':
592 args.append(self._find_best_cpp_std(std))
593 return args
594
595
596 class ElbrusCPPCompiler(ElbrusCompiler, CPPCompiler):
597 def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice,
598 env: Environment, linker: T.Optional['DynamicLinker'] = None,
599 defines: T.Optional[T.Dict[str, str]] = None,
600 full_version: T.Optional[str] = None):
601 CPPCompiler.__init__(self, ccache, exelist, version, for_machine,
602 env, linker=linker, full_version=full_version)
603 ElbrusCompiler.__init__(self)
604
605 def get_options(self) -> 'MutableKeyedOptionDictType':
606 opts = super().get_options()
607
608 key = self.form_compileropt_key('eh')
609 opts[key] = options.UserComboOption(
610 self.make_option_name(key),
611 'C++ exception handling type.',
612 'default',
613 choices=['none', 'default', 'a', 's', 'sc'])
614
615 key = self.form_compileropt_key('debugstl')
616 opts[key] = options.UserBooleanOption(
617 self.make_option_name(key),
618 'STL debug mode',
619 False)
620
621 cpp_stds = ['c++98']
622 if version_compare(self.version, '>=1.20.00'):
623 cpp_stds += ['c++03', 'c++0x', 'c++11']
624 if version_compare(self.version, '>=1.21.00') and version_compare(self.version, '<1.22.00'):
625 cpp_stds += ['c++14', 'c++1y']
626 if version_compare(self.version, '>=1.22.00'):
627 cpp_stds += ['c++14']
628 if version_compare(self.version, '>=1.23.00'):
629 cpp_stds += ['c++1y']
630 if version_compare(self.version, '>=1.24.00'):
631 cpp_stds += ['c++1z', 'c++17']
632 if version_compare(self.version, '>=1.25.00'):
633 cpp_stds += ['c++2a']
634 if version_compare(self.version, '>=1.26.00'):
635 cpp_stds += ['c++20']
636 if version_compare(self.version, '>=1.28.00'):
637 cpp_stds += ['c++2b', 'c++23']
638
639 key = self.form_compileropt_key('std')
640 std_opt = opts[key]
641 assert isinstance(std_opt, options.UserStdOption), 'for mypy'
642 std_opt.set_versions(cpp_stds, gnu=True)
643 return opts
644
645 def has_function(self, funcname: str, prefix: str, *,
646 extra_args: T.Optional[T.List[str]] = None,
647 dependencies: T.Optional[T.List['Dependency']] = None) -> T.Tuple[bool, bool]:
648 return super().has_function(funcname, prefix, extra_args=extra_args, dependencies=dependencies)
649
650 # Elbrus C++ compiler does not support RTTI, so don't check for it.
651 def get_option_compile_args(self, target: 'BuildTarget', subproject: T.Optional[str] = None) -> T.List[str]:
652 args: T.List[str] = []
653 eh = self.get_compileropt_value('eh', target, subproject)
654 assert isinstance(eh, str)
655
656 non_msvc_eh_options(eh, args)
657
658 debugstl = self.get_compileropt_value('debugstl', target, subproject)
659 assert isinstance(debugstl, bool)
660 if debugstl:
661 args.append('-D_GLIBCXX_DEBUG=1')
662 return args
663
664 def get_option_std_args(self, target: BuildTarget, subproject: T.Optional[str] = None) -> T.List[str]:
665 args: T.List[str] = []
666 std = self.get_compileropt_value('std', target, subproject)
667 assert isinstance(std, str)
668 if std != 'none':
669 args.append(self._find_best_cpp_std(std))
670 return args
671
672
673 class IntelCPPCompiler(IntelGnuLikeCompiler, CPPCompiler):
674 def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice,
675 env: Environment, linker: T.Optional['DynamicLinker'] = None,
676 full_version: T.Optional[str] = None):
677 CPPCompiler.__init__(self, ccache, exelist, version, for_machine,
678 env, linker=linker, full_version=full_version)
679 IntelGnuLikeCompiler.__init__(self)
680 self.lang_header = 'c++-header'
681 default_warn_args = ['-Wall', '-w3', '-Wpch-messages']
682 self.warn_args = {'0': [],
683 '1': default_warn_args + ['-diag-disable:remark'],
684 '2': default_warn_args + ['-Wextra', '-diag-disable:remark'],
685 '3': default_warn_args + ['-Wextra', '-diag-disable:remark'],
686 'everything': default_warn_args + ['-Wextra']}
687
688 def get_options(self) -> 'MutableKeyedOptionDictType':
689 opts = super().get_options()
690
691 key = self.form_compileropt_key('eh')
692 opts[key] = options.UserComboOption(
693 self.make_option_name(key),
694 'C++ exception handling type.',
695 'default',
696 choices=['none', 'default', 'a', 's', 'sc'])
697
698 key = self.form_compileropt_key('rtti')
699 opts[key] = options.UserBooleanOption(
700 self.make_option_name(key),
701 'Enable RTTI',
702 True)
703
704 key = self.form_compileropt_key('debugstl')
705 opts[key] = options.UserBooleanOption(
706 self.make_option_name(key),
707 'STL debug mode',
708 False)
709
710 # Every Unix compiler under the sun seems to accept -std=c++03,
711 # with the exception of ICC. Instead of preventing the user from
712 # globally requesting C++03, we transparently remap it to C++98
713 c_stds = ['c++98', 'c++03']
714 g_stds = ['gnu++98', 'gnu++03']
715 if version_compare(self.version, '>=15.0.0'):
716 c_stds += ['c++11', 'c++14']
717 g_stds += ['gnu++11']
718 if version_compare(self.version, '>=16.0.0'):
719 c_stds += ['c++17']
720 if version_compare(self.version, '>=17.0.0'):
721 g_stds += ['gnu++14']
722 if version_compare(self.version, '>=19.1.0'):
723 c_stds += ['c++2a']
724 g_stds += ['gnu++2a']
725
726 self._update_language_stds(opts, c_stds + g_stds)
727 return opts
728
729 def get_option_compile_args(self, target: 'BuildTarget', subproject: T.Optional[str] = None) -> T.List[str]:
730 args: T.List[str] = []
731
732 rtti = self.get_compileropt_value('rtti', target, subproject)
733 debugstl = self.get_compileropt_value('debugstl', target, subproject)
734 eh = self.get_compileropt_value('eh', target, subproject)
735
736 assert isinstance(rtti, bool)
737 assert isinstance(eh, str)
738 assert isinstance(debugstl, bool)
739
740 if eh == 'none':
741 args.append('-fno-exceptions')
742 if not rtti:
743 args.append('-fno-rtti')
744 if debugstl:
745 args.append('-D_GLIBCXX_DEBUG=1')
746 return args
747
748 def get_option_std_args(self, target: BuildTarget, subproject: T.Optional[str] = None) -> T.List[str]:
749 args: T.List[str] = []
750 std = self.get_compileropt_value('std', target, subproject)
751 assert isinstance(std, str)
752 if std != 'none':
753 remap_cpp03 = {
754 'c++03': 'c++98',
755 'gnu++03': 'gnu++98'
756 }
757 args.append('-std=' + remap_cpp03.get(std, std))
758
759 return args
760
761 def get_option_link_args(self, target: 'BuildTarget', subproject: T.Optional[str] = None) -> T.List[str]:
762 return []
763
764
765 class IntelLLVMCPPCompiler(IntelLLVMLikeCompiler, ClangCPPCompiler):
766
767 id = 'intel-llvm'
768
769
770 class VisualStudioLikeCPPCompilerMixin(CompilerMixinBase):
771
772 """Mixin for C++ specific method overrides in MSVC-like compilers."""
773
774 VC_VERSION_MAP = {
775 'none': (True, None),
776 'vc++11': (True, 11),
777 'vc++14': (True, 14),
778 'vc++17': (True, 17),
779 'vc++20': (True, 20),
780 'vc++latest': (True, "latest"),
781 'c++11': (False, 11),
782 'c++14': (False, 14),
783 'c++17': (False, 17),
784 'c++20': (False, 20),
785 'c++latest': (False, "latest"),
786 }
787
788 def get_option_link_args(self, target: 'BuildTarget', subproject: T.Optional[str] = None) -> T.List[str]:
789 # need a typeddict for this
790 key = self.form_compileropt_key('winlibs').evolve(subproject=subproject)
791 if target:
792 value = self.environment.coredata.get_option_for_target(target, key)
793 else:
794 value = self.environment.coredata.optstore.get_value_for(key)
795 return T.cast('T.List[str]', value)[:]
796
797 def _get_options_impl(self, opts: 'MutableKeyedOptionDictType', cpp_stds: T.List[str]) -> 'MutableKeyedOptionDictType':
798 opts = super().get_options()
799
800 key = self.form_compileropt_key('eh')
801 opts[key] = options.UserComboOption(
802 self.make_option_name(key),
803 'C++ exception handling type.',
804 'default',
805 choices=['none', 'default', 'a', 's', 'sc'])
806
807 key = self.form_compileropt_key('rtti')
808 opts[key] = options.UserBooleanOption(
809 self.make_option_name(key),
810 'Enable RTTI',
811 True)
812
813 key = self.form_compileropt_key('winlibs')
814 opts[key] = options.UserStringArrayOption(
815 self.make_option_name(key),
816 'Standard Win libraries to link against',
817 msvc_winlibs)
818
819 std_opt = opts[self.form_compileropt_key('std')]
820 assert isinstance(std_opt, options.UserStdOption), 'for mypy'
821 std_opt.set_versions(cpp_stds)
822
823 if version_compare(self.version, '>=19.44.35219'):
824 key = self.form_compileropt_key('importstd')
825 opts[key] = options.UserComboOption(self.make_option_name(key),
826 'Use #import std.',
827 'false',
828 choices=['false', 'true'])
829 return opts
830
831 def get_option_compile_args(self, target: 'BuildTarget', subproject: T.Optional[str] = None) -> T.List[str]:
832 args: T.List[str] = []
833
834 eh = self.get_compileropt_value('eh', target, subproject)
835 rtti = self.get_compileropt_value('rtti', target, subproject)
836
837 assert isinstance(rtti, bool)
838 assert isinstance(eh, str)
839
840 if eh == 'default':
841 args.append('/EHsc')
842 elif eh == 'none':
843 args.append('/EHs-c-')
844 else:
845 args.append('/EH' + eh)
846
847 if not rtti:
848 args.append('/GR-')
849
850 return args
851
852 def get_option_std_args(self, target: BuildTarget, subproject: T.Optional[str] = None) -> T.List[str]:
853 args: T.List[str] = []
854 std = self.get_compileropt_value('std', target, subproject)
855 assert isinstance(std, str)
856
857 permissive, ver = self.VC_VERSION_MAP[std]
858 if ver is not None:
859 args.append(f'/std:c++{ver}')
860 if not permissive:
861 args.append('/permissive-')
862 return args
863
864 def get_cpp_permissive_args(self) -> T.List[str]:
865 return ['/permissive']
866
867 class CPP11AsCPP14Mixin(CompilerMixinBase):
868
869 """Mixin class for VisualStudio and ClangCl to replace C++11 std with C++14.
870
871 This is a limitation of Clang and MSVC that ICL doesn't share.
872 """
873
874 def get_option_std_args(self, target: BuildTarget, subproject: T.Optional[str] = None) -> T.List[str]:
875 # Note: there is no explicit flag for supporting C++11; we attempt to do the best we can
876 # which means setting the C++ standard version to C++14, in compilers that support it
877 # (i.e., after VS2015U3)
878 # if one is using anything before that point, one cannot set the standard.
879 stdkey = self.form_compileropt_key('std').evolve(subproject=subproject)
880 if target is not None:
881 std = self.environment.coredata.get_option_for_target(target, stdkey)
882 else:
883 std = self.environment.coredata.optstore.get_value_for(stdkey)
884 if std in {'vc++11', 'c++11'}:
885 mlog.warning(self.id, 'does not support C++11;',
886 'attempting best effort; setting the standard to C++14',
887 once=True, fatal=False)
888 original_args = super().get_option_std_args(target, subproject)
889 std_mapping = {'/std:c++11': '/std:c++14'}
890 processed_args = [std_mapping.get(x, x) for x in original_args]
891 return processed_args
892
893
894 class VisualStudioCPPCompiler(CPP11AsCPP14Mixin, VisualStudioLikeCPPCompilerMixin, MSVCCompiler, CPPCompiler):
895
896 id = 'msvc'
897
898 def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice,
899 env: Environment, target: str,
900 linker: T.Optional['DynamicLinker'] = None,
901 full_version: T.Optional[str] = None):
902 CPPCompiler.__init__(self, ccache, exelist, version, for_machine,
903 env, linker=linker, full_version=full_version)
904 MSVCCompiler.__init__(self, target)
905
906 # By default, MSVC has a broken __cplusplus define that pretends to be c++98:
907 # https://docs.microsoft.com/en-us/cpp/build/reference/zc-cplusplus?view=msvc-160
908 # Pass the flag to enable a truthful define, if possible.
909 if version_compare(self.version, '>= 19.14.26428'):
910 self.always_args = self.always_args + ['/Zc:__cplusplus']
911
912 def get_options(self) -> 'MutableKeyedOptionDictType':
913 cpp_stds = ['none', 'c++11', 'vc++11']
914 # Visual Studio 2015 and later
915 if version_compare(self.version, '>=19'):
916 cpp_stds.extend(['c++14', 'c++latest', 'vc++latest'])
917 # Visual Studio 2017 and later
918 if version_compare(self.version, '>=19.11'):
919 cpp_stds.extend(['vc++14', 'c++17', 'vc++17'])
920 if version_compare(self.version, '>=19.29'):
921 cpp_stds.extend(['c++20', 'vc++20'])
922 return self._get_options_impl(super().get_options(), cpp_stds)
923
924 def get_option_std_args(self, target: BuildTarget, subproject: T.Optional[str] = None) -> T.List[str]:
925 std = self.get_compileropt_value('std', target, subproject)
926 if std != 'none' and version_compare(self.version, '<19.00.24210'):
927 mlog.warning('This version of MSVC does not support cpp_std arguments', fatal=False)
928
929 args = super().get_option_std_args(target, subproject)
930
931 if version_compare(self.version, '<19.11'):
932 try:
933 i = args.index('/permissive-')
934 except ValueError:
935 return args
936 del args[i]
937 return args
938
939 def get_cpp_modules_args(self) -> T.List[str]:
940 return ['/interface']
941
942 class ClangClCPPCompiler(VisualStudioLikeCPPCompilerMixin, ClangClCompiler, CPPCompiler):
943
944 id = 'clang-cl'
945
946 def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice,
947 env: Environment, target: str,
948 linker: T.Optional['DynamicLinker'] = None,
949 full_version: T.Optional[str] = None):
950 CPPCompiler.__init__(self, [], exelist, version, for_machine,
951 env, linker=linker, full_version=full_version)
952 ClangClCompiler.__init__(self, target)
953
954 def get_options(self) -> 'MutableKeyedOptionDictType':
955 cpp_stds = list(self.VC_VERSION_MAP) + ['c++23', 'vc++23']
956 return self._get_options_impl(super().get_options(), cpp_stds)
957
958 def get_option_std_args(self, target: BuildTarget, subproject: T.Optional[str] = None) -> T.List[str]:
959 std = self.get_compileropt_value('std', target, subproject)
960 assert isinstance(std, str)
961 if std == 'none':
962 return []
963 # c++latest and vc++latest have no /clang:-std= equivalent
964 if std in {'c++latest', 'vc++latest'}:
965 args = ['/std:c++latest']
966 if std == 'c++latest':
967 args.append('/permissive-')
968 return args
969 # vc++ variants: permissive mode, strip 'vc++' prefix to get clang std name
970 if std.startswith('vc++'):
971 return [f'/clang:-std=c++{std[4:]}']
972 # c++ variants: strict conformance mode
973 return [f'/clang:-std={std}', '/permissive-']
974
975 def get_cpp_modules_args(self) -> T.List[str]:
976 # clang-cl does not support /interface.
977 return ['-fmodules', '-fmodules-ts']
978
979
980 class IntelClCPPCompiler(VisualStudioLikeCPPCompilerMixin, IntelVisualStudioLikeCompiler, CPPCompiler):
981
982 def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice,
983 env: Environment, target: str,
984 linker: T.Optional['DynamicLinker'] = None,
985 full_version: T.Optional[str] = None):
986 CPPCompiler.__init__(self, [], exelist, version, for_machine,
987 env, linker=linker, full_version=full_version)
988 IntelVisualStudioLikeCompiler.__init__(self, target)
989
990 def get_options(self) -> 'MutableKeyedOptionDictType':
991 # This has only been tested with version 19.0, 2021.2.1, 2024.4.2 and 2025.0.1
992 if version_compare(self.version, '<2021.1.0'):
993 cpp_stds = ['none', 'c++11', 'vc++11', 'c++14', 'vc++14', 'c++17', 'vc++17', 'c++latest']
994 else:
995 cpp_stds = ['none', 'c++14', 'c++17', 'c++latest']
996 if version_compare(self.version, '>=2024.1.0'):
997 cpp_stds += ['c++20']
998 return self._get_options_impl(super().get_options(), cpp_stds)
999
1000
1001 class IntelLLVMClCPPCompiler(IntelClCPPCompiler):
1002
1003 id = 'intel-llvm-cl'
1004
1005
1006 class ArmCPPCompiler(ArmCompiler, CPPCompiler):
1007 def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice,
1008 env: Environment, linker: T.Optional['DynamicLinker'] = None,
1009 full_version: T.Optional[str] = None):
1010 CPPCompiler.__init__(self, ccache, exelist, version, for_machine,
1011 env, linker=linker, full_version=full_version)
1012 ArmCompiler.__init__(self)
1013
1014 def get_options(self) -> 'MutableKeyedOptionDictType':
1015 opts = super().get_options()
1016 std_opt = self.form_compileropt_key('std')
1017 assert isinstance(std_opt, options.UserStdOption), 'for mypy'
1018 std_opt.set_versions(['c++03', 'c++11'])
1019 return opts
1020
1021 def get_option_std_args(self, target: BuildTarget, subproject: T.Optional[str] = None) -> T.List[str]:
1022 args: T.List[str] = []
1023 std = self.get_compileropt_value('std', target, subproject)
1024 assert isinstance(std, str)
1025 if std == 'c++11':
1026 args.append('--cpp11')
1027 elif std == 'c++03':
1028 args.append('--cpp')
1029 return args
1030
1031 def get_option_link_args(self, target: 'BuildTarget', subproject: T.Optional[str] = None) -> T.List[str]:
1032 return []
1033
1034 def get_compiler_check_args(self, mode: CompileCheckMode) -> T.List[str]:
1035 return []
1036
1037
1038 class CcrxCPPCompiler(CcrxCompiler, CPPCompiler):
1039 def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice,
1040 env: Environment, linker: T.Optional['DynamicLinker'] = None,
1041 full_version: T.Optional[str] = None):
1042 CPPCompiler.__init__(self, ccache, exelist, version, for_machine,
1043 env, linker=linker, full_version=full_version)
1044 CcrxCompiler.__init__(self)
1045
1046 # Override CCompiler.get_always_args
1047 def get_always_args(self) -> T.List[str]:
1048 return ['-nologo', '-lang=cpp']
1049
1050 def get_compile_only_args(self) -> T.List[str]:
1051 return []
1052
1053 def get_output_args(self, outputname: str) -> T.List[str]:
1054 return [f'-output=obj={outputname}']
1055
1056 def get_option_link_args(self, target: 'BuildTarget', subproject: T.Optional[str] = None) -> T.List[str]:
1057 return []
1058
1059 def get_compiler_check_args(self, mode: CompileCheckMode) -> T.List[str]:
1060 return []
1061
1062 class TICPPCompiler(TICompiler, CPPCompiler):
1063 def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice,
1064 env: Environment, linker: T.Optional['DynamicLinker'] = None,
1065 full_version: T.Optional[str] = None):
1066 CPPCompiler.__init__(self, ccache, exelist, version, for_machine,
1067 env, linker=linker, full_version=full_version)
1068 TICompiler.__init__(self)
1069
1070 def get_options(self) -> 'MutableKeyedOptionDictType':
1071 opts = super().get_options()
1072 key = self.form_compileropt_key('std')
1073 std_opt = opts[key]
1074 assert isinstance(std_opt, options.UserStdOption), 'for mypy'
1075 std_opt.set_versions(['c++03'])
1076 return opts
1077
1078 def get_option_std_args(self, target: BuildTarget, subproject: T.Optional[str] = None) -> T.List[str]:
1079 args: T.List[str] = []
1080 std = self.get_compileropt_value('std', target, subproject)
1081 assert isinstance(std, str)
1082 if std != 'none':
1083 args.append('--' + std)
1084 return args
1085
1086 def get_always_args(self) -> T.List[str]:
1087 return []
1088
1089 def get_cpp_permissive_args(self) -> T.List[str]:
1090 return ['-fpermissive']
1091
1092 def get_option_link_args(self, target: 'BuildTarget', subproject: T.Optional[str] = None) -> T.List[str]:
1093 return []
1094
1095 class C2000CPPCompiler(TICPPCompiler):
1096 # Required for backwards compat with projects created before ti-cgt support existed
1097 id = 'c2000'
1098
1099 class C6000CPPCompiler(TICPPCompiler):
1100 id = 'c6000'
1101
1102 class MetrowerksCPPCompilerARM(MetrowerksCompiler, CPPCompiler):
1103 id = 'mwccarm'
1104
1105 def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice,
1106 env: Environment, linker: T.Optional['DynamicLinker'] = None,
1107 full_version: T.Optional[str] = None):
1108 CPPCompiler.__init__(self, ccache, exelist, version, for_machine,
1109 env, linker=linker, full_version=full_version)
1110 MetrowerksCompiler.__init__(self)
1111
1112 def get_instruction_set_args(self, instruction_set: str) -> T.Optional[T.List[str]]:
1113 return mwccarm_instruction_set_args.get(instruction_set, None)
1114
1115 def get_options(self) -> 'MutableKeyedOptionDictType':
1116 opts = super().get_options()
1117 self._update_language_stds(opts, [])
1118 return opts
1119
1120 def get_option_std_args(self, target: BuildTarget, subproject: T.Optional[str] = None) -> T.List[str]:
1121 args: T.List[str] = []
1122 std = self.get_compileropt_value('std', target, subproject)
1123 assert isinstance(std, str)
1124 if std != 'none':
1125 args.append('-lang')
1126 args.append(std)
1127 return args
1128
1129 class MetrowerksCPPCompilerEmbeddedPowerPC(MetrowerksCompiler, CPPCompiler):
1130 id = 'mwcceppc'
1131
1132 def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice,
1133 env: Environment, linker: T.Optional['DynamicLinker'] = None,
1134 full_version: T.Optional[str] = None):
1135 CPPCompiler.__init__(self, ccache, exelist, version, for_machine,
1136 env, linker=linker, full_version=full_version)
1137 MetrowerksCompiler.__init__(self)
1138
1139 def get_instruction_set_args(self, instruction_set: str) -> T.Optional[T.List[str]]:
1140 return mwcceppc_instruction_set_args.get(instruction_set, None)
1141
1142 def get_options(self) -> 'MutableKeyedOptionDictType':
1143 opts = super().get_options()
1144 self._update_language_stds(opts, [])
1145 return opts
1146
1147 def get_option_std_args(self, target: BuildTarget, subproject: T.Optional[str] = None) -> T.List[str]:
1148 args: T.List[str] = []
1149 std = self.get_compileropt_value('std', target, subproject)
1150 assert isinstance(std, str)
1151 if std != 'none':
1152 args.append('-lang ' + std)
1153 return args
1154
1155
1156 class Xc32CPPCompiler(Xc32CPPStds, Xc32Compiler, GnuCPPCompiler):
1157
1158 """Microchip XC32 C++ compiler."""
1159
1160 def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice,
1161 env: Environment, linker: T.Optional[DynamicLinker] = None,
1162 defines: T.Optional[T.Dict[str, str]] = None,
1163 full_version: T.Optional[str] = None):
1164 GnuCPPCompiler.__init__(self, ccache, exelist, version, for_machine, env,
1165 linker=linker, full_version=full_version, defines=defines)
1166 Xc32Compiler.__init__(self)