Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 import os
00011 from os.path import join as pjoin
00012 from setuptools import setup
00013 from distutils.extension import Extension
00014 from Cython.Distutils import build_ext
00015 import numpy as np
00016
00017
00018 try:
00019 numpy_include = np.get_include()
00020 except AttributeError:
00021 numpy_include = np.get_numpy_include()
00022
00023
00024 def customize_compiler_for_nvcc(self):
00025 """inject deep into distutils to customize how the dispatch
00026 to gcc/nvcc works.
00027 If you subclass UnixCCompiler, it's not trivial to get your subclass
00028 injected in, and still have the right customizations (i.e.
00029 distutils.sysconfig.customize_compiler) run on it. So instead of going
00030 the OO route, I have this. Note, it's kindof like a wierd functional
00031 subclassing going on."""
00032
00033
00034 self.src_extensions.append('.cu')
00035
00036
00037 default_compiler_so = self.compiler_so
00038 super = self._compile
00039
00040
00041
00042
00043 def _compile(obj, src, ext, cc_args, extra_postargs, pp_opts):
00044 if os.path.splitext(src)[1] == '.cu':
00045
00046 self.set_executable('compiler_so', CUDA['nvcc'])
00047
00048
00049 postargs = extra_postargs['nvcc']
00050 else:
00051 postargs = extra_postargs['gcc']
00052
00053 super(obj, src, ext, cc_args, postargs, pp_opts)
00054
00055 self.compiler_so = default_compiler_so
00056
00057
00058 self._compile = _compile
00059
00060
00061
00062 class custom_build_ext(build_ext):
00063 def build_extensions(self):
00064 customize_compiler_for_nvcc(self.compiler)
00065 build_ext.build_extensions(self)
00066
00067
00068 ext_modules = [
00069 Extension(
00070 "bbox",
00071 ["bbox.pyx"],
00072 extra_compile_args={'gcc': ["-Wno-cpp", "-Wno-unused-function"]},
00073 include_dirs=[numpy_include]
00074 ),
00075 ]
00076
00077 setup(
00078 name='bbox_cython',
00079 ext_modules=ext_modules,
00080
00081 cmdclass={'build_ext': custom_build_ext},
00082 )