summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2024-09-06 10:02:45 -0700
committerDylan Baker <dylan@pnwbakers.com>2025-01-27 09:38:51 -0800
commitc7036e4cae4508a73ebc2b923d50d53968de38a4 (patch)
tree4edf05808a6a0921e478a305ba2f114e378d7e5a
parentb5ff5931b69dedbcee582ecc74bb8e59fb60e068 (diff)
downloadmeson-c7036e4cae4508a73ebc2b923d50d53968de38a4.tar.gz
compilers/gnu: Pull C Standard handling out of GnuCCompiler
So we can re-use it for the ObjC code
-rw-r--r--mesonbuild/compilers/c.py25
-rw-r--r--mesonbuild/compilers/mixins/gnu.py30
2 files changed, 33 insertions, 22 deletions
diff --git a/mesonbuild/compilers/c.py b/mesonbuild/compilers/c.py
index 0cc980e42..70f4dc70e 100644
--- a/mesonbuild/compilers/c.py
+++ b/mesonbuild/compilers/c.py
@@ -19,7 +19,7 @@ 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, ClangCStds
@@ -237,12 +237,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,
@@ -264,25 +260,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),
)
diff --git a/mesonbuild/compilers/mixins/gnu.py b/mesonbuild/compilers/mixins/gnu.py
index b974474fa..1f78ef89d 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,30 @@ 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