From 20083c06943f1fe3e7f8db09f4d9b74ba96a51a7 Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Sat, 10 Sep 2016 17:19:51 +0300 Subject: [PATCH] Factored Clang common stuff in its own class. --- mesonbuild/compilers.py | 60 ++++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/mesonbuild/compilers.py b/mesonbuild/compilers.py index 99e1a417b..ba95ba1e9 100644 --- a/mesonbuild/compilers.py +++ b/mesonbuild/compilers.py @@ -2067,6 +2067,36 @@ class GnuObjCPPCompiler(GnuCompiler, ObjCPPCompiler): '2': ['-Wall', '-Wextra', '-Winvalid-pch', '-Wnon-virtual-dtor'], '3' : ['-Wall', '-Wpedantic', '-Wextra', '-Winvalid-pch', '-Wnon-virtual-dtor']} +class ClangCompiler(): + def __init__(self, clang_type): + self.id = 'clang' + self.clang_type = clang_type + self.base_options = ['b_pch', 'b_lto', 'b_pgo', 'b_sanitize', 'b_coverage'] + if self.clang_type != CLANG_OSX: + self.base_options.append('b_lundef') + self.base_options.append('b_asneeded') + + def get_buildtype_args(self, buildtype): + return gnulike_buildtype_args[buildtype] + + def get_buildtype_linker_args(self, buildtype): + return gnulike_buildtype_linker_args[buildtype] + + def get_pch_suffix(self): + return 'pch' + + def can_compile(self, filename): + return super().can_compile(filename) or filename.split('.')[-1].lower() == 's' # Clang can do asm, too. + + def get_pch_use_args(self, pch_dir, header): + # Workaround for Clang bug http://llvm.org/bugs/show_bug.cgi?id=15136 + # This flag is internal to Clang (or at least not documented on the man page) + # so it might change semantics at any time. + return ['-include-pch', os.path.join (pch_dir, self.get_pch_name (header))] + + def has_argument(self, arg, env): + return super().has_argument(['-Werror=unknown-warning-option', arg], env) + class ClangObjCCompiler(GnuObjCCompiler): def __init__(self, exelist, version, cltype, is_cross, exe_wrapper=None): super().__init__(exelist, version, is_cross, exe_wrapper) @@ -2087,36 +2117,13 @@ class ClangObjCPPCompiler(GnuObjCPPCompiler): self.base_options.append('b_lundef') self.base_options.append('b_asneeded') -class ClangCCompiler(CCompiler): +class ClangCCompiler(ClangCompiler, CCompiler): def __init__(self, exelist, version, clang_type, is_cross, exe_wrapper=None): CCompiler.__init__(self, exelist, version, is_cross, exe_wrapper) - self.id = 'clang' - self.clang_type = clang_type + ClangCompiler.__init__(self, clang_type) self.warn_args = {'1': ['-Wall', '-Winvalid-pch'], '2': ['-Wall', '-Wextra', '-Winvalid-pch'], '3' : ['-Wall', '-Wpedantic', '-Wextra', '-Winvalid-pch']} - self.base_options = ['b_pch', 'b_lto', 'b_pgo', 'b_sanitize', 'b_coverage'] - if self.clang_type != CLANG_OSX: - self.base_options.append('b_lundef') - self.base_options.append('b_asneeded') - - def get_buildtype_args(self, buildtype): - return gnulike_buildtype_args[buildtype] - - def get_buildtype_linker_args(self, buildtype): - return gnulike_buildtype_linker_args[buildtype] - - def get_pch_suffix(self): - return 'pch' - - def can_compile(self, filename): - return super().can_compile(filename) or filename.split('.')[-1].lower() == 's' # Clang can do asm, too. - - def get_pch_use_args(self, pch_dir, header): - # Workaround for Clang bug http://llvm.org/bugs/show_bug.cgi?id=15136 - # This flag is internal to Clang (or at least not documented on the man page) - # so it might change semantics at any time. - return ['-include-pch', os.path.join (pch_dir, self.get_pch_name (header))] def get_options(self): return {'c_std' : coredata.UserComboOption('c_std', 'C language standard to use', @@ -2133,9 +2140,6 @@ class ClangCCompiler(CCompiler): def get_option_link_args(self, options): return [] - def has_argument(self, arg, env): - return super().has_argument(['-Werror=unknown-warning-option', arg], env) - class ClangCPPCompiler(CPPCompiler): def __init__(self, exelist, version, cltype, is_cross, exe_wrapper=None):