meson/mesonbuild/compilers/objcpp.py

126 lines
5.4 KiB
Python
Raw Normal View History

# SPDX-License-Identifier: Apache-2.0
2017-06-23 07:42:41 +08:00
# Copyright 2012-2017 The Meson development team
from __future__ import annotations
2017-06-23 07:42:41 +08:00
import typing as T
2017-06-23 07:42:41 +08:00
from ..options import OptionKey, UserStdOption
2017-06-23 07:42:41 +08:00
from .cpp import ALL_STDS
2019-07-03 06:14:48 +08:00
from .compilers import Compiler
from .mixins.apple import AppleCPPStdsMixin
from .mixins.gnu import GnuCompiler, GnuCPPStds, gnu_common_warning_args, gnu_objc_warning_args
from .mixins.clang import ClangCompiler, ClangCPPStds
from .mixins.clike import CLikeCompiler
2017-06-23 07:42:41 +08:00
if T.TYPE_CHECKING:
from ..envconfig import MachineInfo
2020-09-22 04:04:58 +08:00
from ..environment import Environment
from ..linkers.linkers import DynamicLinker
from ..mesonlib import MachineChoice
from ..build import BuildTarget
from ..options import MutableKeyedOptionDictType
class ObjCPPCompiler(CLikeCompiler, Compiler):
language = 'objcpp'
def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice,
is_cross: bool, info: 'MachineInfo',
2020-09-22 04:04:58 +08:00
linker: T.Optional['DynamicLinker'] = None,
full_version: T.Optional[str] = None):
Compiler.__init__(self, ccache, exelist, version, for_machine, info,
2020-09-22 04:04:58 +08:00
is_cross=is_cross, full_version=full_version,
linker=linker)
CLikeCompiler.__init__(self)
2017-06-23 07:42:41 +08:00
def form_compileropt_key(self, basename: str) -> OptionKey:
if basename == 'std':
return OptionKey('cpp_std', machine=self.for_machine)
return super().form_compileropt_key(basename)
def make_option_name(self, key: OptionKey) -> str:
if key.name == 'std':
return 'cpp_std'
return super().make_option_name(key)
@staticmethod
2020-09-22 04:04:58 +08:00
def get_display_language() -> str:
return 'Objective-C++'
2020-09-22 04:04:58 +08:00
def sanity_check(self, work_dir: str, environment: 'Environment') -> None:
code = '#import<stdio.h>\nclass MyClass;int main(void) { return 0; }\n'
return self._sanity_check_impl(work_dir, environment, 'sanitycheckobjcpp.mm', code)
2017-06-23 07:42:41 +08:00
def get_options(self) -> MutableKeyedOptionDictType:
opts = super().get_options()
key = self.form_compileropt_key('std')
opts.update({
key: UserStdOption('cpp', ALL_STDS),
})
return opts
2017-06-23 07:42:41 +08:00
class GnuObjCPPCompiler(GnuCPPStds, GnuCompiler, ObjCPPCompiler):
def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice,
2020-09-22 04:04:58 +08:00
is_cross: bool, info: 'MachineInfo',
defines: T.Optional[T.Dict[str, str]] = None,
linker: T.Optional['DynamicLinker'] = None,
full_version: T.Optional[str] = None):
ObjCPPCompiler.__init__(self, ccache, exelist, version, for_machine, is_cross,
info, linker=linker, full_version=full_version)
GnuCompiler.__init__(self, defines)
compilers: remove opinionated c++ warning flag -Wnon-virtual-dtor is not what people think of as a standard warning flag. It was previously removed from -Wall in https://gcc.gnu.org/bugzilla/show_bug.cgi?id=16190 on the grounds that people didn't like it and were refusing to use -Wall at all because it forced this warning. Instead, it is enabled by -Weffc++ which is typically not enabled and even comes with GCC documentation warnings stating that the standard library doesn't obey it, and you might need to `grep -v` and filter out warnings. (!!!) It doesn't fit into the typical semantics of Meson's warning_level option, which usually aligns with compiler standard warning levels rather than a niche ideological warning level. It was originally added in commit 22af56e05aa9cba4740d2ff303d876bb0c3cfb2b, but without any specific rationale included, and has gone unquestioned since then -- except by the Meson users who see it, assume there is a finely crafted design behind it, and quietly opt out by rolling their own warning options with `add_project_arguments('-Wall', ...)`. Furthermore a GCC component maintainer for the C++ standard library opened a Meson bug report specially to tell us that this warning flag is a "dumb option" and "broken by design" and "doesn't warn about the right thing anyway", thus it should not be used. This is a reasonably authoritative source that maybe, just maybe, this flag... is too opinionated to force upon Meson users without recourse. It's gone beyond opinionated and into the realm of compiler vendors seem to think that the state of the language would be better if the flag did not exist at all, whether default or not. Fixes #11096
2022-05-02 06:59:21 +08:00
default_warn_args = ['-Wall', '-Winvalid-pch']
2019-02-19 06:06:27 +08:00
self.warn_args = {'0': [],
'1': default_warn_args,
2017-06-23 07:42:41 +08:00
'2': default_warn_args + ['-Wextra'],
'3': default_warn_args + ['-Wextra', '-Wpedantic'],
'everything': (default_warn_args + ['-Wextra', '-Wpedantic'] +
self.supported_warn_args(gnu_common_warning_args) +
self.supported_warn_args(gnu_objc_warning_args))}
2017-06-23 07:42:41 +08:00
def get_option_std_args(self, target: BuildTarget, env: Environment, subproject: T.Optional[str] = None) -> T.List[str]:
args: T.List[str] = []
key = OptionKey('cpp_std', subproject=subproject, machine=self.for_machine)
if target:
std = env.coredata.get_option_for_target(target, key)
else:
std = env.coredata.optstore.get_value_for(key)
assert isinstance(std, str)
if std != 'none':
args.append('-std=' + std)
return args
class ClangObjCPPCompiler(ClangCPPStds, ClangCompiler, ObjCPPCompiler):
2020-09-22 04:04:58 +08:00
def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice,
2020-09-22 04:04:58 +08:00
is_cross: bool, info: 'MachineInfo',
defines: T.Optional[T.Dict[str, str]] = None,
linker: T.Optional['DynamicLinker'] = None,
full_version: T.Optional[str] = None):
ObjCPPCompiler.__init__(self, ccache, exelist, version, for_machine, is_cross,
info, linker=linker, full_version=full_version)
2020-09-22 04:04:58 +08:00
ClangCompiler.__init__(self, defines)
compilers: remove opinionated c++ warning flag -Wnon-virtual-dtor is not what people think of as a standard warning flag. It was previously removed from -Wall in https://gcc.gnu.org/bugzilla/show_bug.cgi?id=16190 on the grounds that people didn't like it and were refusing to use -Wall at all because it forced this warning. Instead, it is enabled by -Weffc++ which is typically not enabled and even comes with GCC documentation warnings stating that the standard library doesn't obey it, and you might need to `grep -v` and filter out warnings. (!!!) It doesn't fit into the typical semantics of Meson's warning_level option, which usually aligns with compiler standard warning levels rather than a niche ideological warning level. It was originally added in commit 22af56e05aa9cba4740d2ff303d876bb0c3cfb2b, but without any specific rationale included, and has gone unquestioned since then -- except by the Meson users who see it, assume there is a finely crafted design behind it, and quietly opt out by rolling their own warning options with `add_project_arguments('-Wall', ...)`. Furthermore a GCC component maintainer for the C++ standard library opened a Meson bug report specially to tell us that this warning flag is a "dumb option" and "broken by design" and "doesn't warn about the right thing anyway", thus it should not be used. This is a reasonably authoritative source that maybe, just maybe, this flag... is too opinionated to force upon Meson users without recourse. It's gone beyond opinionated and into the realm of compiler vendors seem to think that the state of the language would be better if the flag did not exist at all, whether default or not. Fixes #11096
2022-05-02 06:59:21 +08:00
default_warn_args = ['-Wall', '-Winvalid-pch']
2019-02-19 06:06:27 +08:00
self.warn_args = {'0': [],
'1': default_warn_args,
'2': default_warn_args + ['-Wextra'],
'3': default_warn_args + ['-Wextra', '-Wpedantic'],
'everything': ['-Weverything']}
def get_option_std_args(self, target: BuildTarget, env: Environment, subproject: T.Optional[str] = None) -> T.List[str]:
args = []
key = OptionKey('cpp_std', machine=self.for_machine)
std = self.get_compileropt_value(key, env, target, subproject)
assert isinstance(std, str)
if std != 'none':
args.append('-std=' + std)
return args
class AppleClangObjCPPCompiler(AppleCPPStdsMixin, ClangObjCPPCompiler):
"""Handle the differences between Apple's clang and vanilla clang."""