aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/compilers.py
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2016-06-11 23:14:30 +0300
committerGitHub <noreply@github.com>2016-06-11 23:14:30 +0300
commit5384a203f3d68f460e1075889ce02a6c5acdfe4f (patch)
tree9530048b07e4e4a536c6310a2833ebac039adedf /mesonbuild/compilers.py
parent1d709400210e40ad06ed463656d5071cc39ac1be (diff)
parentd4adf0983bd5dcf4083e433146aaec8b51daaaa8 (diff)
downloadmeson-5384a203f3d68f460e1075889ce02a6c5acdfe4f.zip
meson-5384a203f3d68f460e1075889ce02a6c5acdfe4f.tar.gz
meson-5384a203f3d68f460e1075889ce02a6c5acdfe4f.tar.bz2
Merge pull request #585 from mesonbuild/hasarg
Added functionality to check for supported compiler arguments.
Diffstat (limited to 'mesonbuild/compilers.py')
-rw-r--r--mesonbuild/compilers.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/mesonbuild/compilers.py b/mesonbuild/compilers.py
index 03ef9f9..eeb4185 100644
--- a/mesonbuild/compilers.py
+++ b/mesonbuild/compilers.py
@@ -293,6 +293,9 @@ class Compiler():
def get_library_dirs(self):
return []
+ def has_argument(self, arg):
+ raise EnvironmentException('Language {} does not support has_arg.'.format(self.language))
+
class CCompiler(Compiler):
def __init__(self, exelist, version, is_cross, exe_wrapper=None):
super().__init__(exelist, version)
@@ -506,6 +509,8 @@ int main () {{ {1}; }}'''
return p
def compiles(self, code, extra_args = []):
+ if isinstance(extra_args, str):
+ extra_args = [extra_args]
suflen = len(self.default_suffix)
(fd, srcname) = tempfile.mkstemp(suffix='.'+self.default_suffix)
os.close(fd)
@@ -819,6 +824,9 @@ void bar() {
def thread_link_flags(self):
return ['-pthread']
+ def has_argument(self, arg):
+ return self.compiles('int i;\n', extra_args=arg)
+
class CPPCompiler(CCompiler):
def __init__(self, exelist, version, is_cross, exe_wrap):
CCompiler.__init__(self, exelist, version, is_cross, exe_wrap)
@@ -1427,6 +1435,27 @@ class VisualStudioCCompiler(CCompiler):
# msvc does not have a concept of system header dirs.
return ['-I' + path]
+ # Visual Studio is special. It ignores arguments it does not
+ # understand and you can't tell it to error out on those.
+ # http://stackoverflow.com/questions/15259720/how-can-i-make-the-microsoft-c-compiler-treat-unknown-flags-as-errors-rather-t
+ def has_argument(self, arg):
+ warning_text = b'9002'
+ code = 'int i;\n'
+ (fd, srcname) = tempfile.mkstemp(suffix='.'+self.default_suffix)
+ os.close(fd)
+ ofile = open(srcname, 'w')
+ ofile.write(code)
+ ofile.close()
+ commands = self.exelist + [arg] + self.get_compile_only_args() + [srcname]
+ mlog.debug('Running VS compile:')
+ mlog.debug('Command line: ', ' '.join(commands))
+ mlog.debug('Code:\n', code)
+ p = subprocess.Popen(commands, cwd=os.path.split(srcname)[0], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ (stde, stdo) = p.communicate()
+ if p.returncode != 0:
+ raise MesonException('Compiling test app failed.')
+ return not(warning_text in stde or warning_text in stdo)
+
class VisualStudioCPPCompiler(VisualStudioCCompiler):
def __init__(self, exelist, version, is_cross, exe_wrap):
VisualStudioCCompiler.__init__(self, exelist, version, is_cross, exe_wrap)