The Meson Build System http://mesonbuild.com/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

108 lines
4.7 KiB

# SPDX-License-Identifier: Apache-2.0
# Copyright 2012-2017 The Meson development team
from __future__ import annotations
import typing as T
from .. import coredata
from ..mesonlib import OptionKey
from .mixins.clike import CLikeCompiler
from .compilers import Compiler
from .mixins.gnu import GnuCompiler, gnu_common_warning_args, gnu_objc_warning_args
from .mixins.clang import ClangCompiler
if T.TYPE_CHECKING:
from ..programs import ExternalProgram
from ..envconfig import MachineInfo
from ..environment import Environment
from ..linkers.linkers import DynamicLinker
from ..mesonlib import MachineChoice
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',
exe_wrap: T.Optional['ExternalProgram'],
linker: T.Optional['DynamicLinker'] = None,
full_version: T.Optional[str] = None):
Compiler.__init__(self, ccache, exelist, version, for_machine, info,
is_cross=is_cross, full_version=full_version,
linker=linker)
CLikeCompiler.__init__(self, exe_wrap)
@staticmethod
def get_display_language() -> str:
return 'Objective-C++'
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)
class GnuObjCPPCompiler(GnuCompiler, ObjCPPCompiler):
def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice,
is_cross: bool, info: 'MachineInfo',
exe_wrapper: T.Optional['ExternalProgram'] = None,
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, exe_wrapper, 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
3 years ago
default_warn_args = ['-Wall', '-Winvalid-pch']
self.warn_args = {'0': [],
'1': default_warn_args,
'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))}
class ClangObjCPPCompiler(ClangCompiler, ObjCPPCompiler):
def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice,
is_cross: bool, info: 'MachineInfo',
exe_wrapper: T.Optional['ExternalProgram'] = None,
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, exe_wrapper, linker=linker, full_version=full_version)
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
3 years ago
default_warn_args = ['-Wall', '-Winvalid-pch']
self.warn_args = {'0': [],
'1': default_warn_args,
'2': default_warn_args + ['-Wextra'],
'3': default_warn_args + ['-Wextra', '-Wpedantic'],
'everything': ['-Weverything']}
def get_options(self) -> 'coredata.MutableKeyedOptionDictType':
opts = super().get_options()
opts.update({
OptionKey('std', machine=self.for_machine, lang='cpp'): coredata.UserComboOption(
'C++ language standard to use',
['none', 'c++98', 'c++11', 'c++14', 'c++17', 'c++20', 'c++2b',
'gnu++98', 'gnu++11', 'gnu++14', 'gnu++17', 'gnu++20',
'gnu++2b'],
'none',
)
})
return opts
def get_option_compile_args(self, options: 'coredata.KeyedOptionDictType') -> T.List[str]:
args = []
std = options[OptionKey('std', machine=self.for_machine, lang='cpp')]
if std.value != 'none':
args.append('-std=' + std.value)
return args
class AppleClangObjCPPCompiler(ClangObjCPPCompiler):
"""Handle the differences between Apple's clang and vanilla clang."""