例如,我可以使用python setup.py build --compiler=msvc
or python setup.py build --compiler=mingw32
要不就python setup.py build
,在这种情况下默认编译器(例如,bcpp
) 将会被使用。如何在 setup.py 中获取编译器名称(例如msvc
, mingw32
and bcpp
, 分别)?
UPD.:我不需要默认编译器,我需要的是actually将被使用,这不一定是默认的。到目前为止我还没有找到比解析更好的方法sys.argv
看看是否有--compiler...
那里的字符串。
这是 Luper Rouch 答案的扩展版本,它帮助我获得了 openmp 扩展,以便在 Windows 上使用 mingw 和 msvc 进行编译。子类化 build_ext 后,您需要将其传递给 cmdclass arg 中的 setup.py。通过子类化 build_extensions 而不是 Finalize_options,您将拥有要研究的实际编译器对象,因此您可以获得更详细的版本信息。您最终可以在每个编译器、每个扩展的基础上设置编译器标志:
from distutils.core import setup, Extension
from distutils.command.build_ext import build_ext
copt = {'msvc': ['/openmp', '/Ox', '/fp:fast','/favor:INTEL64','/Og'] ,
'mingw32' : ['-fopenmp','-O3','-ffast-math','-march=native'] }
lopt = {'mingw32' : ['-fopenmp'] }
class build_ext_subclass( build_ext ):
def build_extensions(self):
c = self.compiler.compiler_type
if copt.has_key(c):
for e in self.extensions:
e.extra_compile_args = copt[ c ]
if lopt.has_key(c):
for e in self.extensions:
e.extra_link_args = lopt[ c ]
build_ext.build_extensions(self)
mod = Extension('_wripaca',
sources=['../wripaca_wrap.c',
'../../src/wripaca.c'],
include_dirs=['../../include']
)
setup (name = 'wripaca',
ext_modules = [mod],
py_modules = ["wripaca"],
cmdclass = {'build_ext': build_ext_subclass } )
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)