summaryrefslogtreecommitdiff
path: root/mesonbuild/compilers/mixins/gnu.py
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 /mesonbuild/compilers/mixins/gnu.py
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
Diffstat (limited to 'mesonbuild/compilers/mixins/gnu.py')
-rw-r--r--mesonbuild/compilers/mixins/gnu.py30
1 files changed, 29 insertions, 1 deletions
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