diff options
| author | Dylan Baker <dylan@pnwbakers.com> | 2024-09-06 10:08:49 -0700 |
|---|---|---|
| committer | Dylan Baker <dylan@pnwbakers.com> | 2025-01-27 09:38:53 -0800 |
| commit | 4f314baaf638d6a566fa295b8779b4cf3ba6d96f (patch) | |
| tree | fd041e369b4ef7a57cba69370c6000cac357a5a3 /mesonbuild/compilers | |
| parent | 30ca64a25b966c7204325e0338afbbb2c6a64d53 (diff) | |
| download | meson-4f314baaf638d6a566fa295b8779b4cf3ba6d96f.tar.gz | |
compilers/gnu: Split Gnu C++ standard handling into a mixin class
So we can re-use it in the ObjC++ standards
Diffstat (limited to 'mesonbuild/compilers')
| -rw-r--r-- | mesonbuild/compilers/cpp.py | 17 | ||||
| -rw-r--r-- | mesonbuild/compilers/mixins/gnu.py | 25 |
2 files changed, 28 insertions, 14 deletions
diff --git a/mesonbuild/compilers/cpp.py b/mesonbuild/compilers/cpp.py index e051050e2..9626aaceb 100644 --- a/mesonbuild/compilers/cpp.py +++ b/mesonbuild/compilers/cpp.py @@ -25,7 +25,7 @@ from .mixins.ccrx import CcrxCompiler 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 @@ -417,7 +417,7 @@ class ArmclangCPPCompiler(ArmclangCompiler, CPPCompiler): 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, @@ -437,7 +437,7 @@ class GnuCPPCompiler(_StdCPPLibMixin, GnuCompiler, CPPCompiler): 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, @@ -454,17 +454,6 @@ class GnuCPPCompiler(_StdCPPLibMixin, GnuCompiler, CPPCompiler): '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, diff --git a/mesonbuild/compilers/mixins/gnu.py b/mesonbuild/compilers/mixins/gnu.py index 1f78ef89d..4dc344519 100644 --- a/mesonbuild/compilers/mixins/gnu.py +++ b/mesonbuild/compilers/mixins/gnu.py @@ -657,3 +657,28 @@ class GnuCStds(Compiler): 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 |
