From a935eeef5028dfc1999aab40577f97a455c091c7 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Fri, 6 Sep 2024 09:24:43 -0700 Subject: compilers/clang: split the Std handling for C++ out of the ClangCPPCompiler We'll want to use this for the ObjC++ compiler too. --- mesonbuild/compilers/cpp.py | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) (limited to 'mesonbuild/compilers/cpp.py') 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, -- cgit v1.2.3 From b5ff5931b69dedbcee582ecc74bb8e59fb60e068 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Fri, 6 Sep 2024 09:35:11 -0700 Subject: compilers/objcpp: Use shared C++ standards with ClangCPPStandard --- mesonbuild/compilers/cpp.py | 8 ++++---- mesonbuild/compilers/objcpp.py | 38 ++++++++++++++++++++------------------ 2 files changed, 24 insertions(+), 22 deletions(-) (limited to 'mesonbuild/compilers/cpp.py') diff --git a/mesonbuild/compilers/cpp.py b/mesonbuild/compilers/cpp.py index 31a1c93e0..e051050e2 100644 --- a/mesonbuild/compilers/cpp.py +++ b/mesonbuild/compilers/cpp.py @@ -45,9 +45,9 @@ if T.TYPE_CHECKING: else: CompilerMixinBase = object -_ALL_STDS = ['c++98', 'c++0x', 'c++03', 'c++1y', 'c++1z', 'c++11', 'c++14', 'c++17', 'c++2a', 'c++20', 'c++23', 'c++26'] -_ALL_STDS += [f'gnu{std[1:]}' for std in _ALL_STDS] -_ALL_STDS += ['vc++11', 'vc++14', 'vc++17', 'vc++20', 'vc++latest', 'c++latest'] +ALL_STDS = ['c++98', 'c++0x', 'c++03', 'c++1y', 'c++1z', 'c++11', 'c++14', 'c++17', 'c++2a', 'c++20', 'c++23', 'c++26'] +ALL_STDS += [f'gnu{std[1:]}' for std in ALL_STDS] +ALL_STDS += ['vc++11', 'vc++14', 'vc++17', 'vc++20', 'vc++latest', 'c++latest'] def non_msvc_eh_options(eh: str, args: T.List[str]) -> None: @@ -175,7 +175,7 @@ class CPPCompiler(CLikeCompiler, Compiler): opts = super().get_options() key = self.form_compileropt_key('std') opts.update({ - key: options.UserStdOption('C++', _ALL_STDS), + key: options.UserStdOption('C++', ALL_STDS), }) return opts diff --git a/mesonbuild/compilers/objcpp.py b/mesonbuild/compilers/objcpp.py index 973d7bb0c..9fd119690 100644 --- a/mesonbuild/compilers/objcpp.py +++ b/mesonbuild/compilers/objcpp.py @@ -5,13 +5,13 @@ from __future__ import annotations import typing as T -from .. import options -from ..options import OptionKey +from ..options import OptionKey, UserStdOption -from .mixins.clike import CLikeCompiler +from .cpp import ALL_STDS from .compilers import Compiler from .mixins.gnu import GnuCompiler, gnu_common_warning_args, gnu_objc_warning_args -from .mixins.clang import ClangCompiler +from .mixins.clang import ClangCompiler, ClangCPPStds +from .mixins.clike import CLikeCompiler if T.TYPE_CHECKING: from .. import coredata @@ -20,6 +20,7 @@ if T.TYPE_CHECKING: from ..linkers.linkers import DynamicLinker from ..mesonlib import MachineChoice + class ObjCPPCompiler(CLikeCompiler, Compiler): language = 'objcpp' @@ -41,6 +42,19 @@ class ObjCPPCompiler(CLikeCompiler, Compiler): code = '#import\nclass MyClass;int main(void) { return 0; }\n' return self._sanity_check_impl(work_dir, environment, 'sanitycheckobjcpp.mm', code) + def form_compileropt_key(self, basename: str) -> OptionKey: + if basename == 'std': + return OptionKey(f'cpp_{basename}', machine=self.for_machine) + return super().form_compileropt_key(basename) + + def get_options(self) -> coredata.MutableKeyedOptionDictType: + opts = super().get_options() + key = self.form_compileropt_key('std') + opts.update({ + key: UserStdOption('cpp', ALL_STDS), + }) + return opts + class GnuObjCPPCompiler(GnuCompiler, ObjCPPCompiler): def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, @@ -61,7 +75,7 @@ class GnuObjCPPCompiler(GnuCompiler, ObjCPPCompiler): self.supported_warn_args(gnu_objc_warning_args))} -class ClangObjCPPCompiler(ClangCompiler, ObjCPPCompiler): +class ClangObjCPPCompiler(ClangCPPStds, ClangCompiler, ObjCPPCompiler): def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool, info: 'MachineInfo', @@ -78,21 +92,9 @@ class ClangObjCPPCompiler(ClangCompiler, ObjCPPCompiler): '3': default_warn_args + ['-Wextra', '-Wpedantic'], 'everything': ['-Weverything']} - def get_options(self) -> coredata.MutableKeyedOptionDictType: - return self.update_options( - super().get_options(), - self.create_option(options.UserComboOption, - OptionKey('cpp_std', machine=self.for_machine), - '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'), - ) - def get_option_compile_args(self, options: 'coredata.KeyedOptionDictType') -> T.List[str]: args = [] - std = options.get_value(OptionKey('cpp_std', machine=self.for_machine)) + std = options.get_value(self.form_compileropt_key('std')) if std != 'none': args.append('-std=' + std) return args -- cgit v1.2.3 From 4f314baaf638d6a566fa295b8779b4cf3ba6d96f Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Fri, 6 Sep 2024 10:08:49 -0700 Subject: compilers/gnu: Split Gnu C++ standard handling into a mixin class So we can re-use it in the ObjC++ standards --- mesonbuild/compilers/cpp.py | 17 +++-------------- mesonbuild/compilers/mixins/gnu.py | 25 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 14 deletions(-) (limited to 'mesonbuild/compilers/cpp.py') 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 -- cgit v1.2.3 From 19b67fbf29faa3d4a90e05722501be128f6ddbd0 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Wed, 25 Sep 2024 09:45:21 -0700 Subject: compilers: split Apple C++ version handling to a mixin --- mesonbuild/compilers/cpp.py | 8 +++----- mesonbuild/compilers/mixins/apple.py | 8 ++++++++ mesonbuild/compilers/objcpp.py | 3 ++- 3 files changed, 13 insertions(+), 6 deletions(-) (limited to 'mesonbuild/compilers/cpp.py') diff --git a/mesonbuild/compilers/cpp.py b/mesonbuild/compilers/cpp.py index 9626aaceb..46e1ea01b 100644 --- a/mesonbuild/compilers/cpp.py +++ b/mesonbuild/compilers/cpp.py @@ -19,7 +19,7 @@ from .compilers import ( CompileCheckMode, ) from .c_function_attributes import CXX_FUNC_ATTRIBUTES, C_FUNC_ATTRIBUTES -from .mixins.apple import AppleCompilerMixin +from .mixins.apple import AppleCompilerMixin, AppleCPPStdsMixin from .mixins.clike import CLikeCompiler from .mixins.ccrx import CcrxCompiler from .mixins.ti import TICompiler @@ -325,10 +325,8 @@ class ArmLtdClangCPPCompiler(ClangCPPCompiler): id = 'armltdclang' -class AppleClangCPPCompiler(AppleCompilerMixin, ClangCPPCompiler): - - _CPP23_VERSION = '>=13.0.0' - _CPP26_VERSION = '>=16.0.0' +class AppleClangCPPCompiler(AppleCompilerMixin, AppleCPPStdsMixin, ClangCPPCompiler): + pass class EmscriptenCPPCompiler(EmscriptenMixin, ClangCPPCompiler): diff --git a/mesonbuild/compilers/mixins/apple.py b/mesonbuild/compilers/mixins/apple.py index 1056e7749..2a0939334 100644 --- a/mesonbuild/compilers/mixins/apple.py +++ b/mesonbuild/compilers/mixins/apple.py @@ -68,3 +68,11 @@ class AppleCStdsMixin(Compiler): _C17_VERSION = '>=10.0.0' _C18_VERSION = '>=11.0.0' _C2X_VERSION = '>=11.0.0' + + +class AppleCPPStdsMixin(Compiler): + + """Provide version overrides for the Apple C++ Compilers.""" + + _CPP23_VERSION = '>=13.0.0' + _CPP26_VERSION = '>=16.0.0' diff --git a/mesonbuild/compilers/objcpp.py b/mesonbuild/compilers/objcpp.py index c7af84b79..de968be42 100644 --- a/mesonbuild/compilers/objcpp.py +++ b/mesonbuild/compilers/objcpp.py @@ -9,6 +9,7 @@ from ..options import OptionKey, UserStdOption from .cpp import ALL_STDS from .compilers import Compiler +from .mixins.apple import AppleCPPStdsMixin from .mixins.gnu import GnuCompiler, GnuCPPStds, gnu_common_warning_args, gnu_objc_warning_args from .mixins.clang import ClangCompiler, ClangCPPStds from .mixins.clike import CLikeCompiler @@ -107,6 +108,6 @@ class ClangObjCPPCompiler(ClangCPPStds, ClangCompiler, ObjCPPCompiler): return args -class AppleClangObjCPPCompiler(ClangObjCPPCompiler): +class AppleClangObjCPPCompiler(AppleCPPStdsMixin, ClangObjCPPCompiler): """Handle the differences between Apple's clang and vanilla clang.""" -- cgit v1.2.3