diff options
| -rw-r--r-- | mesonbuild/compilers/cpp.py | 19 | ||||
| -rw-r--r-- | mesonbuild/compilers/mixins/clang.py | 27 |
2 files changed, 30 insertions, 16 deletions
diff --git a/mesonbuild/compilers/cpp.py b/mesonbuild/compilers/cpp.py index d2eca897b..31a1c93e0 100644 --- a/mesonbuild/compilers/cpp.py +++ b/mesonbuild/compilers/cpp.py @@ -27,7 +27,7 @@ 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.intel import IntelGnuLikeCompiler, IntelVisualStudioLikeCompiler -from .mixins.clang import ClangCompiler +from .mixins.clang import ClangCompiler, ClangCPPStds from .mixins.elbrus import ElbrusCompiler from .mixins.pgi import PGICompiler from .mixins.emscripten import EmscriptenMixin @@ -218,10 +218,7 @@ class _StdCPPLibMixin(CompilerMixinBase): raise MesonException('Could not detect either libc++ or libstdc++ as your C++ stdlib implementation.') -class ClangCPPCompiler(_StdCPPLibMixin, ClangCompiler, CPPCompiler): - - _CPP23_VERSION = '>=12.0.0' - _CPP26_VERSION = '>=17.0.0' +class ClangCPPCompiler(_StdCPPLibMixin, ClangCPPStds, ClangCompiler, CPPCompiler): def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool, info: 'MachineInfo', @@ -239,7 +236,7 @@ class ClangCPPCompiler(_StdCPPLibMixin, ClangCompiler, CPPCompiler): 'everything': ['-Weverything']} def get_options(self) -> 'MutableKeyedOptionDictType': - opts = CPPCompiler.get_options(self) + opts = super().get_options() self.update_options( opts, self.create_option(options.UserComboOption, @@ -256,16 +253,6 @@ class ClangCPPCompiler(_StdCPPLibMixin, ClangCompiler, 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, self._CPP23_VERSION): - cppstd_choices.append('c++23') - if version_compare(self.version, self._CPP26_VERSION): - cppstd_choices.append('c++26') - std_opt = opts[self.form_compileropt_key('std')] - 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/clang.py b/mesonbuild/compilers/mixins/clang.py index 3d3325416..867b58680 100644 --- a/mesonbuild/compilers/mixins/clang.py +++ b/mesonbuild/compilers/mixins/clang.py @@ -247,3 +247,30 @@ class ClangCStds(CompilerMixinBase): assert isinstance(std_opt, options.UserStdOption), 'for mypy' std_opt.set_versions(stds, gnu=True) return opts + + +class ClangCPPStds(CompilerMixinBase): + + """Mixin class for clang based compilers for setting C++ standards. + + This is used by the ClangCPPCompiler + """ + + _CPP23_VERSION = '>=12.0.0' + _CPP26_VERSION = '>=17.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, options.UserStdOption), 'for mypy' + std_opt.set_versions(stds, gnu=True) + return opts |
