summaryrefslogtreecommitdiff
path: root/mesonbuild/compilers
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2024-09-06 09:15:33 -0700
committerDylan Baker <dylan@pnwbakers.com>2025-01-27 09:37:27 -0800
commit82fbf07a44204cd84fd9341450b10e471cf18a39 (patch)
tree60093857487e4532424ae0959bda887d745d90ef /mesonbuild/compilers
parent1d2627ddbfe2972ae5676f60a30f4d4fde7f4e04 (diff)
downloadmeson-82fbf07a44204cd84fd9341450b10e471cf18a39.tar.gz
compilers/clang: Move the Mixin for C standards out of the c module
We'll want to use this for ObjC as well, so we'll make it public and put it in a public place.
Diffstat (limited to 'mesonbuild/compilers')
-rw-r--r--mesonbuild/compilers/c.py42
-rw-r--r--mesonbuild/compilers/mixins/clang.py43
2 files changed, 46 insertions, 39 deletions
diff --git a/mesonbuild/compilers/c.py b/mesonbuild/compilers/c.py
index 0a05b387b..33f313ed9 100644
--- a/mesonbuild/compilers/c.py
+++ b/mesonbuild/compilers/c.py
@@ -21,7 +21,7 @@ from .mixins.visualstudio import MSVCCompiler, ClangClCompiler
from .mixins.gnu import GnuCompiler
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
@@ -103,43 +103,7 @@ class CCompiler(CLikeCompiler, Compiler):
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',
@@ -523,7 +487,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/mixins/clang.py b/mesonbuild/compilers/mixins/clang.py
index 82df325ec..3d3325416 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,39 @@ 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