| 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 .cpp import ALL_STDS |
| 11 |
from .compilers import Compiler |
| 12 |
from .mixins.apple import AppleCPPStdsMixin |
| 13 |
from .mixins.gnu import GnuCompiler, GnuCPPStds, gnu_common_warning_args, gnu_objc_warning_args |
| 14 |
from .mixins.clang import ClangCompiler, ClangCPPStds |
| 15 |
from .mixins.clike import CLikeCompiler |
| 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 ObjCPPCompiler(CLikeCompiler, Compiler): |
| 26 |
|
| 27 |
language = 'objcpp' |
| 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, linker=linker) |
| 35 |
CLikeCompiler.__init__(self) |
| 36 |
|
| 37 |
def get_no_stdinc_args(self) -> T.List[str]: |
| 38 |
return ['-nostdinc++'] |
| 39 |
|
| 40 |
def get_no_stdlib_link_args(self) -> T.List[str]: |
| 41 |
return ['-nostdlib++'] |
| 42 |
|
| 43 |
def form_compileropt_key(self, basename: str) -> OptionKey: |
| 44 |
if basename == 'std': |
| 45 |
return OptionKey('cpp_std', machine=self.for_machine) |
| 46 |
return super().form_compileropt_key(basename) |
| 47 |
|
| 48 |
def make_option_name(self, key: OptionKey) -> str: |
| 49 |
if key.name == 'std': |
| 50 |
return 'cpp_std' |
| 51 |
return super().make_option_name(key) |
| 52 |
|
| 53 |
@staticmethod |
| 54 |
def get_display_language() -> str: |
| 55 |
return 'Objective-C++' |
| 56 |
|
| 57 |
def _sanity_check_source_code(self) -> str: |
| 58 |
return '#import<stdio.h>\nclass MyClass;int main(void) { return 0; }\n' |
| 59 |
|
| 60 |
def get_options(self) -> MutableKeyedOptionDictType: |
| 61 |
opts = super().get_options() |
| 62 |
key = self.form_compileropt_key('std') |
| 63 |
opts.update({ |
| 64 |
key: UserStdOption('cpp', ALL_STDS), |
| 65 |
}) |
| 66 |
return opts |
| 67 |
|
| 68 |
|
| 69 |
class GnuObjCPPCompiler(GnuCPPStds, GnuCompiler, ObjCPPCompiler): |
| 70 |
def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, |
| 71 |
env: Environment, |
| 72 |
defines: T.Optional[T.Dict[str, str]] = None, |
| 73 |
linker: T.Optional['DynamicLinker'] = None, |
| 74 |
full_version: T.Optional[str] = None): |
| 75 |
ObjCPPCompiler.__init__(self, ccache, exelist, version, for_machine, |
| 76 |
env, linker=linker, full_version=full_version) |
| 77 |
GnuCompiler.__init__(self, defines) |
| 78 |
default_warn_args = ['-Wall', '-Winvalid-pch'] |
| 79 |
self.warn_args = {'0': [], |
| 80 |
'1': default_warn_args, |
| 81 |
'2': default_warn_args + ['-Wextra'], |
| 82 |
'3': default_warn_args + ['-Wextra', '-Wpedantic'], |
| 83 |
'everything': (default_warn_args + ['-Wextra', '-Wpedantic'] + |
| 84 |
self.supported_warn_args(gnu_common_warning_args) + |
| 85 |
self.supported_warn_args(gnu_objc_warning_args))} |
| 86 |
|
| 87 |
def get_option_std_args(self, target: BuildTarget, subproject: T.Optional[str] = None) -> T.List[str]: |
| 88 |
args: T.List[str] = [] |
| 89 |
key = OptionKey('cpp_std', subproject=subproject, machine=self.for_machine) |
| 90 |
if target: |
| 91 |
std = self.environment.coredata.get_option_for_target(target, key) |
| 92 |
else: |
| 93 |
std = self.environment.coredata.optstore.get_value_for(key) |
| 94 |
assert isinstance(std, str) |
| 95 |
if std != 'none': |
| 96 |
args.append('-std=' + std) |
| 97 |
return args |
| 98 |
|
| 99 |
class ClangObjCPPCompiler(ClangCPPStds, ClangCompiler, ObjCPPCompiler): |
| 100 |
|
| 101 |
def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, |
| 102 |
env: Environment, |
| 103 |
defines: T.Optional[T.Dict[str, str]] = None, |
| 104 |
linker: T.Optional['DynamicLinker'] = None, |
| 105 |
full_version: T.Optional[str] = None): |
| 106 |
ObjCPPCompiler.__init__(self, ccache, exelist, version, for_machine, |
| 107 |
env, linker=linker, full_version=full_version) |
| 108 |
ClangCompiler.__init__(self, defines) |
| 109 |
default_warn_args = ['-Wall', '-Winvalid-pch'] |
| 110 |
self.warn_args = {'0': [], |
| 111 |
'1': default_warn_args, |
| 112 |
'2': default_warn_args + ['-Wextra'], |
| 113 |
'3': default_warn_args + ['-Wextra', '-Wpedantic'], |
| 114 |
'everything': ['-Weverything']} |
| 115 |
|
| 116 |
def get_option_std_args(self, target: BuildTarget, subproject: T.Optional[str] = None) -> T.List[str]: |
| 117 |
args = [] |
| 118 |
key = OptionKey('cpp_std', machine=self.for_machine) |
| 119 |
std = self.get_compileropt_value(key, target, subproject) |
| 120 |
assert isinstance(std, str) |
| 121 |
if std != 'none': |
| 122 |
args.append('-std=' + std) |
| 123 |
return args |
| 124 |
|
| 125 |
|
| 126 |
class AppleClangObjCPPCompiler(AppleCPPStdsMixin, ClangObjCPPCompiler): |
| 127 |
|
| 128 |
"""Handle the differences between Apple's clang and vanilla clang.""" |