compilers/gnu: Split Gnu C++ standard handling into a mixin class
So we can re-use it in the ObjC++ standards
This commit is contained in:
parent
30ca64a25b
commit
4f314baaf6
|
@ -25,7 +25,7 @@ from .mixins.ccrx import CcrxCompiler
|
||||||
from .mixins.ti import TICompiler
|
from .mixins.ti import TICompiler
|
||||||
from .mixins.arm import ArmCompiler, ArmclangCompiler
|
from .mixins.arm import ArmCompiler, ArmclangCompiler
|
||||||
from .mixins.visualstudio import MSVCCompiler, ClangClCompiler
|
from .mixins.visualstudio import MSVCCompiler, ClangClCompiler
|
||||||
from .mixins.gnu import GnuCompiler, gnu_common_warning_args, gnu_cpp_warning_args
|
from .mixins.gnu import GnuCompiler, GnuCPPStds, gnu_common_warning_args, gnu_cpp_warning_args
|
||||||
from .mixins.intel import IntelGnuLikeCompiler, IntelVisualStudioLikeCompiler
|
from .mixins.intel import IntelGnuLikeCompiler, IntelVisualStudioLikeCompiler
|
||||||
from .mixins.clang import ClangCompiler, ClangCPPStds
|
from .mixins.clang import ClangCompiler, ClangCPPStds
|
||||||
from .mixins.elbrus import ElbrusCompiler
|
from .mixins.elbrus import ElbrusCompiler
|
||||||
|
@ -417,7 +417,7 @@ class ArmclangCPPCompiler(ArmclangCompiler, CPPCompiler):
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
|
||||||
class GnuCPPCompiler(_StdCPPLibMixin, GnuCompiler, CPPCompiler):
|
class GnuCPPCompiler(_StdCPPLibMixin, GnuCPPStds, GnuCompiler, CPPCompiler):
|
||||||
def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool,
|
def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool,
|
||||||
info: 'MachineInfo',
|
info: 'MachineInfo',
|
||||||
linker: T.Optional['DynamicLinker'] = None,
|
linker: T.Optional['DynamicLinker'] = None,
|
||||||
|
@ -437,7 +437,7 @@ class GnuCPPCompiler(_StdCPPLibMixin, GnuCompiler, CPPCompiler):
|
||||||
|
|
||||||
def get_options(self) -> 'MutableKeyedOptionDictType':
|
def get_options(self) -> 'MutableKeyedOptionDictType':
|
||||||
key = self.form_compileropt_key('std')
|
key = self.form_compileropt_key('std')
|
||||||
opts = CPPCompiler.get_options(self)
|
opts = super().get_options()
|
||||||
self.update_options(
|
self.update_options(
|
||||||
opts,
|
opts,
|
||||||
self.create_option(options.UserComboOption,
|
self.create_option(options.UserComboOption,
|
||||||
|
@ -454,17 +454,6 @@ class GnuCPPCompiler(_StdCPPLibMixin, GnuCompiler, CPPCompiler):
|
||||||
'STL debug mode',
|
'STL debug mode',
|
||||||
False),
|
False),
|
||||||
)
|
)
|
||||||
cppstd_choices = [
|
|
||||||
'c++98', 'c++03', 'c++11', 'c++14', 'c++17', 'c++1z',
|
|
||||||
'c++2a', 'c++20',
|
|
||||||
]
|
|
||||||
if version_compare(self.version, '>=11.0.0'):
|
|
||||||
cppstd_choices.append('c++23')
|
|
||||||
if version_compare(self.version, '>=14.0.0'):
|
|
||||||
cppstd_choices.append('c++26')
|
|
||||||
std_opt = opts[key]
|
|
||||||
assert isinstance(std_opt, options.UserStdOption), 'for mypy'
|
|
||||||
std_opt.set_versions(cppstd_choices, gnu=True)
|
|
||||||
if self.info.is_windows() or self.info.is_cygwin():
|
if self.info.is_windows() or self.info.is_cygwin():
|
||||||
self.update_options(
|
self.update_options(
|
||||||
opts,
|
opts,
|
||||||
|
|
|
@ -657,3 +657,28 @@ class GnuCStds(Compiler):
|
||||||
assert isinstance(std_opt, UserStdOption), 'for mypy'
|
assert isinstance(std_opt, UserStdOption), 'for mypy'
|
||||||
std_opt.set_versions(stds, gnu=True)
|
std_opt.set_versions(stds, gnu=True)
|
||||||
return opts
|
return opts
|
||||||
|
|
||||||
|
|
||||||
|
class GnuCPPStds(Compiler):
|
||||||
|
|
||||||
|
"""Mixin class for GNU based compilers for setting CPP standards."""
|
||||||
|
|
||||||
|
_CPP23_VERSION = '>=11.0.0'
|
||||||
|
_CPP26_VERSION = '>=14.0.0'
|
||||||
|
|
||||||
|
def get_options(self) -> MutableKeyedOptionDictType:
|
||||||
|
opts = super().get_options()
|
||||||
|
|
||||||
|
stds = [
|
||||||
|
'c++98', 'c++03', 'c++11', 'c++14', 'c++17', 'c++1z',
|
||||||
|
'c++2a', 'c++20',
|
||||||
|
]
|
||||||
|
if mesonlib.version_compare(self.version, self._CPP23_VERSION):
|
||||||
|
stds.append('c++23')
|
||||||
|
if mesonlib.version_compare(self.version, self._CPP26_VERSION):
|
||||||
|
stds.append('c++26')
|
||||||
|
key = self.form_compileropt_key('std')
|
||||||
|
std_opt = opts[key]
|
||||||
|
assert isinstance(std_opt, UserStdOption), 'for mypy'
|
||||||
|
std_opt.set_versions(stds, gnu=True)
|
||||||
|
return opts
|
||||||
|
|
Loading…
Reference in New Issue