提交 3d31dd81 authored 作者: Pascal Lamblin's avatar Pascal Lamblin

Add method to check if some flags work with g++

上级 116ad0f3
...@@ -1483,6 +1483,46 @@ class GCC_compiler(object): ...@@ -1483,6 +1483,46 @@ class GCC_compiler(object):
cxxflags.append("-D NPY_ARRAY_F_CONTIGUOUS=NPY_F_CONTIGUOUS") cxxflags.append("-D NPY_ARRAY_F_CONTIGUOUS=NPY_F_CONTIGUOUS")
return cxxflags return cxxflags
@staticmethod
def try_flags(flag_list):
'''
Try to compile a dummy file with these flags.
Returns True if compilation was successful, False if there
were errors.
'''
rval = True
try:
code = """
int main(int argc, char** argv)
{
return 0;
}
"""
fd, path = tempfile.mkstemp(suffix='.c', prefix='try_flags_')
dummy_stdin = open(os.devnull)
try:
os.write(fd, code)
os.close(fd)
fd = None
proc = call_subprocess_Popen(['g++', path] + flag_list,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
stdin=dummy_stdin.fileno())
proc.wait()
if proc.returncode != 0:
rval = False
finally:
del dummy_stdin
try:
if fd is not None:
os.close(fd)
finally:
os.remove(path)
except OSError, e:
rval = False
return rval
@staticmethod @staticmethod
def compile_str(module_name, src_code, location=None, def compile_str(module_name, src_code, location=None,
include_dirs=None, lib_dirs=None, libs=None, include_dirs=None, lib_dirs=None, libs=None,
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论