Added basic Visual Studio compiler detection.

This commit is contained in:
Jussi Pakkanen 2013-04-19 21:00:59 +03:00
parent 9f4471c96f
commit 21c6166af9
1 changed files with 59 additions and 25 deletions

View File

@ -161,6 +161,28 @@ class ObjCXXCompiler(CXXCompiler):
if pe.returncode != 0: if pe.returncode != 0:
raise EnvironmentException('Executables created by ObjC++ compiler %s are not runnable.' % self.name_string()) raise EnvironmentException('Executables created by ObjC++ compiler %s are not runnable.' % self.name_string())
class VisualStudioCCompiler(CCompiler):
std_warn_flags = ['/Wall']
std_opt_flags= ['/O2']
def __init__(self, exelist):
CCompiler.__init__(self, exelist)
def get_std_warn_flags(self):
return VisualStudioCCompiler.std_warn_flags
def get_std_opt_flags(self):
return VisualStudioCCompiler.std_opt_flags
def get_pch_suffix(self):
return 'pch'
def get_debug_flags(self):
return ['/D_DEBUG', '/Zi', '/MDd', '/Ob0', '/RTC1']
def get_compile_only_flags(self):
return ['/c']
class GnuCCompiler(CCompiler): class GnuCCompiler(CCompiler):
std_warn_flags = ['-Wall', '-Winvalid-pch'] std_warn_flags = ['-Wall', '-Winvalid-pch']
std_opt_flags = ['-O2'] std_opt_flags = ['-O2']
@ -325,8 +347,13 @@ class Environment():
except IOError: except IOError:
self.coredata = coredata.CoreData(options) self.coredata = coredata.CoreData(options)
self.default_c = ['cc'] # List of potential compilers.
self.default_cxx = ['c++'] if is_windows():
self.default_c = ['cl', 'cc']
self.default_cxx = ['cl', 'c++']
else:
self.default_c = ['cc']
self.default_cxx = ['c++']
self.default_objc = ['cc'] self.default_objc = ['cc']
self.default_objcxx = ['c++'] self.default_objcxx = ['c++']
self.default_static_linker = ['ar'] self.default_static_linker = ['ar']
@ -362,33 +389,40 @@ class Environment():
def get_build_command(self): def get_build_command(self):
return self.meson_script_file return self.meson_script_file
def get_c_compiler_exelist(self):
ccachelist = self.detect_ccache()
evar = 'CC'
if evar in os.environ:
return os.environ[evar].split()
return ccachelist + self.default_c
def is_header(self, fname): def is_header(self, fname):
suffix = fname.split('.')[-1] suffix = fname.split('.')[-1]
return suffix in header_suffixes return suffix in header_suffixes
def detect_c_compiler(self): def detect_c_compiler(self):
exelist = self.get_c_compiler_exelist() evar = 'CC'
try: if evar in os.environ:
p = subprocess.Popen(exelist + ['--version'], stdout=subprocess.PIPE) compilers = [os.environ[evar].split()]
except OSError: ccache = []
raise EnvironmentException('Could not execute C compiler "%s"' % ' '.join(exelist)) else:
out = p.communicate()[0] compilers = self.default_c
out = out.decode() ccache = self.detect_ccache()
if (out.startswith('cc ') or out.startswith('gcc')) and \ for compiler in compilers:
'Free Software Foundation' in out: try:
return GnuCCompiler(exelist) basename = os.path.basename(compiler).lower()
if 'apple' in out and 'Free Software Foundation' in out: if basename == 'cl' or basename == 'cl.exe':
return GnuCCompiler(exelist) arg = '/?'
if (out.startswith('clang')): else:
return ClangCCompiler(exelist) arg = '--version'
raise EnvironmentException('Unknown compiler "' + ' '.join(exelist) + '"') p = subprocess.Popen([compiler] + [arg], stdout=subprocess.PIPE)
except OSError:
continue
out = p.communicate()[0]
out = out.decode()
if (out.startswith('cc ') or out.startswith('gcc')) and \
'Free Software Foundation' in out:
return GnuCCompiler(ccache + [compiler])
if 'apple' in out and 'Free Software Foundation' in out:
return GnuCCompiler(ccache + [compiler])
if (out.startswith('clang')):
return ClangCCompiler(ccache + [compiler])
if 'Microsoft' in out:
return VisualStudioCCompiler([compiler])
raise EnvironmentException('Unknown compiler(s): "' + ', '.join(compilers) + '"')
def get_scratch_dir(self): def get_scratch_dir(self):
return self.scratch_dir return self.scratch_dir