| 1 |
# SPDX-License-Identifier: Apache-2.0 |
| 2 |
# Copyright 2012-2020 The Meson development team |
| 3 |
# Copyright © 2024-2025 Intel Corporation |
| 4 |
|
| 5 |
from __future__ import annotations |
| 6 |
|
| 7 |
import os.path |
| 8 |
import typing as T |
| 9 |
|
| 10 |
from .. import options |
| 11 |
from ..options import OptionKey |
| 12 |
from .. import mlog |
| 13 |
from ..mesonlib import MesonException, version_compare |
| 14 |
from .c_function_attributes import C_FUNC_ATTRIBUTES |
| 15 |
from .mixins.apple import AppleCompilerMixin, AppleCStdsMixin |
| 16 |
from .mixins.clike import CLikeCompiler |
| 17 |
from .mixins.ccrx import CcrxCompiler |
| 18 |
from .mixins.microchip import Xc16Compiler, Xc32Compiler, Xc32CStds |
| 19 |
from .mixins.compcert import CompCertCompiler |
| 20 |
from .mixins.ti import TICompiler |
| 21 |
from .mixins.arm import ArmCompiler, ArmclangCompiler |
| 22 |
from .mixins.visualstudio import MSVCCompiler, ClangClCompiler |
| 23 |
from .mixins.gnu import GnuCompiler, GnuCStds |
| 24 |
from .mixins.gnu import gnu_common_warning_args, gnu_c_warning_args |
| 25 |
from .mixins.intel import IntelGnuLikeCompiler, IntelLLVMLikeCompiler, IntelVisualStudioLikeCompiler |
| 26 |
from .mixins.clang import ClangCompiler, ClangCStds |
| 27 |
from .mixins.elbrus import ElbrusCompiler |
| 28 |
from .mixins.pgi import PGICompiler |
| 29 |
from .mixins.emscripten import EmscriptenMixin |
| 30 |
from .mixins.metrowerks import MetrowerksCompiler |
| 31 |
from .mixins.metrowerks import mwccarm_instruction_set_args, mwcceppc_instruction_set_args |
| 32 |
from .mixins.tasking import TaskingCompiler |
| 33 |
from .compilers import ( |
| 34 |
gnu_winlibs, |
| 35 |
msvc_winlibs, |
| 36 |
Compiler, |
| 37 |
) |
| 38 |
|
| 39 |
if T.TYPE_CHECKING: |
| 40 |
from ..options import MutableKeyedOptionDictType |
| 41 |
from ..dependencies import Dependency |
| 42 |
from ..environment import Environment |
| 43 |
from ..linkers.linkers import DynamicLinker |
| 44 |
from ..mesonlib import MachineChoice |
| 45 |
from .compilers import CompileCheckMode |
| 46 |
from ..build import BuildTarget |
| 47 |
|
| 48 |
CompilerMixinBase = Compiler |
| 49 |
else: |
| 50 |
CompilerMixinBase = object |
| 51 |
|
| 52 |
ALL_STDS = ['c89', 'c9x', 'c90', 'c99', 'c1x', 'c11', 'c17', 'c18', 'c2x', 'c23', 'c2y'] |
| 53 |
ALL_STDS += [f'gnu{std[1:]}' for std in ALL_STDS] |
| 54 |
ALL_STDS += ['iso9899:1990', 'iso9899:199409', 'iso9899:1999', 'iso9899:2011', 'iso9899:2017', 'iso9899:2018', 'iso9899:2024'] |
| 55 |
|
| 56 |
|
| 57 |
class CCompiler(CLikeCompiler, Compiler): |
| 58 |
def attribute_check_func(self, name: str) -> str: |
| 59 |
try: |
| 60 |
return C_FUNC_ATTRIBUTES[name] |
| 61 |
except KeyError: |
| 62 |
raise MesonException(f'Unknown function attribute "{name}"') |
| 63 |
|
| 64 |
language = 'c' |
| 65 |
|
| 66 |
def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, |
| 67 |
env: Environment, linker: T.Optional['DynamicLinker'] = None, |
| 68 |
full_version: T.Optional[str] = None): |
| 69 |
# If a child ObjC or CPP class has already set it, don't set it ourselves |
| 70 |
Compiler.__init__(self, ccache, exelist, version, for_machine, env, |
| 71 |
full_version=full_version, linker=linker) |
| 72 |
CLikeCompiler.__init__(self) |
| 73 |
|
| 74 |
def get_no_stdinc_args(self) -> T.List[str]: |
| 75 |
return ['-nostdinc'] |
| 76 |
|
| 77 |
def _sanity_check_source_code(self) -> str: |
| 78 |
return '#include <stddef.h>\nint main(void) { int class=0; return class; }\n' |
| 79 |
|
| 80 |
def has_header_symbol(self, hname: str, symbol: str, prefix: str, *, |
| 81 |
extra_args: T.Union[None, T.List[str], T.Callable[['CompileCheckMode'], T.List[str]]] = None, |
| 82 |
dependencies: T.Optional[T.List['Dependency']] = None) -> T.Tuple[bool, bool]: |
| 83 |
fargs = {'prefix': prefix, 'header': hname, 'symbol': symbol} |
| 84 |
t = '''{prefix} |
| 85 |
#include <{header}> |
| 86 |
int main(void) {{ |
| 87 |
/* If it's not defined as a macro, try to use as a symbol */ |
| 88 |
#ifndef {symbol} |
| 89 |
{symbol}; |
| 90 |
#endif |
| 91 |
return 0; |
| 92 |
}}''' |
| 93 |
return self.compiles(t.format(**fargs), extra_args=extra_args, |
| 94 |
dependencies=dependencies) |
| 95 |
|
| 96 |
def get_options(self) -> 'MutableKeyedOptionDictType': |
| 97 |
opts = super().get_options() |
| 98 |
key = self.form_compileropt_key('std') |
| 99 |
opts.update({ |
| 100 |
key: options.UserStdOption('c', ALL_STDS), |
| 101 |
}) |
| 102 |
return opts |
| 103 |
|
| 104 |
|
| 105 |
class ClangCCompiler(ClangCStds, ClangCompiler, CCompiler): |
| 106 |
|
| 107 |
def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, |
| 108 |
env: Environment, linker: T.Optional['DynamicLinker'] = None, |
| 109 |
defines: T.Optional[T.Dict[str, str]] = None, |
| 110 |
full_version: T.Optional[str] = None): |
| 111 |
CCompiler.__init__(self, ccache, exelist, version, for_machine, env, linker=linker, full_version=full_version) |
| 112 |
ClangCompiler.__init__(self, defines) |
| 113 |
default_warn_args = ['-Wall', '-Winvalid-pch'] |
| 114 |
self.warn_args = {'0': [], |
| 115 |
'1': default_warn_args, |
| 116 |
'2': default_warn_args + ['-Wextra'], |
| 117 |
'3': default_warn_args + ['-Wextra', '-Wpedantic'], |
| 118 |
'everything': ['-Weverything']} |
| 119 |
|
| 120 |
def get_options(self) -> 'MutableKeyedOptionDictType': |
| 121 |
opts = super().get_options() |
| 122 |
if self.info.is_windows() or self.info.is_cygwin(): |
| 123 |
key = self.form_compileropt_key('winlibs') |
| 124 |
opts[key] = options.UserStringArrayOption( |
| 125 |
self.make_option_name(key), |
| 126 |
'Standard Windows libraries to link against', |
| 127 |
gnu_winlibs) |
| 128 |
return opts |
| 129 |
|
| 130 |
def get_option_std_args(self, target: BuildTarget, subproject: T.Optional[str] = None) -> T.List[str]: |
| 131 |
args = [] |
| 132 |
std = self.get_compileropt_value('std', target, subproject) |
| 133 |
assert isinstance(std, str) |
| 134 |
if std != 'none': |
| 135 |
args.append('-std=' + std) |
| 136 |
return args |
| 137 |
|
| 138 |
def get_option_link_args(self, target: 'BuildTarget', subproject: T.Optional[str] = None) -> T.List[str]: |
| 139 |
if self.info.is_windows() or self.info.is_cygwin(): |
| 140 |
retval = self.get_compileropt_value('winlibs', target, subproject) |
| 141 |
assert isinstance(retval, list) |
| 142 |
libs: T.List[str] = retval.copy() |
| 143 |
for l in libs: |
| 144 |
assert isinstance(l, str) |
| 145 |
return libs |
| 146 |
return [] |
| 147 |
|
| 148 |
|
| 149 |
class ArmLtdClangCCompiler(ClangCCompiler): |
| 150 |
|
| 151 |
id = 'armltdclang' |
| 152 |
|
| 153 |
|
| 154 |
class AppleClangCCompiler(AppleCompilerMixin, AppleCStdsMixin, ClangCCompiler): |
| 155 |
|
| 156 |
"""Handle the differences between Apple Clang and Vanilla Clang. |
| 157 |
|
| 158 |
Right now this just handles the differences between the versions that new |
| 159 |
C standards were added. |
| 160 |
""" |
| 161 |
|
| 162 |
|
| 163 |
class EmscriptenCCompiler(EmscriptenMixin, ClangCCompiler): |
| 164 |
|
| 165 |
id = 'emscripten' |
| 166 |
|
| 167 |
# Emscripten uses different version numbers than Clang; `emcc -v` will show |
| 168 |
# the Clang version number used as well (but `emcc --version` does not). |
| 169 |
# See https://github.com/pyodide/pyodide/discussions/4762 for more on |
| 170 |
# emcc <--> clang versions. Note that c17/c18/c2x are always available, since |
| 171 |
# the lowest supported Emscripten version used a new-enough Clang version. |
| 172 |
_C17_VERSION = '>=1.38.35' |
| 173 |
_C18_VERSION = '>=1.38.35' |
| 174 |
_C2X_VERSION = '>=1.38.35' # 1.38.35 used Clang 9.0.0 |
| 175 |
_C23_VERSION = '>=3.1.45' # 3.1.45 used Clang 18.0.0 |
| 176 |
|
| 177 |
def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, |
| 178 |
env: Environment, linker: T.Optional['DynamicLinker'] = None, |
| 179 |
defines: T.Optional[T.Dict[str, str]] = None, |
| 180 |
full_version: T.Optional[str] = None): |
| 181 |
if not env.is_cross_build(for_machine): |
| 182 |
raise MesonException('Emscripten compiler can only be used for cross compilation.') |
| 183 |
if not version_compare(version, '>=1.39.19'): |
| 184 |
raise MesonException('Meson requires Emscripten >= 1.39.19') |
| 185 |
ClangCCompiler.__init__(self, ccache, exelist, version, for_machine, env, |
| 186 |
linker=linker, defines=defines, full_version=full_version) |
| 187 |
|
| 188 |
|
| 189 |
class ArmclangCCompiler(ArmclangCompiler, CCompiler): |
| 190 |
''' |
| 191 |
Keil armclang |
| 192 |
''' |
| 193 |
|
| 194 |
def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, |
| 195 |
env: Environment, linker: T.Optional['DynamicLinker'] = None, |
| 196 |
full_version: T.Optional[str] = None): |
| 197 |
CCompiler.__init__(self, ccache, exelist, version, for_machine, |
| 198 |
env, linker=linker, full_version=full_version) |
| 199 |
ArmclangCompiler.__init__(self) |
| 200 |
default_warn_args = ['-Wall', '-Winvalid-pch'] |
| 201 |
self.warn_args = {'0': [], |
| 202 |
'1': default_warn_args, |
| 203 |
'2': default_warn_args + ['-Wextra'], |
| 204 |
'3': default_warn_args + ['-Wextra', '-Wpedantic'], |
| 205 |
'everything': ['-Weverything']} |
| 206 |
|
| 207 |
def get_options(self) -> 'MutableKeyedOptionDictType': |
| 208 |
opts = super().get_options() |
| 209 |
key = self.form_compileropt_key('std') |
| 210 |
std_opt = opts[key] |
| 211 |
assert isinstance(std_opt, options.UserStdOption), 'for mypy' |
| 212 |
std_opt.set_versions(['c90', 'c99', 'c11'], gnu=True) |
| 213 |
return opts |
| 214 |
|
| 215 |
def get_option_std_args(self, target: BuildTarget, subproject: T.Optional[str] = None) -> T.List[str]: |
| 216 |
args = [] |
| 217 |
std = self.get_compileropt_value('std', target, subproject) |
| 218 |
assert isinstance(std, str) |
| 219 |
if std != 'none': |
| 220 |
args.append('-std=' + std) |
| 221 |
return args |
| 222 |
|
| 223 |
def get_option_link_args(self, target: 'BuildTarget', subproject: T.Optional[str] = None) -> T.List[str]: |
| 224 |
return [] |
| 225 |
|
| 226 |
|
| 227 |
class GnuCCompiler(GnuCStds, GnuCompiler, CCompiler): |
| 228 |
|
| 229 |
_INVALID_PCH_VERSION = ">=3.4.0" |
| 230 |
|
| 231 |
def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, |
| 232 |
env: Environment, linker: T.Optional['DynamicLinker'] = None, |
| 233 |
defines: T.Optional[T.Dict[str, str]] = None, |
| 234 |
full_version: T.Optional[str] = None): |
| 235 |
CCompiler.__init__(self, ccache, exelist, version, for_machine, env, linker=linker, full_version=full_version) |
| 236 |
GnuCompiler.__init__(self, defines) |
| 237 |
default_warn_args = ['-Wall'] |
| 238 |
if version_compare(self.version, self._INVALID_PCH_VERSION): |
| 239 |
default_warn_args += ['-Winvalid-pch'] |
| 240 |
self.warn_args = {'0': [], |
| 241 |
'1': default_warn_args, |
| 242 |
'2': default_warn_args + ['-Wextra'], |
| 243 |
'3': default_warn_args + ['-Wextra', '-Wpedantic'], |
| 244 |
'everything': (default_warn_args + ['-Wextra', '-Wpedantic'] + |
| 245 |
self.supported_warn_args(gnu_common_warning_args) + |
| 246 |
self.supported_warn_args(gnu_c_warning_args))} |
| 247 |
|
| 248 |
def get_options(self) -> 'MutableKeyedOptionDictType': |
| 249 |
opts = super().get_options() |
| 250 |
if self.info.is_windows() or self.info.is_cygwin(): |
| 251 |
key = self.form_compileropt_key('winlibs') |
| 252 |
opts[key] = options.UserStringArrayOption( |
| 253 |
self.make_option_name(key), |
| 254 |
'Standard Windows libraries to link against', |
| 255 |
gnu_winlibs) |
| 256 |
return opts |
| 257 |
|
| 258 |
def get_option_std_args(self, target: BuildTarget, subproject: T.Optional[str] = None) -> T.List[str]: |
| 259 |
args = [] |
| 260 |
key = OptionKey('c_std', machine=self.for_machine) |
| 261 |
std = self.get_compileropt_value(key, target, subproject) |
| 262 |
assert isinstance(std, str) |
| 263 |
if std != 'none': |
| 264 |
args.append('-std=' + std) |
| 265 |
return args |
| 266 |
|
| 267 |
def get_option_link_args(self, target: 'BuildTarget', subproject: T.Optional[str] = None) -> T.List[str]: |
| 268 |
if self.info.is_windows() or self.info.is_cygwin(): |
| 269 |
# without a typeddict mypy can't figure this out |
| 270 |
retval = self.get_compileropt_value('winlibs', target, subproject) |
| 271 |
|
| 272 |
assert isinstance(retval, list) |
| 273 |
libs: T.List[str] = retval.copy() |
| 274 |
for l in libs: |
| 275 |
assert isinstance(l, str) |
| 276 |
return libs |
| 277 |
return [] |
| 278 |
|
| 279 |
def get_pch_use_args(self, pch_dir: str, header: str) -> T.List[str]: |
| 280 |
return ['-fpch-preprocess', '-include', os.path.basename(header)] |
| 281 |
|
| 282 |
|
| 283 |
class PGICCompiler(PGICompiler, CCompiler): |
| 284 |
def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, |
| 285 |
env: Environment, linker: T.Optional['DynamicLinker'] = None, |
| 286 |
full_version: T.Optional[str] = None): |
| 287 |
CCompiler.__init__(self, ccache, exelist, version, for_machine, |
| 288 |
env, linker=linker, full_version=full_version) |
| 289 |
PGICompiler.__init__(self) |
| 290 |
|
| 291 |
|
| 292 |
class NvidiaHPC_CCompiler(PGICompiler, CCompiler): |
| 293 |
|
| 294 |
id = 'nvidia_hpc' |
| 295 |
|
| 296 |
def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, |
| 297 |
env: Environment, linker: T.Optional['DynamicLinker'] = None, |
| 298 |
full_version: T.Optional[str] = None): |
| 299 |
CCompiler.__init__(self, ccache, exelist, version, for_machine, |
| 300 |
env, linker=linker, full_version=full_version) |
| 301 |
PGICompiler.__init__(self) |
| 302 |
|
| 303 |
def get_options(self) -> 'MutableKeyedOptionDictType': |
| 304 |
opts = super().get_options() |
| 305 |
cppstd_choices = ['c89', 'c90', 'c99', 'c11', 'c17', 'c18'] |
| 306 |
std_opt = opts[self.form_compileropt_key('std')] |
| 307 |
assert isinstance(std_opt, options.UserStdOption), 'for mypy' |
| 308 |
std_opt.set_versions(cppstd_choices, gnu=True) |
| 309 |
return opts |
| 310 |
|
| 311 |
def get_option_std_args(self, target: BuildTarget, subproject: T.Optional[str] = None) -> T.List[str]: |
| 312 |
args: T.List[str] = [] |
| 313 |
std = self.get_compileropt_value('std', target, subproject) |
| 314 |
assert isinstance(std, str) |
| 315 |
if std != 'none': |
| 316 |
args.append('-std=' + std) |
| 317 |
return args |
| 318 |
|
| 319 |
|
| 320 |
class ElbrusCCompiler(ElbrusCompiler, CCompiler): |
| 321 |
def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, |
| 322 |
env: Environment, linker: T.Optional['DynamicLinker'] = None, |
| 323 |
defines: T.Optional[T.Dict[str, str]] = None, |
| 324 |
full_version: T.Optional[str] = None): |
| 325 |
CCompiler.__init__(self, ccache, exelist, version, for_machine, |
| 326 |
env, linker=linker, full_version=full_version) |
| 327 |
ElbrusCompiler.__init__(self) |
| 328 |
|
| 329 |
def get_options(self) -> 'MutableKeyedOptionDictType': |
| 330 |
opts = super().get_options() |
| 331 |
stds = ['c89', 'c9x', 'c99', 'gnu89', 'gnu9x', 'gnu99'] |
| 332 |
stds += ['iso9899:1990', 'iso9899:199409', 'iso9899:1999'] |
| 333 |
if version_compare(self.version, '>=1.20.00'): |
| 334 |
stds += ['c11', 'gnu11'] |
| 335 |
if version_compare(self.version, '>=1.21.00') and version_compare(self.version, '<1.22.00'): |
| 336 |
stds += ['c90', 'c1x', 'gnu90', 'gnu1x', 'iso9899:2011'] |
| 337 |
if version_compare(self.version, '>=1.23.00'): |
| 338 |
stds += ['c90', 'c1x', 'gnu90', 'gnu1x', 'iso9899:2011'] |
| 339 |
if version_compare(self.version, '>=1.26.00'): |
| 340 |
stds += ['c17', 'c18', 'iso9899:2017', 'iso9899:2018', 'gnu17', 'gnu18'] |
| 341 |
if version_compare(self.version, '>=1.28.00'): |
| 342 |
stds += ['c2x', 'gnu2x', 'c23', 'iso9899:2024', 'gnu23'] |
| 343 |
key = self.form_compileropt_key('std') |
| 344 |
std_opt = opts[key] |
| 345 |
assert isinstance(std_opt, options.UserStdOption), 'for mypy' |
| 346 |
std_opt.set_versions(stds) |
| 347 |
return opts |
| 348 |
|
| 349 |
def has_function(self, funcname: str, prefix: str, *, |
| 350 |
extra_args: T.Optional[T.List[str]] = None, |
| 351 |
dependencies: T.Optional[T.List['Dependency']] = None) -> T.Tuple[bool, bool]: |
| 352 |
return super().has_function(funcname, prefix, extra_args=extra_args, dependencies=dependencies) |
| 353 |
|
| 354 |
|
| 355 |
class IntelCCompiler(IntelGnuLikeCompiler, CCompiler): |
| 356 |
def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, |
| 357 |
env: Environment, linker: T.Optional['DynamicLinker'] = None, |
| 358 |
full_version: T.Optional[str] = None): |
| 359 |
CCompiler.__init__(self, ccache, exelist, version, for_machine, |
| 360 |
env, linker=linker, full_version=full_version) |
| 361 |
IntelGnuLikeCompiler.__init__(self) |
| 362 |
self.lang_header = 'c-header' |
| 363 |
default_warn_args = ['-Wall', '-w3'] |
| 364 |
self.warn_args = {'0': [], |
| 365 |
'1': default_warn_args + ['-diag-disable:remark'], |
| 366 |
'2': default_warn_args + ['-Wextra', '-diag-disable:remark'], |
| 367 |
'3': default_warn_args + ['-Wextra', '-diag-disable:remark'], |
| 368 |
'everything': default_warn_args + ['-Wextra']} |
| 369 |
|
| 370 |
def get_options(self) -> 'MutableKeyedOptionDictType': |
| 371 |
opts = super().get_options() |
| 372 |
stds = ['c89', 'c99'] |
| 373 |
if version_compare(self.version, '>=16.0.0'): |
| 374 |
stds += ['c11'] |
| 375 |
key = self.form_compileropt_key('std') |
| 376 |
std_opt = opts[key] |
| 377 |
assert isinstance(std_opt, options.UserStdOption), 'for mypy' |
| 378 |
std_opt.set_versions(stds, gnu=True) |
| 379 |
return opts |
| 380 |
|
| 381 |
def get_option_std_args(self, target: BuildTarget, subproject: T.Optional[str] = None) -> T.List[str]: |
| 382 |
args: T.List[str] = [] |
| 383 |
std = self.get_compileropt_value('std', target, subproject) |
| 384 |
assert isinstance(std, str) |
| 385 |
if std != 'none': |
| 386 |
args.append('-std=' + std) |
| 387 |
return args |
| 388 |
|
| 389 |
|
| 390 |
class IntelLLVMCCompiler(IntelLLVMLikeCompiler, ClangCCompiler): |
| 391 |
|
| 392 |
id = 'intel-llvm' |
| 393 |
|
| 394 |
|
| 395 |
class VisualStudioLikeCCompilerMixin(CompilerMixinBase): |
| 396 |
|
| 397 |
"""Shared methods that apply to MSVC-like C compilers.""" |
| 398 |
|
| 399 |
def get_options(self) -> MutableKeyedOptionDictType: |
| 400 |
opts = super().get_options() |
| 401 |
key = self.form_compileropt_key('winlibs') |
| 402 |
opts[key] = options.UserStringArrayOption( |
| 403 |
self.make_option_name(key), |
| 404 |
'Standard Windows libraries to link against', |
| 405 |
msvc_winlibs) |
| 406 |
return opts |
| 407 |
|
| 408 |
def get_option_link_args(self, target: 'BuildTarget', subproject: T.Optional[str] = None) -> T.List[str]: |
| 409 |
retval = self.get_compileropt_value('winlibs', target, subproject) |
| 410 |
assert isinstance(retval, list) |
| 411 |
libs: T.List[str] = retval.copy() |
| 412 |
for l in libs: |
| 413 |
assert isinstance(l, str) |
| 414 |
return libs |
| 415 |
|
| 416 |
|
| 417 |
class VisualStudioCCompiler(MSVCCompiler, VisualStudioLikeCCompilerMixin, CCompiler): |
| 418 |
|
| 419 |
_C11_VERSION = '>=19.28' |
| 420 |
_C17_VERSION = '>=19.28' |
| 421 |
|
| 422 |
def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, |
| 423 |
env: Environment, target: str, |
| 424 |
linker: T.Optional['DynamicLinker'] = None, |
| 425 |
full_version: T.Optional[str] = None): |
| 426 |
CCompiler.__init__(self, ccache, exelist, version, for_machine, |
| 427 |
env, linker=linker, full_version=full_version) |
| 428 |
MSVCCompiler.__init__(self, target) |
| 429 |
|
| 430 |
def get_options(self) -> 'MutableKeyedOptionDictType': |
| 431 |
opts = super().get_options() |
| 432 |
stds = ['c89', 'c99'] |
| 433 |
if version_compare(self.version, self._C11_VERSION): |
| 434 |
stds += ['c11'] |
| 435 |
if version_compare(self.version, self._C17_VERSION): |
| 436 |
stds += ['c17', 'c18'] |
| 437 |
key = self.form_compileropt_key('std') |
| 438 |
std_opt = opts[key] |
| 439 |
assert isinstance(std_opt, options.UserStdOption), 'for mypy' |
| 440 |
std_opt.set_versions(stds, gnu=True, gnu_deprecated=True) |
| 441 |
return opts |
| 442 |
|
| 443 |
def get_option_std_args(self, target: BuildTarget, subproject: T.Optional[str] = None) -> T.List[str]: |
| 444 |
args = [] |
| 445 |
std = self.get_compileropt_value('std', target, subproject) |
| 446 |
|
| 447 |
# As of MVSC 16.8, /std:c11 and /std:c17 are the only valid C standard options. |
| 448 |
if std in {'c11'}: |
| 449 |
args.append('/std:c11') |
| 450 |
elif std in {'c17', 'c18'}: |
| 451 |
args.append('/std:c17') |
| 452 |
return args |
| 453 |
|
| 454 |
|
| 455 |
class ClangClCCompiler(ClangCStds, ClangClCompiler, VisualStudioLikeCCompilerMixin, CCompiler): |
| 456 |
def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice, |
| 457 |
env: Environment, target: str, |
| 458 |
linker: T.Optional['DynamicLinker'] = None, |
| 459 |
full_version: T.Optional[str] = None): |
| 460 |
CCompiler.__init__(self, [], exelist, version, for_machine, |
| 461 |
env, linker=linker, full_version=full_version) |
| 462 |
ClangClCompiler.__init__(self, target) |
| 463 |
|
| 464 |
def get_option_std_args(self, target: BuildTarget, subproject: T.Optional[str] = None) -> T.List[str]: |
| 465 |
std = self.get_compileropt_value('std', target, subproject) |
| 466 |
assert isinstance(std, str) |
| 467 |
if std != "none": |
| 468 |
return [f'/clang:-std={std}'] |
| 469 |
return [] |
| 470 |
|
| 471 |
|
| 472 |
class IntelClCCompiler(IntelVisualStudioLikeCompiler, VisualStudioLikeCCompilerMixin, CCompiler): |
| 473 |
|
| 474 |
"""Intel "ICL" compiler abstraction.""" |
| 475 |
|
| 476 |
def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice, |
| 477 |
env: Environment, target: str, |
| 478 |
linker: T.Optional['DynamicLinker'] = None, |
| 479 |
full_version: T.Optional[str] = None): |
| 480 |
CCompiler.__init__(self, [], exelist, version, for_machine, |
| 481 |
env, linker=linker, full_version=full_version) |
| 482 |
IntelVisualStudioLikeCompiler.__init__(self, target) |
| 483 |
|
| 484 |
def get_options(self) -> 'MutableKeyedOptionDictType': |
| 485 |
opts = super().get_options() |
| 486 |
key = self.form_compileropt_key('std') |
| 487 |
std_opt = opts[key] |
| 488 |
assert isinstance(std_opt, options.UserStdOption), 'for mypy' |
| 489 |
std_opt.set_versions(['c89', 'c99', 'c11']) |
| 490 |
return opts |
| 491 |
|
| 492 |
def get_option_std_args(self, target: BuildTarget, subproject: T.Optional[str] = None) -> T.List[str]: |
| 493 |
args: T.List[str] = [] |
| 494 |
std = self.get_compileropt_value('std', target, subproject) |
| 495 |
assert isinstance(std, str) |
| 496 |
if std == 'c89': |
| 497 |
mlog.log("ICL doesn't explicitly implement c89, setting the standard to 'none', which is close.", once=True) |
| 498 |
elif std != 'none': |
| 499 |
args.append('/Qstd:' + std) |
| 500 |
return args |
| 501 |
|
| 502 |
|
| 503 |
class IntelLLVMClCCompiler(IntelClCCompiler): |
| 504 |
|
| 505 |
id = 'intel-llvm-cl' |
| 506 |
|
| 507 |
|
| 508 |
class ArmCCompiler(ArmCompiler, CCompiler): |
| 509 |
def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, |
| 510 |
env: Environment, |
| 511 |
linker: T.Optional['DynamicLinker'] = None, |
| 512 |
full_version: T.Optional[str] = None): |
| 513 |
CCompiler.__init__(self, ccache, exelist, version, for_machine, |
| 514 |
env, linker=linker, full_version=full_version) |
| 515 |
ArmCompiler.__init__(self) |
| 516 |
|
| 517 |
def get_options(self) -> 'MutableKeyedOptionDictType': |
| 518 |
opts = super().get_options() |
| 519 |
key = self.form_compileropt_key('std') |
| 520 |
std_opt = opts[key] |
| 521 |
assert isinstance(std_opt, options.UserStdOption), 'for mypy' |
| 522 |
std_opt.set_versions(['c89', 'c99', 'c11']) |
| 523 |
return opts |
| 524 |
|
| 525 |
def get_option_std_args(self, target: BuildTarget, subproject: T.Optional[str] = None) -> T.List[str]: |
| 526 |
args = [] |
| 527 |
std = self.get_compileropt_value('std', target, subproject) |
| 528 |
assert isinstance(std, str) |
| 529 |
if std != 'none': |
| 530 |
args.append('--' + std) |
| 531 |
return args |
| 532 |
|
| 533 |
|
| 534 |
class CcrxCCompiler(CcrxCompiler, CCompiler): |
| 535 |
def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, |
| 536 |
env: Environment, |
| 537 |
linker: T.Optional['DynamicLinker'] = None, |
| 538 |
full_version: T.Optional[str] = None): |
| 539 |
CCompiler.__init__(self, ccache, exelist, version, for_machine, |
| 540 |
env, linker=linker, full_version=full_version) |
| 541 |
CcrxCompiler.__init__(self) |
| 542 |
|
| 543 |
# Override CCompiler.get_always_args |
| 544 |
def get_always_args(self) -> T.List[str]: |
| 545 |
return ['-nologo'] |
| 546 |
|
| 547 |
def get_options(self) -> 'MutableKeyedOptionDictType': |
| 548 |
opts = super().get_options() |
| 549 |
key = self.form_compileropt_key('std') |
| 550 |
std_opt = opts[key] |
| 551 |
assert isinstance(std_opt, options.UserStdOption), 'for mypy' |
| 552 |
std_opt.set_versions(['c89', 'c99']) |
| 553 |
return opts |
| 554 |
|
| 555 |
def get_no_stdinc_args(self) -> T.List[str]: |
| 556 |
return [] |
| 557 |
|
| 558 |
def get_option_std_args(self, target: BuildTarget, subproject: T.Optional[str] = None) -> T.List[str]: |
| 559 |
args = [] |
| 560 |
std = self.get_compileropt_value('std', target, subproject) |
| 561 |
assert isinstance(std, str) |
| 562 |
if std == 'c89': |
| 563 |
args.append('-lang=c') |
| 564 |
elif std == 'c99': |
| 565 |
args.append('-lang=c99') |
| 566 |
return args |
| 567 |
|
| 568 |
def get_compile_only_args(self) -> T.List[str]: |
| 569 |
return [] |
| 570 |
|
| 571 |
def get_no_optimization_args(self) -> T.List[str]: |
| 572 |
return ['-optimize=0'] |
| 573 |
|
| 574 |
def get_output_args(self, target: str) -> T.List[str]: |
| 575 |
return [f'-output=obj={target}'] |
| 576 |
|
| 577 |
def get_werror_args(self) -> T.List[str]: |
| 578 |
return ['-change_message=error'] |
| 579 |
|
| 580 |
def get_include_args(self, path: str, is_system: bool) -> T.List[str]: |
| 581 |
if path == '': |
| 582 |
path = '.' |
| 583 |
return ['-include=' + path] |
| 584 |
|
| 585 |
|
| 586 |
class Xc16CCompiler(Xc16Compiler, CCompiler): |
| 587 |
def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, |
| 588 |
env: Environment, |
| 589 |
linker: T.Optional['DynamicLinker'] = None, |
| 590 |
full_version: T.Optional[str] = None): |
| 591 |
CCompiler.__init__(self, ccache, exelist, version, for_machine, |
| 592 |
env, linker=linker, full_version=full_version) |
| 593 |
Xc16Compiler.__init__(self) |
| 594 |
|
| 595 |
def get_options(self) -> 'MutableKeyedOptionDictType': |
| 596 |
opts = super().get_options() |
| 597 |
key = self.form_compileropt_key('std') |
| 598 |
std_opt = opts[key] |
| 599 |
assert isinstance(std_opt, options.UserStdOption), 'for mypy' |
| 600 |
std_opt.set_versions(['c89', 'c99'], gnu=True) |
| 601 |
return opts |
| 602 |
|
| 603 |
def get_no_stdinc_args(self) -> T.List[str]: |
| 604 |
return [] |
| 605 |
|
| 606 |
def get_option_std_args(self, target: BuildTarget, subproject: T.Optional[str] = None) -> T.List[str]: |
| 607 |
args = [] |
| 608 |
std = self.get_compileropt_value('std', target, subproject) |
| 609 |
assert isinstance(std, str) |
| 610 |
if std != 'none': |
| 611 |
args.append('-ansi') |
| 612 |
args.append('-std=' + std) |
| 613 |
return args |
| 614 |
|
| 615 |
def get_compile_only_args(self) -> T.List[str]: |
| 616 |
return [] |
| 617 |
|
| 618 |
def get_no_optimization_args(self) -> T.List[str]: |
| 619 |
return ['-O0'] |
| 620 |
|
| 621 |
def get_output_args(self, target: str) -> T.List[str]: |
| 622 |
return [f'-o{target}'] |
| 623 |
|
| 624 |
def get_werror_args(self) -> T.List[str]: |
| 625 |
return ['-change_message=error'] |
| 626 |
|
| 627 |
def get_include_args(self, path: str, is_system: bool) -> T.List[str]: |
| 628 |
if path == '': |
| 629 |
path = '.' |
| 630 |
return ['-I' + path] |
| 631 |
|
| 632 |
|
| 633 |
class Xc32CCompiler(Xc32CStds, Xc32Compiler, GnuCCompiler): |
| 634 |
|
| 635 |
"""Microchip XC32 C compiler.""" |
| 636 |
|
| 637 |
def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, |
| 638 |
env: Environment, linker: T.Optional[DynamicLinker] = None, |
| 639 |
defines: T.Optional[T.Dict[str, str]] = None, |
| 640 |
full_version: T.Optional[str] = None): |
| 641 |
GnuCCompiler.__init__(self, ccache, exelist, version, for_machine, |
| 642 |
env, linker=linker, full_version=full_version, defines=defines) |
| 643 |
Xc32Compiler.__init__(self) |
| 644 |
|
| 645 |
|
| 646 |
class CompCertCCompiler(CompCertCompiler, CCompiler): |
| 647 |
def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, |
| 648 |
env: Environment, |
| 649 |
linker: T.Optional['DynamicLinker'] = None, |
| 650 |
full_version: T.Optional[str] = None): |
| 651 |
CCompiler.__init__(self, ccache, exelist, version, for_machine, |
| 652 |
env, linker=linker, full_version=full_version) |
| 653 |
CompCertCompiler.__init__(self) |
| 654 |
|
| 655 |
def get_options(self) -> 'MutableKeyedOptionDictType': |
| 656 |
opts = super().get_options() |
| 657 |
key = self.form_compileropt_key('std') |
| 658 |
std_opt = opts[key] |
| 659 |
assert isinstance(std_opt, options.UserStdOption), 'for mypy' |
| 660 |
std_opt.set_versions(['c89', 'c99']) |
| 661 |
return opts |
| 662 |
|
| 663 |
def get_no_optimization_args(self) -> T.List[str]: |
| 664 |
return ['-O0'] |
| 665 |
|
| 666 |
def get_output_args(self, target: str) -> T.List[str]: |
| 667 |
return [f'-o{target}'] |
| 668 |
|
| 669 |
def get_werror_args(self) -> T.List[str]: |
| 670 |
return ['-Werror'] |
| 671 |
|
| 672 |
def get_include_args(self, path: str, is_system: bool) -> T.List[str]: |
| 673 |
if path == '': |
| 674 |
path = '.' |
| 675 |
return ['-I' + path] |
| 676 |
|
| 677 |
class TICCompiler(TICompiler, CCompiler): |
| 678 |
def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, |
| 679 |
env: Environment, |
| 680 |
linker: T.Optional['DynamicLinker'] = None, |
| 681 |
full_version: T.Optional[str] = None): |
| 682 |
CCompiler.__init__(self, ccache, exelist, version, for_machine, |
| 683 |
env, linker=linker, full_version=full_version) |
| 684 |
TICompiler.__init__(self) |
| 685 |
|
| 686 |
# Override CCompiler.get_always_args |
| 687 |
def get_always_args(self) -> T.List[str]: |
| 688 |
return [] |
| 689 |
|
| 690 |
def get_options(self) -> 'MutableKeyedOptionDictType': |
| 691 |
opts = super().get_options() |
| 692 |
key = self.form_compileropt_key('std') |
| 693 |
std_opt = opts[key] |
| 694 |
assert isinstance(std_opt, options.UserStdOption), 'for mypy' |
| 695 |
std_opt.set_versions(['c89', 'c99', 'c11']) |
| 696 |
return opts |
| 697 |
|
| 698 |
def get_no_stdinc_args(self) -> T.List[str]: |
| 699 |
return [] |
| 700 |
|
| 701 |
def get_option_std_args(self, target: BuildTarget, subproject: T.Optional[str] = None) -> T.List[str]: |
| 702 |
args = [] |
| 703 |
std = self.get_compileropt_value('std', target, subproject) |
| 704 |
assert isinstance(std, str) |
| 705 |
if std != 'none': |
| 706 |
args.append('--' + std) |
| 707 |
return args |
| 708 |
|
| 709 |
class C2000CCompiler(TICCompiler): |
| 710 |
# Required for backwards compat with projects created before ti-cgt support existed |
| 711 |
id = 'c2000' |
| 712 |
|
| 713 |
class C6000CCompiler(TICCompiler): |
| 714 |
id = 'c6000' |
| 715 |
|
| 716 |
class MetrowerksCCompilerARM(MetrowerksCompiler, CCompiler): |
| 717 |
id = 'mwccarm' |
| 718 |
|
| 719 |
def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, |
| 720 |
env: Environment, |
| 721 |
linker: T.Optional['DynamicLinker'] = None, |
| 722 |
full_version: T.Optional[str] = None): |
| 723 |
CCompiler.__init__(self, ccache, exelist, version, for_machine, |
| 724 |
env, linker=linker, full_version=full_version) |
| 725 |
MetrowerksCompiler.__init__(self) |
| 726 |
|
| 727 |
def get_instruction_set_args(self, instruction_set: str) -> T.Optional[T.List[str]]: |
| 728 |
return mwccarm_instruction_set_args.get(instruction_set, None) |
| 729 |
|
| 730 |
def get_options(self) -> 'MutableKeyedOptionDictType': |
| 731 |
opts = super().get_options() |
| 732 |
self._update_language_stds(opts, ['c99']) |
| 733 |
return opts |
| 734 |
|
| 735 |
def get_option_std_args(self, target: BuildTarget, subproject: T.Optional[str] = None) -> T.List[str]: |
| 736 |
args = [] |
| 737 |
std = self.get_compileropt_value('std', target, subproject) |
| 738 |
assert isinstance(std, str) |
| 739 |
if std != 'none': |
| 740 |
args.append('-lang') |
| 741 |
args.append(std) |
| 742 |
return args |
| 743 |
|
| 744 |
class MetrowerksCCompilerEmbeddedPowerPC(MetrowerksCompiler, CCompiler): |
| 745 |
id = 'mwcceppc' |
| 746 |
|
| 747 |
def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, |
| 748 |
env: Environment, |
| 749 |
linker: T.Optional['DynamicLinker'] = None, |
| 750 |
full_version: T.Optional[str] = None): |
| 751 |
CCompiler.__init__(self, ccache, exelist, version, for_machine, |
| 752 |
env, linker=linker, full_version=full_version) |
| 753 |
MetrowerksCompiler.__init__(self) |
| 754 |
|
| 755 |
def get_instruction_set_args(self, instruction_set: str) -> T.Optional[T.List[str]]: |
| 756 |
return mwcceppc_instruction_set_args.get(instruction_set, None) |
| 757 |
|
| 758 |
def get_options(self) -> 'MutableKeyedOptionDictType': |
| 759 |
opts = super().get_options() |
| 760 |
self._update_language_stds(opts, ['c99']) |
| 761 |
return opts |
| 762 |
|
| 763 |
def get_option_std_args(self, target: BuildTarget, subproject: T.Optional[str] = None) -> T.List[str]: |
| 764 |
args = [] |
| 765 |
std = self.get_compileropt_value('std', target, subproject) |
| 766 |
assert isinstance(std, str) |
| 767 |
if std != 'none': |
| 768 |
args.append('-lang ' + std) |
| 769 |
return args |
| 770 |
|
| 771 |
class TaskingCCompiler(TaskingCompiler, CCompiler): |
| 772 |
id = 'tasking' |
| 773 |
|
| 774 |
def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, |
| 775 |
env: Environment, |
| 776 |
linker: T.Optional['DynamicLinker'] = None, |
| 777 |
full_version: T.Optional[str] = None): |
| 778 |
CCompiler.__init__(self, ccache, exelist, version, for_machine, |
| 779 |
env, linker=linker, full_version=full_version) |
| 780 |
TaskingCompiler.__init__(self) |