Merge pull request #7866 from dcbaker/submit/compiler-std-in-base

Put the Compiler standard option in the Language mixin
pull/7979/head
Jussi Pakkanen 4 years ago committed by GitHub
commit 91876b4031
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 174
      mesonbuild/compilers/c.py
  2. 74
      mesonbuild/compilers/cpp.py
  3. 8
      mesonbuild/compilers/cuda.py
  4. 37
      mesonbuild/compilers/fortran.py

@ -1,4 +1,4 @@
# Copyright 2012-2017 The Meson development team
# Copyright 2012-2020 The Meson development team
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@ -95,28 +95,32 @@ class CCompiler(CLikeCompiler, Compiler):
return self.compiles(t.format(**fargs), env, extra_args=extra_args,
dependencies=dependencies)
def get_options(self) -> 'OptionDictType':
opts = super().get_options()
opts.update({
'std': coredata.UserComboOption(
'C langauge standard to use',
['none'],
'none',
)
})
return opts
class _ClangCStds(CompilerMixinBase):
class ClangCCompiler(ClangCompiler, CCompiler):
"""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'
def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool,
info: 'MachineInfo', exe_wrapper: T.Optional['ExternalProgram'] = None,
linker: T.Optional['DynamicLinker'] = None,
defines: T.Optional[T.Dict[str, str]] = None,
full_version: T.Optional[str] = None):
CCompiler.__init__(self, exelist, version, for_machine, is_cross, info, exe_wrapper, linker=linker, full_version=full_version)
ClangCompiler.__init__(self, defines)
default_warn_args = ['-Wall', '-Winvalid-pch']
self.warn_args = {'0': [],
'1': default_warn_args,
'2': default_warn_args + ['-Wextra'],
'3': default_warn_args + ['-Wextra', '-Wpedantic']}
def get_options(self) -> 'OptionDictType':
opts = CCompiler.get_options(self)
opts = super().get_options()
c_stds = ['c89', 'c99', 'c11']
g_stds = ['gnu89', 'gnu99', 'gnu11']
# https://releases.llvm.org/6.0.0/tools/clang/docs/ReleaseNotes.html
@ -130,13 +134,27 @@ class ClangCCompiler(ClangCompiler, CCompiler):
if version_compare(self.version, self._C2X_VERSION):
c_stds += ['c2x']
g_stds += ['gnu2x']
opts.update({
'std': coredata.UserComboOption(
'C language standard to use',
['none'] + c_stds + g_stds,
'none',
),
})
opts['std'].choices = ['none'] + c_stds + g_stds # type: ignore
return opts
class ClangCCompiler(_ClangCStds, ClangCompiler, CCompiler):
def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool,
info: 'MachineInfo', exe_wrapper: T.Optional['ExternalProgram'] = None,
linker: T.Optional['DynamicLinker'] = None,
defines: T.Optional[T.Dict[str, str]] = None,
full_version: T.Optional[str] = None):
CCompiler.__init__(self, exelist, version, for_machine, is_cross, info, exe_wrapper, linker=linker, full_version=full_version)
ClangCompiler.__init__(self, defines)
default_warn_args = ['-Wall', '-Winvalid-pch']
self.warn_args = {'0': [],
'1': default_warn_args,
'2': default_warn_args + ['-Wextra'],
'3': default_warn_args + ['-Wextra', '-Wpedantic']}
def get_options(self) -> 'OptionDictType':
opts = super().get_options()
if self.info.is_windows() or self.info.is_cygwin():
opts.update({
'winlibs': coredata.UserArrayOption(
@ -207,13 +225,7 @@ class ArmclangCCompiler(ArmclangCompiler, CCompiler):
def get_options(self) -> 'OptionDictType':
opts = CCompiler.get_options(self)
opts.update({
'std': coredata.UserComboOption(
'C language standard to use',
['none', 'c90', 'c99', 'c11', 'gnu90', 'gnu99', 'gnu11'],
'none',
),
})
opts['std'].choices = ['none', 'c90', 'c99', 'c11', 'gnu90', 'gnu99', 'gnu11'] # type: ignore
return opts
def get_option_compile_args(self, options: 'OptionDictType') -> T.List[str]:
@ -255,13 +267,7 @@ class GnuCCompiler(GnuCompiler, CCompiler):
if version_compare(self.version, self._C2X_VERSION):
c_stds += ['c2x']
g_stds += ['gnu2x']
opts.update({
'std': coredata.UserComboOption(
'C language standard to use',
['none'] + c_stds + g_stds,
'none',
),
})
opts['std'].choices = ['none'] + c_stds + g_stds # type: ignore
if self.info.is_windows() or self.info.is_cygwin():
opts.update({
'winlibs': coredata.UserArrayOption(
@ -327,17 +333,11 @@ class ElbrusCCompiler(GnuCCompiler, ElbrusCompiler):
# It does support some various ISO standards and c/gnu 90, 9x, 1x in addition to those which GNU CC supports.
def get_options(self) -> 'OptionDictType':
opts = CCompiler.get_options(self)
opts.update({
'std': coredata.UserComboOption(
'C language standard to use',
[
'none', 'c89', 'c90', 'c9x', 'c99', 'c1x', 'c11',
'gnu89', 'gnu90', 'gnu9x', 'gnu99', 'gnu1x', 'gnu11',
'iso9899:2011', 'iso9899:1990', 'iso9899:199409', 'iso9899:1999',
],
'none',
),
})
opts['std'].choices = [ # type: ignore
'none', 'c89', 'c90', 'c9x', 'c99', 'c1x', 'c11',
'gnu89', 'gnu90', 'gnu9x', 'gnu99', 'gnu1x', 'gnu11',
'iso9899:2011', 'iso9899:1990', 'iso9899:199409', 'iso9899:1999',
]
return opts
# Elbrus C compiler does not have lchmod, but there is only linker warning, not compiler error.
@ -374,13 +374,7 @@ class IntelCCompiler(IntelGnuLikeCompiler, CCompiler):
g_stds = ['gnu89', 'gnu99']
if version_compare(self.version, '>=16.0.0'):
c_stds += ['c11']
opts.update({
'std': coredata.UserComboOption(
'C language standard to use',
['none'] + c_stds + g_stds,
'none',
),
})
opts['std'].choices = ['none'] + c_stds + g_stds # type: ignore
return opts
def get_option_compile_args(self, options: 'OptionDictType') -> T.List[str]:
@ -428,26 +422,29 @@ class VisualStudioCCompiler(MSVCCompiler, VisualStudioLikeCCompilerMixin, CCompi
def get_options(self) -> 'OptionDictType':
opts = super().get_options()
c_stds = ['none', 'c89', 'c99', 'c11']
opts.update({
'std': coredata.UserComboOption(
'C language standard to use',
c_stds,
'none',
),
})
c_stds = ['none', 'c89', 'c99', 'c11',
# Need to have these to be compatible with projects
# that set c_std to e.g. gnu99.
# https://github.com/mesonbuild/meson/issues/7611
'gnu89', 'gnu90', 'gnu9x', 'gnu99', 'gnu1x', 'gnu11']
opts['std'].choices = c_stds # type: ignore
return opts
def get_option_compile_args(self, options: 'OptionDictType') -> T.List[str]:
args = []
std = options['std']
if std.value.startswith('gnu'):
mlog.log(
'cl.exe does not actually support gnu standards, and meson '
'will instead demote to the nearest ISO C standard. This '
'may cause compilation to fail.', once=True)
# As of MVSC 16.7, /std:c11 is the only valid C standard option.
if std.value in {'c11'}:
args.append('/std:' + std.value)
if std.value in {'c11', 'gnu11'}:
args.append('/std:c11')
return args
class ClangClCCompiler(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,
exe_wrapper: T.Optional['ExternalProgram'] = None,
@ -458,6 +455,12 @@ class ClangClCCompiler(ClangClCompiler, VisualStudioLikeCCompilerMixin, CCompile
full_version=full_version)
ClangClCompiler.__init__(self, target)
def get_option_compile_args(self, options: 'OptionDictType') -> T.List[str]:
std = options['std'].value
if std != "none":
return ['/clang:-std={}'.format(std)]
return []
class IntelClCCompiler(IntelVisualStudioLikeCompiler, VisualStudioLikeCCompilerMixin, CCompiler):
@ -475,21 +478,14 @@ class IntelClCCompiler(IntelVisualStudioLikeCompiler, VisualStudioLikeCCompilerM
def get_options(self) -> 'OptionDictType':
opts = super().get_options()
c_stds = ['none', 'c89', 'c99', 'c11']
opts.update({
'std': coredata.UserComboOption(
'C language standard to use',
c_stds,
'none',
),
})
opts['std'].choices = ['none', 'c89', 'c99', 'c11'] # type: ignore
return opts
def get_option_compile_args(self, options: 'OptionDictType') -> T.List[str]:
args = []
std = options['std']
if std.value == 'c89':
mlog.warning("ICL doesn't explicitly implement c89, setting the standard to 'none', which is close.", once=True)
mlog.log("ICL doesn't explicitly implement c89, setting the standard to 'none', which is close.", once=True)
elif std.value != 'none':
args.append('/Qstd:' + std.value)
return args
@ -508,13 +504,7 @@ class ArmCCompiler(ArmCompiler, CCompiler):
def get_options(self) -> 'OptionDictType':
opts = CCompiler.get_options(self)
opts.update({
'std': coredata.UserComboOption(
'C language standard to use',
['none', 'c90', 'c99'],
'none',
),
})
opts['std'].choices = ['none', 'c89', 'c99', 'c11'] # type: ignore
return opts
def get_option_compile_args(self, options: 'OptionDictType') -> T.List[str]:
@ -541,13 +531,7 @@ class CcrxCCompiler(CcrxCompiler, CCompiler):
def get_options(self) -> 'OptionDictType':
opts = CCompiler.get_options(self)
opts.update({
'std': coredata.UserComboOption(
'C language standard to use',
['none', 'c89', 'c99'],
'none',
),
})
opts['std'].choices = ['none', 'c89', 'c99'] # type: ignore
return opts
def get_no_stdinc_args(self) -> T.List[str]:
@ -592,9 +576,7 @@ class Xc16CCompiler(Xc16Compiler, CCompiler):
def get_options(self) -> 'OptionDictType':
opts = CCompiler.get_options(self)
opts.update({'c_std': coredata.UserComboOption('C language standard to use',
['none', 'c89', 'c99', 'gnu89', 'gnu99'],
'none')})
opts['std'].choices = ['none', 'c89', 'c99', 'gnu89', 'gnu99'] # type: ignore
return opts
def get_no_stdinc_args(self) -> T.List[str]:
@ -637,9 +619,7 @@ class CompCertCCompiler(CompCertCompiler, CCompiler):
def get_options(self) -> 'OptionDictType':
opts = CCompiler.get_options(self)
opts.update({'c_std': coredata.UserComboOption('C language standard to use',
['none', 'c89', 'c99'],
'none')})
opts['std'].choices = ['none', 'c89', 'c99'] # type: ignore
return opts
def get_option_compile_args(self, options: 'OptionDictType') -> T.List[str]:
@ -675,9 +655,7 @@ class C2000CCompiler(C2000Compiler, CCompiler):
def get_options(self) -> 'OptionDictType':
opts = CCompiler.get_options(self)
opts.update({'c_std': coredata.UserComboOption('C language standard to use',
['none', 'c89', 'c99', 'c11'],
'none')})
opts['std'].choices = ['none', 'c89', 'c99', 'c11'] # type: ignore
return opts
def get_no_stdinc_args(self) -> T.List[str]:

@ -167,6 +167,17 @@ class CPPCompiler(CLikeCompiler, Compiler):
raise MesonException('C++ Compiler does not support -std={}'.format(cpp_std))
def get_options(self) -> 'OptionDictType':
opts = super().get_options()
opts.update({
'std': coredata.UserComboOption(
'C++ language standard to use',
['none'],
'none',
),
})
return opts
class ClangCPPCompiler(ClangCompiler, CPPCompiler):
def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool,
@ -192,13 +203,11 @@ class ClangCPPCompiler(ClangCompiler, CPPCompiler):
'default',
),
'rtti': coredata.UserBooleanOption('Enable RTTI', True),
'std': coredata.UserComboOption(
'C++ language standard to use',
['none', 'c++98', 'c++03', 'c++11', 'c++14', 'c++17', 'c++1z', 'c++2a',
'gnu++11', 'gnu++14', 'gnu++17', 'gnu++1z', 'gnu++2a'],
'none',
),
})
opts['std'].choices = [ # type: ignore
'none', 'c++98', 'c++03', 'c++11', 'c++14', 'c++17', 'c++1z',
'c++2a', 'gnu++11', 'gnu++14', 'gnu++17', 'gnu++1z', 'gnu++2a',
]
if self.info.is_windows() or self.info.is_cygwin():
opts.update({
'winlibs': coredata.UserArrayOption(
@ -283,15 +292,11 @@ class ArmclangCPPCompiler(ArmclangCompiler, CPPCompiler):
['none', 'default', 'a', 's', 'sc'],
'default',
),
'std': coredata.UserComboOption(
'C++ language standard to use',
[
'none', 'c++98', 'c++03', 'c++11', 'c++14', 'c++17',
'gnu++98', 'gnu++03', 'gnu++11', 'gnu++14', 'gnu++17',
],
'none',
),
})
opts['std'].choices = [ # type: ignore
'none', 'c++98', 'c++03', 'c++11', 'c++14', 'c++17', 'gnu++98',
'gnu++03', 'gnu++11', 'gnu++14', 'gnu++17',
]
return opts
def get_option_compile_args(self, options: 'OptionDictType') -> T.List[str]:
@ -332,17 +337,16 @@ class GnuCPPCompiler(GnuCompiler, CPPCompiler):
'default',
),
'rtti': coredata.UserBooleanOption('Enable RTTI', True),
'std': coredata.UserComboOption(
'C++ language standard to use',
['none', 'c++98', 'c++03', 'c++11', 'c++14', 'c++17', 'c++1z', 'c++2a',
'gnu++03', 'gnu++11', 'gnu++14', 'gnu++17', 'gnu++1z', 'gnu++2a'],
'none',
),
'debugstl': coredata.UserBooleanOption(
'STL debug mode',
False,
)
})
opts['std'].choices = [ # type: ignore
'none', 'c++98', 'c++03', 'c++11', 'c++14', 'c++17', 'c++1z',
'c++2a', 'gnu++03', 'gnu++11', 'gnu++14', 'gnu++17', 'gnu++1z',
'gnu++2a',
]
if self.info.is_windows() or self.info.is_cygwin():
opts.update({
'winlibs': coredata.UserArrayOption(
@ -437,16 +441,12 @@ class ElbrusCPPCompiler(GnuCPPCompiler, ElbrusCompiler):
['none', 'default', 'a', 's', 'sc'],
'default',
),
'std': coredata.UserComboOption(
'C++ language standard to use',
cpp_stds,
'none',
),
'debugstl': coredata.UserBooleanOption(
'STL debug mode',
False,
),
})
opts['std'].choices = cpp_stds # type: ignore
return opts
# Elbrus C++ compiler does not have lchmod, but there is only linker warning, not compiler error.
@ -515,13 +515,9 @@ class IntelCPPCompiler(IntelGnuLikeCompiler, CPPCompiler):
'default',
),
'rtti': coredata.UserBooleanOption('Enable RTTI', True),
'std': coredata.UserComboOption(
'C++ language standard to use',
['none'] + c_stds + g_stds,
'none',
),
'debugstl': coredata.UserBooleanOption('STL debug mode', False),
})
opts['std'].choices = ['none'] + c_stds + g_stds # type: ignore
return opts
def get_option_compile_args(self, options: 'OptionDictType') -> T.List[str]:
@ -573,16 +569,12 @@ class VisualStudioLikeCPPCompilerMixin(CompilerMixinBase):
'default',
),
'rtti': coredata.UserBooleanOption('Enable RTTI', True),
'std': coredata.UserComboOption(
'C++ language standard to use',
cpp_stds,
'none',
),
'winlibs': coredata.UserArrayOption(
'Windows libs to link against.',
msvc_winlibs,
),
})
opts['std'].choices = cpp_stds # type: ignore
return opts
def get_option_compile_args(self, options: 'OptionDictType') -> T.List[str]:
@ -726,13 +718,7 @@ class ArmCPPCompiler(ArmCompiler, CPPCompiler):
def get_options(self) -> 'OptionDictType':
opts = CPPCompiler.get_options(self)
opts.update({
'std': coredata.UserComboOption(
'C++ language standard to use',
['none', 'c++03', 'c++11'],
'none',
),
})
opts['std'].choices = ['none', 'c++03', 'c++11'] # type: ignore
return opts
def get_option_compile_args(self, options: 'OptionDictType') -> T.List[str]:
@ -790,9 +776,7 @@ class C2000CPPCompiler(C2000Compiler, CPPCompiler):
def get_options(self) -> 'OptionDictType':
opts = CPPCompiler.get_options(self)
opts.update({'cpp_std': coredata.UserComboOption('C++ language standard to use',
['none', 'c++03'],
'none')})
opts['std'].choices = ['none', 'c++03'] # type: ignore
return opts
def get_always_args(self) -> T.List[str]:

@ -197,9 +197,9 @@ class CudaCompiler(Compiler):
def get_options(self) -> 'OptionDictType':
opts = super().get_options()
opts.update({'cuda_std': coredata.UserComboOption('C++ language standard to use',
['none', 'c++03', 'c++11', 'c++14'],
'none')})
opts.update({'std': coredata.UserComboOption('C++ language standard to use with cuda',
['none', 'c++03', 'c++11', 'c++14'],
'none')})
return opts
def _to_host_compiler_options(self, options: 'OptionDictType') -> 'OptionDictType':
@ -212,7 +212,7 @@ class CudaCompiler(Compiler):
# the combination of CUDA version and MSVC version; the --std= is thus ignored
# and attempting to use it will result in a warning: https://stackoverflow.com/a/51272091/741027
if not is_windows():
std = options['cuda_std']
std = options['std']
if std.value != 'none':
args.append('--std=' + std.value)

@ -150,6 +150,17 @@ class FortranCompiler(CLikeCompiler, Compiler):
def has_multi_link_arguments(self, args: T.List[str], env: 'Environment') -> T.Tuple[bool, bool]:
return self._has_multi_link_arguments(args, env, 'stop; end program')
def get_options(self) -> 'OptionDictType':
opts = super().get_options()
opts.update({
'std': coredata.UserComboOption(
'Fortran language standard to use',
['none'],
'none',
),
})
return opts
class GnuFortranCompiler(GnuCompiler, FortranCompiler):
@ -175,13 +186,7 @@ class GnuFortranCompiler(GnuCompiler, FortranCompiler):
fortran_stds += ['f2008']
if version_compare(self.version, '>=8.0.0'):
fortran_stds += ['f2018']
opts.update({
'std': coredata.UserComboOption(
'Fortran language standard to use',
['none'] + fortran_stds,
'none',
),
})
opts['std'].choices = ['none'] + fortran_stds # type: ignore
return opts
def get_option_compile_args(self, options: 'OptionDictType') -> T.List[str]:
@ -310,14 +315,7 @@ class IntelFortranCompiler(IntelGnuLikeCompiler, FortranCompiler):
def get_options(self) -> 'OptionDictType':
opts = FortranCompiler.get_options(self)
fortran_stds = ['legacy', 'f95', 'f2003', 'f2008', 'f2018']
opts.update({
'std': coredata.UserComboOption(
'Fortran language standard to use',
['none'] + fortran_stds,
'none',
),
})
opts['std'].choices = ['legacy', 'f95', 'f2003', 'f2008', 'f2018'] # type: ignore
return opts
def get_option_compile_args(self, options: 'OptionDictType') -> T.List[str]:
@ -367,14 +365,7 @@ class IntelClFortranCompiler(IntelVisualStudioLikeCompiler, FortranCompiler):
def get_options(self) -> 'OptionDictType':
opts = FortranCompiler.get_options(self)
fortran_stds = ['legacy', 'f95', 'f2003', 'f2008', 'f2018']
opts.update({
'std': coredata.UserComboOption(
'Fortran language standard to use',
['none'] + fortran_stds,
'none',
),
})
opts['std'].choices = ['legacy', 'f95', 'f2003', 'f2008', 'f2018'] # type: ignore
return opts
def get_option_compile_args(self, options: 'OptionDictType') -> T.List[str]:

Loading…
Cancel
Save