diff options
author | Jussi Pakkanen <jpakkane@gmail.com> | 2016-09-14 19:12:09 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-09-14 19:12:09 +0300 |
commit | 7d24f96d2dd4d4120cd619008454a0101531744d (patch) | |
tree | 9dc6344b9e048605aa9c619aba08ea6473493f78 | |
parent | 3d8876bf59ed20635cdc25de7a2da0d17210c944 (diff) | |
parent | 873558b2b4ffc697a732110f2701267bae6f883c (diff) | |
download | meson-7d24f96d2dd4d4120cd619008454a0101531744d.zip meson-7d24f96d2dd4d4120cd619008454a0101531744d.tar.gz meson-7d24f96d2dd4d4120cd619008454a0101531744d.tar.bz2 |
Merge pull request #774 from mesonbuild/compilerreorg
Move compiler common functionality to own class
-rw-r--r-- | mesonbuild/compilers.py | 262 |
1 files changed, 93 insertions, 169 deletions
diff --git a/mesonbuild/compilers.py b/mesonbuild/compilers.py index d1f3896..fb2a81a 100644 --- a/mesonbuild/compilers.py +++ b/mesonbuild/compilers.py @@ -1947,14 +1947,11 @@ def get_gcc_soname_args(gcc_type, shlib_name, path, soversion): raise RuntimeError('Not implemented yet.') -class GnuCCompiler(CCompiler): - def __init__(self, exelist, version, gcc_type, is_cross, exe_wrapper=None): - CCompiler.__init__(self, exelist, version, is_cross, exe_wrapper) +class GnuCompiler: + # Functionality that is common to all GNU family compilers. + def __init__(self, gcc_type): self.id = 'gcc' self.gcc_type = gcc_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', 'b_colorout'] if self.gcc_type != GCC_OSX: @@ -1971,15 +1968,15 @@ class GnuCCompiler(CCompiler): return [] # On Window gcc defaults to fpic being always on. return ['-fPIC'] - def get_always_args(self): - return ['-pipe'] - 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_always_args(self): + return ['-pipe'] + def get_pch_suffix(self): return 'gch' @@ -1989,6 +1986,14 @@ class GnuCCompiler(CCompiler): def get_soname_args(self, shlib_name, path, soversion): return get_gcc_soname_args(self.gcc_type, shlib_name, path, soversion) +class GnuCCompiler(GnuCompiler, CCompiler): + def __init__(self, exelist, version, gcc_type, is_cross, exe_wrapper=None): + CCompiler.__init__(self, exelist, version, is_cross, exe_wrapper) + GnuCompiler.__init__(self, gcc_type) + self.warn_args = {'1': ['-Wall', '-Winvalid-pch'], + '2': ['-Wall', '-Wextra', '-Winvalid-pch'], + '3' : ['-Wall', '-Wpedantic', '-Wextra', '-Winvalid-pch']} + def can_compile(self, filename): return super().can_compile(filename) or filename.split('.')[-1].lower() == 's' # Gcc can do asm, too. @@ -2015,92 +2020,70 @@ class GnuCCompiler(CCompiler): return options['c_winlibs'].value return [] -class GnuObjCCompiler(ObjCCompiler): - std_opt_args = ['-O2'] +class GnuCPPCompiler(GnuCompiler, CPPCompiler): + + def __init__(self, exelist, version, gcc_type, is_cross, exe_wrap): + CPPCompiler.__init__(self, exelist, version, is_cross, exe_wrap) + GnuCompiler.__init__(self, gcc_type) + self.warn_args = {'1': ['-Wall', '-Winvalid-pch', '-Wnon-virtual-dtor'], + '2': ['-Wall', '-Wextra', '-Winvalid-pch', '-Wnon-virtual-dtor'], + '3': ['-Wall', '-Wpedantic', '-Wextra', '-Winvalid-pch', '-Wnon-virtual-dtor']} + + def get_options(self): + opts = {'cpp_std' : coredata.UserComboOption('cpp_std', 'C++ language standard to use', + ['none', 'c++03', 'c++11', 'c++14', 'c++1z', + 'gnu++03', 'gnu++11', 'gnu++14', 'gnu++1z'], + 'none'), + 'cpp_debugstl': coredata.UserBooleanOption('cpp_debugstl', + 'STL debug mode', + False)} + if self.gcc_type == GCC_MINGW: + opts.update({ + 'cpp_winlibs': coredata.UserStringArrayOption('c_winlibs', 'Standard Win libraries to link against', + gnu_winlibs), + }) + return opts + + def get_option_compile_args(self, options): + args = [] + std = options['cpp_std'] + if std.value != 'none': + args.append('-std=' + std.value) + if options['cpp_debugstl'].value: + args.append('-D_GLIBCXX_DEBUG=1') + return args + + def get_option_link_args(self, options): + if self.gcc_type == GCC_MINGW: + return options['cpp_winlibs'].value + return [] + +class GnuObjCCompiler(GnuCompiler,ObjCCompiler): def __init__(self, exelist, version, is_cross, exe_wrapper=None): ObjCCompiler.__init__(self, exelist, version, is_cross, exe_wrapper) - self.id = 'gcc' # Not really correct, but GNU objc is only used on non-OSX non-win. File a bug # if this breaks your use case. - self.gcc_type = GCC_STANDARD + GnuCompiler.__init__(self, GCC_STANDARD) 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.gcc_type != GCC_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 'gch' - - def get_soname_args(self, shlib_name, path, soversion): - return get_gcc_soname_args(self.gcc_type, shlib_name, path, soversion) - -class GnuObjCPPCompiler(ObjCPPCompiler): - std_opt_args = ['-O2'] +class GnuObjCPPCompiler(GnuCompiler, ObjCPPCompiler): def __init__(self, exelist, version, is_cross, exe_wrapper=None): ObjCCompiler.__init__(self, exelist, version, is_cross, exe_wrapper) - self.id = 'gcc' # Not really correct, but GNU objc is only used on non-OSX non-win. File a bug # if this breaks your use case. - self.gcc_type = GCC_STANDARD + GnuCompiler.__init__(self, GCC_STANDARD) self.warn_args = {'1': ['-Wall', '-Winvalid-pch', '-Wnon-virtual-dtor'], '2': ['-Wall', '-Wextra', '-Winvalid-pch', '-Wnon-virtual-dtor'], '3' : ['-Wall', '-Wpedantic', '-Wextra', '-Winvalid-pch', '-Wnon-virtual-dtor']} - self.base_options = ['b_pch', 'b_lto', 'b_pgo', 'b_sanitize', 'b_coverage'] - if self.gcc_type != GCC_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 'gch' - - def get_soname_args(self, shlib_name, path, soversion): - return get_gcc_soname_args(self.gcc_type, shlib_name, path, soversion) -class ClangObjCCompiler(GnuObjCCompiler): - def __init__(self, exelist, version, cltype, is_cross, exe_wrapper=None): - super().__init__(exelist, version, is_cross, exe_wrapper) - self.id = 'clang' - self.base_options = ['b_pch', 'b_lto', 'b_pgo', 'b_sanitize', 'b_coverage'] - self.clang_type = cltype - if self.clang_type != CLANG_OSX: - self.base_options.append('b_lundef') - self.base_options.append('b_asneeded') - -class ClangObjCPPCompiler(GnuObjCPPCompiler): - def __init__(self, exelist, version, cltype, is_cross, exe_wrapper=None): - super().__init__(exelist, version, is_cross, exe_wrapper) - self.id = 'clang' - self.clang_type = cltype - 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') - -class ClangCCompiler(CCompiler): - def __init__(self, exelist, version, clang_type, is_cross, exe_wrapper=None): - CCompiler.__init__(self, exelist, version, is_cross, exe_wrapper) +class ClangCompiler(): + def __init__(self, clang_type): self.id = 'clang' self.clang_type = 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') @@ -2115,15 +2098,20 @@ class ClangCCompiler(CCompiler): 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))] +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) + ClangCompiler.__init__(self, clang_type) + self.warn_args = {'1': ['-Wall', '-Winvalid-pch'], + '2': ['-Wall', '-Wextra', '-Winvalid-pch'], + '3' : ['-Wall', '-Wpedantic', '-Wextra', '-Winvalid-pch']} + def get_options(self): return {'c_std' : coredata.UserComboOption('c_std', 'C language standard to use', ['none', 'c89', 'c99', 'c11'], @@ -2142,104 +2130,17 @@ class ClangCCompiler(CCompiler): def has_argument(self, arg, env): return super().has_argument(['-Werror=unknown-warning-option', arg], env) -class GnuCPPCompiler(CPPCompiler): - # may need to separate the latter to extra_debug_args or something - std_debug_args = ['-g'] - - def __init__(self, exelist, version, gcc_type, is_cross, exe_wrap): - CPPCompiler.__init__(self, exelist, version, is_cross, exe_wrap) - self.id = 'gcc' - self.gcc_type = gcc_type - self.warn_args = {'1': ['-Wall', '-Winvalid-pch', '-Wnon-virtual-dtor'], - '2': ['-Wall', '-Wextra', '-Winvalid-pch', '-Wnon-virtual-dtor'], - '3': ['-Wall', '-Wpedantic', '-Wextra', '-Winvalid-pch', '-Wnon-virtual-dtor']} - self.base_options = ['b_pch', 'b_lto', 'b_pgo', 'b_sanitize', 'b_coverage', - 'b_colorout'] - if self.gcc_type != GCC_OSX: - self.base_options.append('b_lundef') - self.base_options.append('b_asneeded') - - def get_colorout_args(self, colortype): - if mesonlib.version_compare(self.version, '>=4.9.0'): - return gnu_color_args[colortype][:] - return [] - - def get_pic_args(self): - if self.gcc_type == GCC_MINGW: - return [] # On Window gcc defaults to fpic being always on. - return ['-fPIC'] - - def get_always_args(self): - return ['-pipe'] - - 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 'gch' - - def get_soname_args(self, shlib_name, path, soversion): - return get_gcc_soname_args(self.gcc_type, shlib_name, path, soversion) - - def get_options(self): - opts = {'cpp_std' : coredata.UserComboOption('cpp_std', 'C++ language standard to use', - ['none', 'c++03', 'c++11', 'c++14', 'c++1z', - 'gnu++03', 'gnu++11', 'gnu++14', 'gnu++1z'], - 'none'), - 'cpp_debugstl': coredata.UserBooleanOption('cpp_debugstl', - 'STL debug mode', - False)} - if self.gcc_type == GCC_MINGW: - opts.update({ - 'cpp_winlibs': coredata.UserStringArrayOption('c_winlibs', 'Standard Win libraries to link against', - gnu_winlibs), - }) - return opts - - def get_option_compile_args(self, options): - args = [] - std = options['cpp_std'] - if std.value != 'none': - args.append('-std=' + std.value) - if options['cpp_debugstl'].value: - args.append('-D_GLIBCXX_DEBUG=1') - return args + def can_compile(self, filename): + return super().can_compile(filename) or filename.split('.')[-1].lower() == 's' # Clang can do asm, too. - def get_option_link_args(self, options): - if self.gcc_type == GCC_MINGW: - return options['cpp_winlibs'].value - return [] -class ClangCPPCompiler(CPPCompiler): +class ClangCPPCompiler(ClangCompiler, CPPCompiler): def __init__(self, exelist, version, cltype, is_cross, exe_wrapper=None): CPPCompiler.__init__(self, exelist, version, is_cross, exe_wrapper) - self.id = 'clang' + ClangCompiler.__init__(self, cltype) self.warn_args = {'1': ['-Wall', '-Winvalid-pch', '-Wnon-virtual-dtor'], '2': ['-Wall', '-Wextra', '-Winvalid-pch', '-Wnon-virtual-dtor'], '3': ['-Wall', '-Wpedantic', '-Wextra', '-Winvalid-pch', '-Wnon-virtual-dtor']} - self.clang_type = cltype - 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 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 {'cpp_std' : coredata.UserComboOption('cpp_std', 'C++ language standard to use', @@ -2259,6 +2160,29 @@ class ClangCPPCompiler(CPPCompiler): def has_argument(self, arg, env): return super().has_argument(['-Werror=unknown-warning-option', arg], env) + def can_compile(self, filename): + return super().can_compile(filename) or filename.split('.')[-1].lower() == 's' # Clang can do asm, too. + +class ClangObjCCompiler(GnuObjCCompiler): + def __init__(self, exelist, version, cltype, is_cross, exe_wrapper=None): + super().__init__(exelist, version, is_cross, exe_wrapper) + self.id = 'clang' + self.base_options = ['b_pch', 'b_lto', 'b_pgo', 'b_sanitize', 'b_coverage'] + self.clang_type = cltype + if self.clang_type != CLANG_OSX: + self.base_options.append('b_lundef') + self.base_options.append('b_asneeded') + +class ClangObjCPPCompiler(GnuObjCPPCompiler): + def __init__(self, exelist, version, cltype, is_cross, exe_wrapper=None): + super().__init__(exelist, version, is_cross, exe_wrapper) + self.id = 'clang' + self.clang_type = cltype + 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') + class FortranCompiler(Compiler): def __init__(self, exelist, version, is_cross, exe_wrapper=None): super().__init__(exelist, version) |