aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/environment.py
diff options
context:
space:
mode:
Diffstat (limited to 'mesonbuild/environment.py')
-rw-r--r--mesonbuild/environment.py31
1 files changed, 24 insertions, 7 deletions
diff --git a/mesonbuild/environment.py b/mesonbuild/environment.py
index 8c6c60e..dfed376 100644
--- a/mesonbuild/environment.py
+++ b/mesonbuild/environment.py
@@ -39,6 +39,8 @@ from .compilers import (
ClangCPPCompiler,
ClangObjCCompiler,
ClangObjCPPCompiler,
+ ClangClCCompiler,
+ ClangClCPPCompiler,
G95FortranCompiler,
GnuCCompiler,
GnuCPPCompiler,
@@ -190,6 +192,8 @@ def detect_windows_arch(compilers):
platform = os.environ.get('Platform', 'x86').lower()
if platform == 'x86':
return platform
+ if compiler.id == 'clang-cl' and not compiler.is_64:
+ return 'x86'
if compiler.id == 'gcc' and compiler.has_builtin_define('__i386__'):
return 'x86'
return os_arch
@@ -344,8 +348,8 @@ class Environment:
# List of potential compilers.
if mesonlib.is_windows():
- self.default_c = ['cl', 'cc', 'gcc', 'clang']
- self.default_cpp = ['cl', 'c++', 'g++', 'clang++']
+ self.default_c = ['cl', 'cc', 'gcc', 'clang', 'clang-cl']
+ self.default_cpp = ['cl', 'c++', 'g++', 'clang++', 'clang-cl']
else:
self.default_c = ['cc', 'gcc', 'clang']
self.default_cpp = ['c++', 'g++', 'clang++']
@@ -359,6 +363,7 @@ class Environment:
self.default_rust = ['rustc']
self.default_static_linker = ['ar']
self.vs_static_linker = ['lib']
+ self.clang_cl_static_linker = ['llvm-lib']
self.gcc_static_linker = ['gcc-ar']
self.clang_static_linker = ['llvm-ar']
@@ -537,7 +542,7 @@ This is probably wrong, it should always point to the native compiler.''' % evar
for compiler in compilers:
if isinstance(compiler, str):
compiler = [compiler]
- if 'cl' in compiler or 'cl.exe' in compiler:
+ if not set(['cl', 'cl.exe', 'clang-cl', 'clang-cl.exe']).isdisjoint(compiler):
# Watcom C provides it's own cl.exe clone that mimics an older
# version of Microsoft's compiler. Since Watcom's cl.exe is
# just a wrapper, we skip using it if we detect its presence
@@ -606,6 +611,18 @@ This is probably wrong, it should always point to the native compiler.''' % evar
compiler_type = CompilerType.ARM_WIN
cls = ArmclangCCompiler if lang == 'c' else ArmclangCPPCompiler
return cls(ccache + compiler, version, compiler_type, is_cross, exe_wrap, full_version=full_version)
+ if 'CL.EXE COMPATIBILITY' in out:
+ # if this is clang-cl masquerading as cl, detect it as cl, not
+ # clang
+ arg = '--version'
+ try:
+ p, out, err = Popen_safe(compiler + [arg])
+ except OSError as e:
+ popen_exceptions[' '.join(compiler + [arg])] = e
+ version = search_version(out)
+ is_64 = 'Target: x86_64' in out
+ cls = ClangClCCompiler if lang == 'c' else ClangClCPPCompiler
+ return cls(compiler, version, is_cross, exe_wrap, is_64)
if 'clang' in out:
if 'Apple' in out or mesonlib.for_darwin(want_cross, self):
compiler_type = CompilerType.CLANG_OSX
@@ -903,7 +920,7 @@ This is probably wrong, it should always point to the native compiler.''' % evar
if evar in os.environ:
linkers = [shlex.split(os.environ[evar])]
elif isinstance(compiler, compilers.VisualStudioCCompiler):
- linkers = [self.vs_static_linker]
+ linkers = [self.vs_static_linker, self.clang_cl_static_linker]
elif isinstance(compiler, compilers.GnuCompiler):
# Use gcc-ar if available; needed for LTO
linkers = [self.gcc_static_linker, self.default_static_linker]
@@ -913,14 +930,14 @@ This is probably wrong, it should always point to the native compiler.''' % evar
elif isinstance(compiler, compilers.DCompiler):
# Prefer static linkers over linkers used by D compilers
if mesonlib.is_windows():
- linkers = [self.vs_static_linker, compiler.get_linker_exelist()]
+ linkers = [self.vs_static_linker, self.clang_cl_static_linker, compiler.get_linker_exelist()]
else:
linkers = [self.default_static_linker, compiler.get_linker_exelist()]
else:
linkers = [self.default_static_linker]
popen_exceptions = {}
for linker in linkers:
- if 'lib' in linker or 'lib.exe' in linker:
+ if not set(['lib', 'lib.exe', 'llvm-lib', 'llvm-lib.exe']).isdisjoint(linker):
arg = '/?'
else:
arg = '--version'
@@ -929,7 +946,7 @@ This is probably wrong, it should always point to the native compiler.''' % evar
except OSError as e:
popen_exceptions[' '.join(linker + [arg])] = e
continue
- if '/OUT:' in out or '/OUT:' in err:
+ if '/OUT:' in out.upper() or '/OUT:' in err.upper():
return VisualStudioLinker(linker)
if p.returncode == 0 and ('armar' in linker or 'armar.exe' in linker):
return ArmarLinker(linker)