summaryrefslogtreecommitdiff
path: root/mesonbuild/compilers
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2025-01-28 23:12:18 +0200
committerGitHub <noreply@github.com>2025-01-28 23:12:18 +0200
commitb55cef0c3bf047591ee9a3e9503c530cf726deab (patch)
treee9771265e2c83ff6d262561f90d18257cf4555ff /mesonbuild/compilers
parent7bcf38de60afd5ef9f8bc52ea67e6cb693c3d8a3 (diff)
parent1eaab0253bea69432d69a1eddab377fbbd9ed74d (diff)
downloadmeson-b55cef0c3bf047591ee9a3e9503c530cf726deab.tar.gz
Merge pull request #13642 from dcbaker/submit/fix-objc-standards
Support lists for ObjC and ObjC++ standards
Diffstat (limited to 'mesonbuild/compilers')
-rw-r--r--mesonbuild/compilers/c.py84
-rw-r--r--mesonbuild/compilers/cpp.py52
-rw-r--r--mesonbuild/compilers/detect.py6
-rw-r--r--mesonbuild/compilers/mixins/apple.py19
-rw-r--r--mesonbuild/compilers/mixins/clang.py70
-rw-r--r--mesonbuild/compilers/mixins/gnu.py55
-rw-r--r--mesonbuild/compilers/objc.py47
-rw-r--r--mesonbuild/compilers/objcpp.py52
8 files changed, 234 insertions, 151 deletions
diff --git a/mesonbuild/compilers/c.py b/mesonbuild/compilers/c.py
index 0a05b387b..8379f81ba 100644
--- a/mesonbuild/compilers/c.py
+++ b/mesonbuild/compilers/c.py
@@ -1,5 +1,6 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright 2012-2020 The Meson development team
+# Copyright © 2024-2025 Intel Corporation
from __future__ import annotations
@@ -10,7 +11,7 @@ from .. import options
from .. import mlog
from ..mesonlib import MesonException, version_compare
from .c_function_attributes import C_FUNC_ATTRIBUTES
-from .mixins.apple import AppleCompilerMixin
+from .mixins.apple import AppleCompilerMixin, AppleCStdsMixin
from .mixins.clike import CLikeCompiler
from .mixins.ccrx import CcrxCompiler
from .mixins.xc16 import Xc16Compiler
@@ -18,10 +19,10 @@ from .mixins.compcert import CompCertCompiler
from .mixins.ti import TICompiler
from .mixins.arm import ArmCompiler, ArmclangCompiler
from .mixins.visualstudio import MSVCCompiler, ClangClCompiler
-from .mixins.gnu import GnuCompiler
+from .mixins.gnu import GnuCompiler, GnuCStds
from .mixins.gnu import gnu_common_warning_args, gnu_c_warning_args
from .mixins.intel import IntelGnuLikeCompiler, IntelVisualStudioLikeCompiler
-from .mixins.clang import ClangCompiler
+from .mixins.clang import ClangCompiler, ClangCStds
from .mixins.elbrus import ElbrusCompiler
from .mixins.pgi import PGICompiler
from .mixins.emscripten import EmscriptenMixin
@@ -47,9 +48,9 @@ if T.TYPE_CHECKING:
else:
CompilerMixinBase = object
-_ALL_STDS = ['c89', 'c9x', 'c90', 'c99', 'c1x', 'c11', 'c17', 'c18', 'c2x', 'c23', 'c2y']
-_ALL_STDS += [f'gnu{std[1:]}' for std in _ALL_STDS]
-_ALL_STDS += ['iso9899:1990', 'iso9899:199409', 'iso9899:1999', 'iso9899:2011', 'iso9899:2017', 'iso9899:2018']
+ALL_STDS = ['c89', 'c9x', 'c90', 'c99', 'c1x', 'c11', 'c17', 'c18', 'c2x', 'c23', 'c2y']
+ALL_STDS += [f'gnu{std[1:]}' for std in ALL_STDS]
+ALL_STDS += ['iso9899:1990', 'iso9899:199409', 'iso9899:1999', 'iso9899:2011', 'iso9899:2017', 'iso9899:2018']
class CCompiler(CLikeCompiler, Compiler):
@@ -98,48 +99,12 @@ class CCompiler(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
-class _ClangCStds(CompilerMixinBase):
-
- """Mixin class for clang based compilers for setting C standards.
-
- This is used by both ClangCCompiler and ClangClCompiler, as they share
- the same versions
- """
-
- _C17_VERSION = '>=6.0.0'
- _C18_VERSION = '>=8.0.0'
- _C2X_VERSION = '>=9.0.0'
- _C23_VERSION = '>=18.0.0'
- _C2Y_VERSION = '>=19.0.0'
-
- def get_options(self) -> 'MutableKeyedOptionDictType':
- opts = super().get_options()
- stds = ['c89', 'c99', 'c11']
- # https://releases.llvm.org/6.0.0/tools/clang/docs/ReleaseNotes.html
- # https://en.wikipedia.org/wiki/Xcode#Latest_versions
- if version_compare(self.version, self._C17_VERSION):
- stds += ['c17']
- if version_compare(self.version, self._C18_VERSION):
- stds += ['c18']
- if version_compare(self.version, self._C2X_VERSION):
- stds += ['c2x']
- if version_compare(self.version, self._C23_VERSION):
- stds += ['c23']
- if version_compare(self.version, self._C2Y_VERSION):
- stds += ['c2y']
- 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
-
-
-class ClangCCompiler(_ClangCStds, ClangCompiler, CCompiler):
+class ClangCCompiler(ClangCStds, ClangCompiler, CCompiler):
def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool,
info: 'MachineInfo',
@@ -192,7 +157,7 @@ class ArmLtdClangCCompiler(ClangCCompiler):
id = 'armltdclang'
-class AppleClangCCompiler(AppleCompilerMixin, ClangCCompiler):
+class AppleClangCCompiler(AppleCompilerMixin, AppleCStdsMixin, ClangCCompiler):
"""Handle the differences between Apple Clang and Vanilla Clang.
@@ -200,10 +165,6 @@ class AppleClangCCompiler(AppleCompilerMixin, ClangCCompiler):
C standards were added.
"""
- _C17_VERSION = '>=10.0.0'
- _C18_VERSION = '>=11.0.0'
- _C2X_VERSION = '>=11.0.0'
-
class EmscriptenCCompiler(EmscriptenMixin, ClangCCompiler):
@@ -272,12 +233,8 @@ class ArmclangCCompiler(ArmclangCompiler, CCompiler):
return []
-class GnuCCompiler(GnuCompiler, CCompiler):
+class GnuCCompiler(GnuCStds, GnuCompiler, CCompiler):
- _C18_VERSION = '>=8.0.0'
- _C2X_VERSION = '>=9.0.0'
- _C23_VERSION = '>=14.0.0'
- _C2Y_VERSION = '>=15.0.0'
_INVALID_PCH_VERSION = ">=3.4.0"
def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool,
@@ -299,25 +256,12 @@ class GnuCCompiler(GnuCompiler, CCompiler):
self.supported_warn_args(gnu_c_warning_args))}
def get_options(self) -> 'MutableKeyedOptionDictType':
- opts = CCompiler.get_options(self)
- stds = ['c89', 'c99', 'c11']
- if version_compare(self.version, self._C18_VERSION):
- stds += ['c17', 'c18']
- if version_compare(self.version, self._C2X_VERSION):
- stds += ['c2x']
- if version_compare(self.version, self._C23_VERSION):
- stds += ['c23']
- if version_compare(self.version, self._C2Y_VERSION):
- stds += ['c2y']
- 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)
+ opts = super().get_options()
if self.info.is_windows() or self.info.is_cygwin():
self.update_options(
opts,
self.create_option(options.UserArrayOption,
- key.evolve('c_winlibs'),
+ self.form_compileropt_key('winlibs'),
'Standard Windows libs to link against',
gnu_winlibs),
)
@@ -523,7 +467,7 @@ class VisualStudioCCompiler(MSVCCompiler, VisualStudioLikeCCompilerMixin, CCompi
return args
-class ClangClCCompiler(_ClangCStds, ClangClCompiler, VisualStudioLikeCCompilerMixin, CCompiler):
+class ClangClCCompiler(ClangCStds, ClangClCompiler, VisualStudioLikeCCompilerMixin, CCompiler):
def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice,
is_cross: bool, info: 'MachineInfo', target: str,
linker: T.Optional['DynamicLinker'] = None,
diff --git a/mesonbuild/compilers/cpp.py b/mesonbuild/compilers/cpp.py
index 73877a9b2..37d82c395 100644
--- a/mesonbuild/compilers/cpp.py
+++ b/mesonbuild/compilers/cpp.py
@@ -19,15 +19,15 @@ 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
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
+from .mixins.clang import ClangCompiler, ClangCPPStds
from .mixins.elbrus import ElbrusCompiler
from .mixins.pgi import PGICompiler
from .mixins.emscripten import EmscriptenMixin
@@ -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
@@ -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,
@@ -344,10 +331,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):
@@ -436,7 +421,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,
@@ -456,7 +441,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,
@@ -473,17 +458,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/detect.py b/mesonbuild/compilers/detect.py
index 7bd48d10c..d4ad4bade 100644
--- a/mesonbuild/compilers/detect.py
+++ b/mesonbuild/compilers/detect.py
@@ -897,9 +897,13 @@ def _detect_objc_or_objcpp_compiler(env: 'Environment', lang: str, for_machine:
version = _get_gnu_version_from_defines(defines)
comp = objc.GnuObjCCompiler if lang == 'objc' else objcpp.GnuObjCPPCompiler
linker = guess_nix_linker(env, compiler, comp, version, for_machine)
- return comp(
+ c = comp(
ccache, compiler, version, for_machine, is_cross, info,
defines, linker=linker)
+ if not c.compiles('int main(void) { return 0; }', env)[0]:
+ popen_exceptions[join_args(compiler)] = f'GCC was not built with support for {"objective-c" if lang == "objc" else "objective-c++"}'
+ continue
+ return c
if 'clang' in out:
linker = None
defines = _get_clang_compiler_defines(compiler, lang)
diff --git a/mesonbuild/compilers/mixins/apple.py b/mesonbuild/compilers/mixins/apple.py
index 6ec923952..2a0939334 100644
--- a/mesonbuild/compilers/mixins/apple.py
+++ b/mesonbuild/compilers/mixins/apple.py
@@ -1,5 +1,5 @@
# SPDX-License-Identifier: Apache-2.0
-# Copyright © 2024 Intel Corporation
+# Copyright © 2024-2025 Intel Corporation
"""Provides mixins for Apple compilers."""
@@ -59,3 +59,20 @@ class AppleCompilerMixin(Compiler):
def get_prelink_args(self, prelink_name: str, obj_list: T.List[str]) -> T.Tuple[T.List[str], T.List[str]]:
# The objects are prelinked through the compiler, which injects -lSystem
return [prelink_name], ['-nostdlib', '-r', '-o', prelink_name] + obj_list
+
+
+class AppleCStdsMixin(Compiler):
+
+ """Provide version overrides for the Apple Compilers."""
+
+ _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/mixins/clang.py b/mesonbuild/compilers/mixins/clang.py
index 82df325ec..867b58680 100644
--- a/mesonbuild/compilers/mixins/clang.py
+++ b/mesonbuild/compilers/mixins/clang.py
@@ -10,6 +10,7 @@ import shutil
import typing as T
from ... import mesonlib
+from ... import options
from ...linkers.linkers import AppleDynamicLinker, ClangClDynamicLinker, LLVMDynamicLinker, GnuGoldDynamicLinker, \
MoldDynamicLinker, MSVCDynamicLinker
from ...options import OptionKey
@@ -17,8 +18,14 @@ from ..compilers import CompileCheckMode
from .gnu import GnuLikeCompiler
if T.TYPE_CHECKING:
+ from ...coredata import MutableKeyedOptionDictType
from ...environment import Environment
from ...dependencies import Dependency # noqa: F401
+ from ..compilers import Compiler
+
+ CompilerMixinBase = Compiler
+else:
+ CompilerMixinBase = object
clang_color_args: T.Dict[str, T.List[str]] = {
'auto': ['-fdiagnostics-color=auto'],
@@ -204,3 +211,66 @@ class ClangCompiler(GnuLikeCompiler):
raise mesonlib.MesonException('clang support for LTO threads requires clang >=4.0')
args.append(f'-flto-jobs={threads}')
return args
+
+
+class ClangCStds(CompilerMixinBase):
+
+ """Mixin class for clang based compilers for setting C standards.
+
+ This is used by both ClangCCompiler and ClangClCompiler, as they share
+ the same versions
+ """
+
+ _C17_VERSION = '>=6.0.0'
+ _C18_VERSION = '>=8.0.0'
+ _C2X_VERSION = '>=9.0.0'
+ _C23_VERSION = '>=18.0.0'
+ _C2Y_VERSION = '>=19.0.0'
+
+ def get_options(self) -> MutableKeyedOptionDictType:
+ opts = super().get_options()
+ stds = ['c89', 'c99', 'c11']
+ # https://releases.llvm.org/6.0.0/tools/clang/docs/ReleaseNotes.html
+ # https://en.wikipedia.org/wiki/Xcode#Latest_versions
+ if mesonlib.version_compare(self.version, self._C17_VERSION):
+ stds += ['c17']
+ if mesonlib.version_compare(self.version, self._C18_VERSION):
+ stds += ['c18']
+ if mesonlib.version_compare(self.version, self._C2X_VERSION):
+ stds += ['c2x']
+ if mesonlib.version_compare(self.version, self._C23_VERSION):
+ stds += ['c23']
+ if mesonlib.version_compare(self.version, self._C2Y_VERSION):
+ stds += ['c2y']
+ 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
+
+
+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
diff --git a/mesonbuild/compilers/mixins/gnu.py b/mesonbuild/compilers/mixins/gnu.py
index b974474fa..4dc344519 100644
--- a/mesonbuild/compilers/mixins/gnu.py
+++ b/mesonbuild/compilers/mixins/gnu.py
@@ -15,11 +15,12 @@ import typing as T
from ... import mesonlib
from ... import mlog
-from ...options import OptionKey
+from ...options import OptionKey, UserStdOption
from mesonbuild.compilers.compilers import CompileCheckMode
if T.TYPE_CHECKING:
from ..._typing import ImmutableListProtocol
+ from ...coredata import MutableKeyedOptionDictType
from ...environment import Environment
from ..compilers import Compiler
else:
@@ -629,3 +630,55 @@ class GnuCompiler(GnuLikeCompiler):
def get_profile_use_args(self) -> T.List[str]:
return super().get_profile_use_args() + ['-fprofile-correction']
+
+
+class GnuCStds(Compiler):
+
+ """Mixin class for gcc based compilers for setting C standards."""
+
+ _C18_VERSION = '>=8.0.0'
+ _C2X_VERSION = '>=9.0.0'
+ _C23_VERSION = '>=14.0.0'
+ _C2Y_VERSION = '>=15.0.0'
+
+ def get_options(self) -> MutableKeyedOptionDictType:
+ opts = super().get_options()
+ stds = ['c89', 'c99', 'c11']
+ if mesonlib.version_compare(self.version, self._C18_VERSION):
+ stds += ['c17', 'c18']
+ if mesonlib.version_compare(self.version, self._C2X_VERSION):
+ stds += ['c2x']
+ if mesonlib.version_compare(self.version, self._C23_VERSION):
+ stds += ['c23']
+ if mesonlib.version_compare(self.version, self._C2Y_VERSION):
+ stds += ['c2y']
+ 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
+
+
+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
diff --git a/mesonbuild/compilers/objc.py b/mesonbuild/compilers/objc.py
index 97550c2ea..56bc12d45 100644
--- a/mesonbuild/compilers/objc.py
+++ b/mesonbuild/compilers/objc.py
@@ -5,13 +5,14 @@ from __future__ import annotations
import typing as T
-from .. import options
-from ..options import OptionKey
+from ..options import OptionKey, UserStdOption
+from .c import ALL_STDS
from .compilers import Compiler
+from .mixins.apple import AppleCStdsMixin
+from .mixins.clang import ClangCompiler, ClangCStds
from .mixins.clike import CLikeCompiler
-from .mixins.gnu import GnuCompiler, gnu_common_warning_args, gnu_objc_warning_args
-from .mixins.clang import ClangCompiler
+from .mixins.gnu import GnuCompiler, GnuCStds, gnu_common_warning_args, gnu_objc_warning_args
if T.TYPE_CHECKING:
from .. import coredata
@@ -34,6 +35,14 @@ class ObjCCompiler(CLikeCompiler, Compiler):
linker=linker)
CLikeCompiler.__init__(self)
+ def get_options(self) -> coredata.MutableKeyedOptionDictType:
+ opts = super().get_options()
+ key = self.form_compileropt_key('std')
+ opts.update({
+ key: UserStdOption('c', ALL_STDS),
+ })
+ return opts
+
@staticmethod
def get_display_language() -> str:
return 'Objective-C'
@@ -42,8 +51,13 @@ class ObjCCompiler(CLikeCompiler, Compiler):
code = '#import<stddef.h>\nint main(void) { return 0; }\n'
return self._sanity_check_impl(work_dir, environment, 'sanitycheckobjc.m', code)
+ def form_compileropt_key(self, basename: str) -> OptionKey:
+ if basename == 'std':
+ return OptionKey(f'c_{basename}', machine=self.for_machine)
+ return super().form_compileropt_key(basename)
+
-class GnuObjCCompiler(GnuCompiler, ObjCCompiler):
+class GnuObjCCompiler(GnuCStds, GnuCompiler, ObjCCompiler):
def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice,
is_cross: bool, info: 'MachineInfo',
defines: T.Optional[T.Dict[str, str]] = None,
@@ -61,8 +75,15 @@ class GnuObjCCompiler(GnuCompiler, ObjCCompiler):
self.supported_warn_args(gnu_common_warning_args) +
self.supported_warn_args(gnu_objc_warning_args))}
+ def get_option_compile_args(self, options: 'coredata.KeyedOptionDictType') -> T.List[str]:
+ args = []
+ std = options.get_value(self.form_compileropt_key('std'))
+ if std != 'none':
+ args.append('-std=' + std)
+ return args
-class ClangObjCCompiler(ClangCompiler, ObjCCompiler):
+
+class ClangObjCCompiler(ClangCStds, ClangCompiler, ObjCCompiler):
def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice,
is_cross: bool, info: 'MachineInfo',
defines: T.Optional[T.Dict[str, str]] = None,
@@ -78,23 +99,13 @@ class ClangObjCCompiler(ClangCompiler, ObjCCompiler):
'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('c_std', machine=self.for_machine),
- 'C language standard to use',
- ['none', 'c89', 'c99', 'c11', 'c17', 'gnu89', 'gnu99', 'gnu11', 'gnu17'],
- 'none'),
- )
-
def get_option_compile_args(self, options: 'coredata.KeyedOptionDictType') -> T.List[str]:
args = []
- std = options.get_value(OptionKey('c_std', machine=self.for_machine))
+ std = options.get_value(self.form_compileropt_key('std'))
if std != 'none':
args.append('-std=' + std)
return args
-class AppleClangObjCCompiler(ClangObjCCompiler):
+class AppleClangObjCCompiler(AppleCStdsMixin, ClangObjCCompiler):
"""Handle the differences between Apple's clang and vanilla clang."""
diff --git a/mesonbuild/compilers/objcpp.py b/mesonbuild/compilers/objcpp.py
index 973d7bb0c..de968be42 100644
--- a/mesonbuild/compilers/objcpp.py
+++ b/mesonbuild/compilers/objcpp.py
@@ -5,13 +5,14 @@ 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.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
if T.TYPE_CHECKING:
from .. import coredata
@@ -20,6 +21,7 @@ if T.TYPE_CHECKING:
from ..linkers.linkers import DynamicLinker
from ..mesonlib import MachineChoice
+
class ObjCPPCompiler(CLikeCompiler, Compiler):
language = 'objcpp'
@@ -41,8 +43,21 @@ class ObjCPPCompiler(CLikeCompiler, Compiler):
code = '#import<stdio.h>\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)
-class GnuObjCPPCompiler(GnuCompiler, ObjCPPCompiler):
+ 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(GnuCPPStds, GnuCompiler, ObjCPPCompiler):
def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice,
is_cross: bool, info: 'MachineInfo',
defines: T.Optional[T.Dict[str, str]] = None,
@@ -60,8 +75,15 @@ class GnuObjCPPCompiler(GnuCompiler, ObjCPPCompiler):
self.supported_warn_args(gnu_common_warning_args) +
self.supported_warn_args(gnu_objc_warning_args))}
+ def get_option_compile_args(self, options: 'coredata.KeyedOptionDictType') -> T.List[str]:
+ args = []
+ std = options.get_value(self.form_compileropt_key('std'))
+ if std != 'none':
+ args.append('-std=' + std)
+ return 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,26 +100,14 @@ 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
-class AppleClangObjCPPCompiler(ClangObjCPPCompiler):
+class AppleClangObjCPPCompiler(AppleCPPStdsMixin, ClangObjCPPCompiler):
"""Handle the differences between Apple's clang and vanilla clang."""