Commit 3d8aeecee96c7b5b2de0a1623fa76b69426a60dc
1 parent
488f3810
Exists in
master
Simplified the setup.py
Showing
1 changed file
with
61 additions
and
92 deletions
Show diff stats
setup.py
1 | -from distutils.core import setup | ||
2 | -from distutils.extension import Extension | ||
3 | -from Cython.Distutils import build_ext | ||
4 | -from Cython.Build import cythonize | ||
5 | - | ||
6 | import os | 1 | import os |
7 | import sys | 2 | import sys |
3 | +from distutils.core import setup | ||
4 | +from distutils.extension import Extension | ||
8 | 5 | ||
9 | import numpy | 6 | import numpy |
7 | +from Cython.Build import cythonize | ||
8 | +from Cython.Distutils import build_ext | ||
10 | 9 | ||
11 | -if sys.platform.startswith('linux'): | ||
12 | - setup( | ||
13 | - cmdclass = {'build_ext': build_ext}, | ||
14 | - ext_modules = cythonize([ Extension("invesalius.data.mips", ["invesalius/data/mips.pyx"], | ||
15 | - include_dirs = [numpy.get_include()], | ||
16 | - extra_compile_args=['-fopenmp'], | ||
17 | - extra_link_args=['-fopenmp']), | ||
18 | - | ||
19 | - Extension("invesalius.data.interpolation", ["invesalius/data/interpolation.pyx"], | ||
20 | - include_dirs=[numpy.get_include()], | ||
21 | - extra_compile_args=['-fopenmp',], | ||
22 | - extra_link_args=['-fopenmp',]), | ||
23 | - | ||
24 | - Extension("invesalius.data.transforms", ["invesalius/data/transforms.pyx"], | ||
25 | - include_dirs=[numpy.get_include()], | ||
26 | - extra_compile_args=['-fopenmp',], | ||
27 | - extra_link_args=['-fopenmp',]), | ||
28 | - | ||
29 | - Extension("invesalius.data.floodfill", ["invesalius/data/floodfill.pyx"], | ||
30 | - include_dirs=[numpy.get_include()], | ||
31 | - language='c++',), | ||
32 | - | ||
33 | - Extension("invesalius.data.cy_mesh", ["invesalius/data/cy_mesh.pyx"], | ||
34 | - include_dirs=[numpy.get_include()], | ||
35 | - extra_compile_args=['-fopenmp', '-std=c++11'], | ||
36 | - extra_link_args=['-fopenmp', '-std=c++11'], | ||
37 | - language='c++',), | ||
38 | - ]) | ||
39 | - ) | ||
40 | - | ||
41 | -elif sys.platform == 'win32': | ||
42 | - setup( | ||
43 | - cmdclass = {'build_ext': build_ext}, | ||
44 | - ext_modules = cythonize([ Extension("invesalius.data.mips", ["invesalius/data/mips.pyx"], | ||
45 | - include_dirs = [numpy.get_include()], | ||
46 | - extra_compile_args=['/openmp'],), | ||
47 | - | ||
48 | - Extension("invesalius.data.interpolation", ["invesalius/data/interpolation.pyx"], | ||
49 | - include_dirs=[numpy.get_include()], | ||
50 | - extra_compile_args=['/openmp'],), | ||
51 | - | ||
52 | - Extension("invesalius.data.transforms", ["invesalius/data/transforms.pyx"], | ||
53 | - include_dirs=[numpy.get_include()], | ||
54 | - extra_compile_args=['/openmp'],), | ||
55 | - | ||
56 | - Extension("invesalius.data.floodfill", ["invesalius/data/floodfill.pyx"], | ||
57 | - include_dirs=[numpy.get_include()], | ||
58 | - language='c++',), | ||
59 | - | ||
60 | - Extension("invesalius.data.cy_mesh", ["invesalius/data/cy_mesh.pyx"], | ||
61 | - include_dirs=[numpy.get_include()], | ||
62 | - extra_compile_args=['/openmp',], | ||
63 | - language='c++',), | ||
64 | - ]) | ||
65 | - ) | ||
66 | - | ||
67 | -elif sys.platform == 'darwin': | ||
68 | - setup( | ||
69 | - packages=["invesalius", ], | ||
70 | - cmdclass = {'build_ext': build_ext}, | ||
71 | - ext_modules = cythonize([Extension("invesalius.data.mips", ["invesalius/data/mips.pyx"], | ||
72 | - include_dirs = [numpy.get_include()], | ||
73 | - extra_compile_args=['-Xpreprocessor', '-fopenmp', '-lomp'], | ||
74 | - extra_link_args=['-Xpreprocessor', '-fopenmp', '-lomp']), | ||
75 | - | ||
76 | - Extension("invesalius.data.interpolation", ["invesalius/data/interpolation.pyx"], | ||
77 | - include_dirs=[numpy.get_include()], | ||
78 | - extra_compile_args=['-Xpreprocessor', '-fopenmp', '-lomp'], | ||
79 | - extra_link_args=['-Xpreprocessor', '-fopenmp', '-lomp']), | ||
80 | - | ||
81 | - Extension("invesalius.data.transforms", ["invesalius/data/transforms.pyx"], | ||
82 | - include_dirs=[numpy.get_include()], | ||
83 | - extra_compile_args=['-Xpreprocessor', '-fopenmp', '-lomp'], | ||
84 | - extra_link_args=['-Xpreprocessor', '-fopenmp', '-lomp']), | ||
85 | - | ||
86 | - Extension("invesalius.data.floodfill", ["invesalius/data/floodfill.pyx"], | ||
87 | - include_dirs=[numpy.get_include()], | ||
88 | - language='c++',), | ||
89 | - | ||
90 | - Extension("invesalius.data.cy_mesh", ["invesalius/data/cy_mesh.pyx"], | ||
91 | - include_dirs=[numpy.get_include()], | ||
92 | - extra_compile_args=['-Xpreprocessor', '-fopenmp', '-lomp'], | ||
93 | - extra_link_args=['-Xpreprocessor', '-fopenmp', '-lomp'], | ||
94 | - language='c++',), | ||
95 | - | ||
96 | - ]) | ||
97 | - ) | 10 | +if sys.platform == 'darwin': |
11 | + unix_copt = ['-Xpreprocessor', '-fopenmp', '-lomp'] | ||
12 | + unix_lopt = ['-Xpreprocessor', '-fopenmp', '-lomp'] | ||
13 | +else: | ||
14 | + unix_copt = ['-fopenmp',] | ||
15 | + unix_lopt = ['-fopenmp',] | ||
16 | + | ||
17 | + | ||
18 | +copt = {"msvc": ["/openmp"], "mingw32": ["-fopenmp"], "unix": unix_copt} | ||
19 | + | ||
20 | +lopt = {"mingw32": ["-fopenmp"], "unix": unix_lopt} | ||
21 | + | ||
22 | + | ||
23 | +class build_ext_subclass(build_ext): | ||
24 | + def build_extensions(self): | ||
25 | + c = self.compiler.compiler_type | ||
26 | + print("Compiler", c) | ||
27 | + if c in copt: | ||
28 | + for e in self.extensions: | ||
29 | + e.extra_compile_args = copt[c] | ||
30 | + if c in lopt: | ||
31 | + for e in self.extensions: | ||
32 | + e.extra_link_args = lopt[c] | ||
33 | + for e in self.extensions: | ||
34 | + e.include_dirs = [numpy.get_include()] | ||
35 | + build_ext.build_extensions(self) | ||
36 | + | ||
37 | + | ||
38 | +setup( | ||
39 | + cmdclass={"build_ext": build_ext_subclass}, | ||
40 | + ext_modules=cythonize( | ||
41 | + [ | ||
42 | + Extension( | ||
43 | + "invesalius.data.mips", | ||
44 | + ["invesalius/data/mips.pyx"], | ||
45 | + ), | ||
46 | + Extension( | ||
47 | + "invesalius.data.interpolation", | ||
48 | + ["invesalius/data/interpolation.pyx"], | ||
49 | + ), | ||
50 | + Extension( | ||
51 | + "invesalius.data.transforms", | ||
52 | + ["invesalius/data/transforms.pyx"], | ||
53 | + ), | ||
54 | + Extension( | ||
55 | + "invesalius.data.floodfill", | ||
56 | + ["invesalius/data/floodfill.pyx"], | ||
57 | + language="c++", | ||
58 | + ), | ||
59 | + Extension( | ||
60 | + "invesalius.data.cy_mesh", | ||
61 | + ["invesalius/data/cy_mesh.pyx"], | ||
62 | + language="c++", | ||
63 | + ), | ||
64 | + ] | ||
65 | + ), | ||
66 | +) |