Browse Source

Merge pull request #7 from SylvainCorlay/has_flag_better_implementation

Better implementation of has_flag method
master
Sylvain Corlay 9 years ago
parent
commit
818b984d90
  1. 7
      setup.py

7
setup.py

@ -17,16 +17,17 @@ ext_modules = [
), ),
] ]
# As of Python 3.6, CCompiler has a `has_flag` method.
# cf http://bugs.python.org/issue26689
def has_flag(compiler, flagname): def has_flag(compiler, flagname):
"""Return a boolean indicating whether a flag name is supported on """Return a boolean indicating whether a flag name is supported on
the specified compiler. the specified compiler.
""" """
import tempfile import tempfile
fd, fname = tempfile.mkstemp('.cpp', 'main', text=True) with tempfile.NamedTemporaryFile('w', suffix='.cpp') as f:
with os.fdopen(fd, 'w') as f:
f.write('int main (int argc, char **argv) { return 0; }') f.write('int main (int argc, char **argv) { return 0; }')
try: try:
compiler.compile([fname], extra_postargs=[flagname]) compiler.compile([f.name], extra_postargs=[flagname])
except setuptools.distutils.errors.CompileError: except setuptools.distutils.errors.CompileError:
return False return False
return True return True

Loading…
Cancel
Save