Skip to content

Commit

Permalink
compilers/gnu: Split Gnu C++ standard handling into a mixin class
Browse files Browse the repository at this point in the history
So we can re-use it in the ObjC++ standards
  • Loading branch information
dcbaker committed Sep 6, 2024
1 parent 21ae664 commit 42c0747
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
17 changes: 3 additions & 14 deletions mesonbuild/compilers/cpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from .mixins.ti import TICompiler
from .mixins.arm import ArmCompiler, ArmclangCompiler
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.clang import ClangCompiler, ClangCPPStds
from .mixins.elbrus import ElbrusCompiler
Expand Down Expand Up @@ -413,7 +413,7 @@ def get_option_link_args(self, options: 'KeyedOptionDictType') -> T.List[str]:
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,
info: 'MachineInfo',
linker: T.Optional['DynamicLinker'] = None,
Expand All @@ -433,7 +433,7 @@ def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_

def get_options(self) -> 'MutableKeyedOptionDictType':
key = self.form_compileropt_key('std')
opts = CPPCompiler.get_options(self)
opts = super().get_options()
self.update_options(
opts,
self.create_option(options.UserComboOption,
Expand All @@ -450,17 +450,6 @@ def get_options(self) -> 'MutableKeyedOptionDictType':
'STL debug mode',
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():
self.update_options(
opts,
Expand Down
25 changes: 25 additions & 0 deletions mesonbuild/compilers/mixins/gnu.py
Original file line number Diff line number Diff line change
Expand Up @@ -653,3 +653,28 @@ def get_options(self) -> MutableKeyedOptionDictType:
assert isinstance(std_opt, UserStdOption), 'for mypy'
std_opt.set_versions(stds, gnu=True)
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

0 comments on commit 42c0747

Please sign in to comment.