diff --git a/mesonbuild/compilers.py b/mesonbuild/compilers.py index 4bb0d83c9..2c35c67a8 100644 --- a/mesonbuild/compilers.py +++ b/mesonbuild/compilers.py @@ -1348,6 +1348,11 @@ GCC_STANDARD = 0 GCC_OSX = 1 GCC_MINGW = 2 +CLANG_STANDARD = 0 +CLANG_OSX = 1 +CLANG_WIN = 2 +# Possibly clang-cl? + def get_gcc_soname_args(gcc_type, shlib_name, path, soversion): if soversion is None: sostr = '' @@ -1480,22 +1485,34 @@ class GnuObjCPPCompiler(ObjCPPCompiler): return get_gcc_soname_args(self.gcc_type, shlib_name, path, soversion) class ClangObjCCompiler(GnuObjCCompiler): - def __init__(self, exelist, version, is_cross, exe_wrapper=None): + 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_lto', 'b_pgo', 'b_sanitize'] + self.clang_type = cltype + if self.clang_type != CLANG_OSX: + self.base_options.append('b_lundef') class ClangObjCPPCompiler(GnuObjCPPCompiler): - def __init__(self, exelist, version, is_cross, exe_wrapper=None): + 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_lto', 'b_pgo', 'b_sanitize'] + if self.clang_type != CLANG_OSX: + self.base_options.append('b_lundef') class ClangCCompiler(CCompiler): - def __init__(self, exelist, version, is_cross, exe_wrapper=None): + 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 self.warn_args = {'1': ['-Wall', '-Winvalid-pch'], '2': ['-Wall', '-Wextra', '-Winvalid-pch'], '3' : ['-Wall', '-Wpedantic', '-Wextra', '-Winvalid-pch']} + self.base_options = ['b_lto', 'b_pgo', 'b_sanitize'] + if self.clang_type != CLANG_OSX: + self.base_options.append('b_lundef') def get_buildtype_args(self, buildtype): return gnulike_buildtype_args[buildtype] @@ -1584,12 +1601,16 @@ class GnuCPPCompiler(CPPCompiler): return [] class ClangCPPCompiler(CPPCompiler): - def __init__(self, exelist, version, is_cross, exe_wrapper=None): + def __init__(self, exelist, version, cltype, is_cross, exe_wrapper=None): CPPCompiler.__init__(self, exelist, version, is_cross, exe_wrapper) self.id = 'clang' 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_lto', 'b_pgo', 'b_sanitize'] + if self.clang_type != CLANG_OSX: + self.base_options.append('b_lundef') def get_buildtype_args(self, buildtype): return gnulike_buildtype_args[buildtype] diff --git a/mesonbuild/environment.py b/mesonbuild/environment.py index 1586248e5..3893e60aa 100644 --- a/mesonbuild/environment.py +++ b/mesonbuild/environment.py @@ -222,7 +222,11 @@ class Environment(): gtype = GCC_STANDARD return GnuCCompiler(ccache + [compiler], version, gtype, is_cross, exe_wrap) if 'clang' in out: - return ClangCCompiler(ccache + [compiler], version, is_cross, exe_wrap) + if 'Apple' in out: + cltype = CLANG_OSX + else: + cltype = CLANG_STANDARD + return ClangCCompiler(ccache + [compiler], version, cltype, is_cross, exe_wrap) if 'Microsoft' in out or 'Microsoft' in err: # Visual Studio prints version number to stderr but # everything else to stdout. Why? Lord only knows. @@ -346,7 +350,11 @@ class Environment(): gtype = GCC_STANDARD return GnuCPPCompiler(ccache + [compiler], version, gtype, is_cross, exe_wrap) if 'clang' in out: - return ClangCPPCompiler(ccache + [compiler], version, is_cross, exe_wrap) + if 'Apple' in out: + cltype = CLANG_OSX + else: + cltype = CLANG_STANDARD + return ClangCPPCompiler(ccache + [compiler], version, cltype, is_cross, exe_wrap) if 'Microsoft' in out or 'Microsoft' in err: version = re.search(Environment.version_regex, err).group() return VisualStudioCPPCompiler([compiler], version, is_cross, exe_wrap) @@ -377,7 +385,7 @@ class Environment(): 'Free Software Foundation' in out: return GnuObjCCompiler(exelist, version, is_cross, exe_wrap) if out.startswith('Apple LLVM'): - return ClangObjCCompiler(exelist, version, is_cross, exe_wrap) + return ClangObjCCompiler(exelist, version, CLANG_OSX, is_cross, exe_wrap) if 'apple' in out and 'Free Software Foundation' in out: return GnuObjCCompiler(exelist, version, is_cross, exe_wrap) raise EnvironmentException('Unknown compiler "' + ' '.join(exelist) + '"') @@ -407,7 +415,7 @@ class Environment(): 'Free Software Foundation' in out: return GnuObjCPPCompiler(exelist, version, is_cross, exe_wrap) if out.startswith('Apple LLVM'): - return ClangObjCPPCompiler(exelist, version, is_cross, exe_wrap) + return ClangObjCPPCompiler(exelist, version, CLANG_OSX, is_cross, exe_wrap) if 'apple' in out and 'Free Software Foundation' in out: return GnuObjCPPCompiler(exelist, version, is_cross, exe_wrap) raise EnvironmentException('Unknown compiler "' + ' '.join(exelist) + '"')