diff options
author | John Ericson <John.Ericson@Obsidian.Systems> | 2019-06-12 18:08:45 -0400 |
---|---|---|
committer | Jussi Pakkanen <jpakkane@gmail.com> | 2020-04-20 23:23:15 +0300 |
commit | 278c294aa45efc3e8b068bcd7632828ed5c92523 (patch) | |
tree | 36372ef2c9a5897cca87e8c44628c8f9e00c368e /mesonbuild/compilers/c.py | |
parent | e04b0ae6b6220381b4aa493289960a3555201717 (diff) | |
download | meson-278c294aa45efc3e8b068bcd7632828ed5c92523.zip meson-278c294aa45efc3e8b068bcd7632828ed5c92523.tar.gz meson-278c294aa45efc3e8b068bcd7632828ed5c92523.tar.bz2 |
Compiler options per lang
A current rather untyped storage of options is one of the things that
contributes to the options code being so complex. This takes a small
step in synching down by storing the compiler options in dicts per
language.
Future work might be replacing the langauge strings with an enum, and
defaultdict with a custom struct, just like `PerMachine` and
`MachineChoice`.
Diffstat (limited to 'mesonbuild/compilers/c.py')
-rw-r--r-- | mesonbuild/compilers/c.py | 129 |
1 files changed, 86 insertions, 43 deletions
diff --git a/mesonbuild/compilers/c.py b/mesonbuild/compilers/c.py index eba7131..1bc9e84 100644 --- a/mesonbuild/compilers/c.py +++ b/mesonbuild/compilers/c.py @@ -107,25 +107,32 @@ class ClangCCompiler(ClangCompiler, CCompiler): if version_compare(self.version, self._C18_VERSION): c_stds += ['c18'] g_stds += ['gnu18'] - opts.update({'c_std': coredata.UserComboOption('C language standard to use', - ['none'] + c_stds + g_stds, - 'none')}) + opts.update({ + 'std': coredata.UserComboOption( + 'C language standard to use', + ['none'] + c_stds + g_stds, + 'none', + ), + }) if self.info.is_windows() or self.info.is_cygwin(): opts.update({ - 'c_winlibs': coredata.UserArrayOption('Standard Win libraries to link against', - gnu_winlibs), }) + 'winlibs': coredata.UserArrayOption( + 'Standard Win libraries to link against', + gnu_winlibs, + ), + }) return opts def get_option_compile_args(self, options): args = [] - std = options['c_std'] + std = options['std'] if std.value != 'none': args.append('-std=' + std.value) return args def get_option_link_args(self, options): if self.info.is_windows() or self.info.is_cygwin(): - return options['c_winlibs'].value[:] + return options['winlibs'].value[:] return [] @@ -166,15 +173,18 @@ class ArmclangCCompiler(ArmclangCompiler, CCompiler): def get_options(self): opts = CCompiler.get_options(self) - opts.update({'c_std': coredata.UserComboOption('C language standard to use', - ['none', 'c90', 'c99', 'c11', - 'gnu90', 'gnu99', 'gnu11'], - 'none')}) + opts.update({ + 'std': coredata.UserComboOption( + 'C language standard to use', + ['none', 'c90', 'c99', 'c11', 'gnu90', 'gnu99', 'gnu11'], + 'none', + ), + }) return opts def get_option_compile_args(self, options): args = [] - std = options['c_std'] + std = options['std'] if std.value != 'none': args.append('-std=' + std.value) return args @@ -204,25 +214,32 @@ class GnuCCompiler(GnuCompiler, CCompiler): if version_compare(self.version, v): c_stds += ['c17', 'c18'] g_stds += ['gnu17', 'gnu18'] - opts.update({'c_std': coredata.UserComboOption('C language standard to use', - ['none'] + c_stds + g_stds, - 'none')}) + opts.update({ + 'std': coredata.UserComboOption( + 'C language standard to use', + ['none'] + c_stds + g_stds, + 'none', + ), + }) if self.info.is_windows() or self.info.is_cygwin(): opts.update({ - 'c_winlibs': coredata.UserArrayOption('Standard Win libraries to link against', - gnu_winlibs), }) + 'winlibs': coredata.UserArrayOption( + 'Standard Win libraries to link against', + gnu_winlibs, + ), + }) return opts def get_option_compile_args(self, options): args = [] - std = options['c_std'] + std = options['std'] if std.value != 'none': args.append('-std=' + std.value) return args def get_option_link_args(self, options): if self.info.is_windows() or self.info.is_cygwin(): - return options['c_winlibs'].value[:] + return options['winlibs'].value[:] return [] def get_pch_use_args(self, pch_dir, header): @@ -248,11 +265,17 @@ 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): opts = CCompiler.get_options(self) - opts.update({'c_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.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', + ), + }) return opts # Elbrus C compiler does not have lchmod, but there is only linker warning, not compiler error. @@ -285,14 +308,18 @@ class IntelCCompiler(IntelGnuLikeCompiler, CCompiler): g_stds = ['gnu89', 'gnu99'] if version_compare(self.version, '>=16.0.0'): c_stds += ['c11'] - opts.update({'c_std': coredata.UserComboOption('C language standard to use', - ['none'] + c_stds + g_stds, - 'none')}) + opts.update({ + 'std': coredata.UserComboOption( + 'C language standard to use', + ['none'] + c_stds + g_stds, + 'none', + ), + }) return opts def get_option_compile_args(self, options): args = [] - std = options['c_std'] + std = options['std'] if std.value != 'none': args.append('-std=' + std.value) return args @@ -304,12 +331,16 @@ class VisualStudioLikeCCompilerMixin: def get_options(self): opts = super().get_options() - opts.update({'c_winlibs': coredata.UserArrayOption('Windows libs to link against.', - msvc_winlibs)}) + opts.update({ + 'winlibs': coredata.UserArrayOption( + 'Windows libs to link against.', + msvc_winlibs, + ), + }) return opts def get_option_link_args(self, options): - return options['c_winlibs'].value[:] + return options['winlibs'].value[:] class VisualStudioCCompiler(MSVCCompiler, VisualStudioLikeCCompilerMixin, CCompiler): @@ -343,14 +374,18 @@ class IntelClCCompiler(IntelVisualStudioLikeCompiler, VisualStudioLikeCCompilerM def get_options(self): opts = super().get_options() c_stds = ['none', 'c89', 'c99', 'c11'] - opts.update({'c_std': coredata.UserComboOption('C language standard to use', - c_stds, - 'none')}) + opts.update({ + 'std': coredata.UserComboOption( + 'C language standard to use', + c_stds, + 'none', + ), + }) return opts def get_option_compile_args(self, options): args = [] - std = options['c_std'] + 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) elif std.value != 'none': @@ -367,14 +402,18 @@ class ArmCCompiler(ArmCompiler, CCompiler): def get_options(self): opts = CCompiler.get_options(self) - opts.update({'c_std': coredata.UserComboOption('C language standard to use', - ['none', 'c90', 'c99'], - 'none')}) + opts.update({ + 'std': coredata.UserComboOption( + 'C language standard to use', + ['none', 'c90', 'c99'], + 'none', + ), + }) return opts def get_option_compile_args(self, options): args = [] - std = options['c_std'] + std = options['std'] if std.value != 'none': args.append('--' + std.value) return args @@ -393,9 +432,13 @@ class CcrxCCompiler(CcrxCompiler, CCompiler): def get_options(self): opts = CCompiler.get_options(self) - opts.update({'c_std': coredata.UserComboOption('C language standard to use', - ['none', 'c89', 'c99'], - 'none')}) + opts.update({ + 'std': coredata.UserComboOption( + 'C language standard to use', + ['none', 'c89', 'c99'], + 'none', + ), + }) return opts def get_no_stdinc_args(self): @@ -403,7 +446,7 @@ class CcrxCCompiler(CcrxCompiler, CCompiler): def get_option_compile_args(self, options): args = [] - std = options['c_std'] + std = options['std'] if std.value == 'c89': args.append('-lang=c') elif std.value == 'c99': |