-
Notifications
You must be signed in to change notification settings - Fork 27
/
setup.py
113 lines (102 loc) · 3.26 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
try:
from setuptools import setup
except ImportError:
from distutils.core import setup
from distutils.extension import Extension
from Cython.Build import cythonize
from setuptools.command.build_ext import build_ext
import numpy
numpy_include_dir = numpy.get_include()
# Extensions
# triangle hash (efficient mesh intersection)
triangle_hash_module = Extension(
'external.libmesh.triangle_hash',
sources=[
'external/libmesh/triangle_hash.pyx'
],
libraries=['m'], # Unix-like specific
include_dirs=[numpy_include_dir]
)
# voxelization (efficient mesh voxelization)
voxelize_module = Extension(
'external.libvoxelize.voxelize',
sources=[
'external/libvoxelize/voxelize.pyx'
],
libraries=['m'] # Unix-like specific
)
# pykdtree (kd tree)
pykdtree = Extension(
'external.libkdtree.pykdtree.kdtree',
sources=[
'external/libkdtree/pykdtree/kdtree.c',
'external/libkdtree/pykdtree/_kdtree_core.c'
],
language='c',
extra_compile_args=['-std=c99', '-O3', '-fopenmp'],
extra_link_args=['-lgomp'],
include_dirs=[numpy_include_dir]
)
# simplify (efficient mesh simplification)
simplify_mesh_module = Extension(
'external.libsimplify.simplify_mesh',
sources=[
'external/libsimplify/simplify_mesh.pyx'
],
include_dirs=[numpy_include_dir]
)
# mise (efficient mesh extraction)
mise_module = Extension(
'external.libmise.mise',
sources=[
'external/libmise/mise.pyx'
],
)
# Gather all extension modules
ext_modules = [
pykdtree,
triangle_hash_module,
voxelize_module,
simplify_mesh_module,
mise_module
]
def set_builtin(name, value):
if isinstance(__builtins__, dict):
__builtins__[name] = value
else:
setattr(__builtins__, name, value)
class build_ext_subclass(build_ext):
def build_extensions(self):
comp = self.compiler.compiler_type
if comp in ('unix', 'cygwin', 'mingw32'):
# Check if build is with OpenMP
extra_compile_args = ['-std=c99', '-O3', '-fopenmp']
extra_link_args=['-lgomp']
elif comp == 'msvc':
extra_compile_args = ['/Ox']
extra_link_args = []
extra_compile_args.append('/openmp')
else:
# Add support for more compilers here
raise ValueError('Compiler flags undefined for %s. Please modify setup.py and add compiler flags'
% comp)
self.extensions[0].extra_compile_args = extra_compile_args
self.extensions[0].extra_link_args = extra_link_args
build_ext.build_extensions(self)
def finalize_options(self):
'''
In order to avoid premature import of numpy before it gets installed as a dependency
get numpy include directories during the extensions building process
http://stackoverflow.com/questions/19919905/how-to-bootstrap-numpy-installation-in-setup-py
'''
build_ext.finalize_options(self)
# Prevent numpy from thinking it is still in its setup process:
set_builtin('__NUMPY_SETUP__', False)
import numpy
self.include_dirs.append(numpy.get_include())
setup(
ext_modules=cythonize(ext_modules),
cmdclass={
'build_ext': build_ext_subclass
}
)