|
1 | | -#The template of this setup.py is taken from pybind github (https://github.com/pybind/python_example) |
2 | | -from setuptools import setup, Extension |
3 | 1 | from setuptools.command.build_ext import build_ext |
| 2 | +from distutils.core import setup, Extension |
4 | 3 | import sys |
5 | | -import setuptools |
6 | 4 | from sysconfig import get_config_var, get_paths |
| 5 | +import logging |
7 | 6 |
|
| 7 | +__version__ = '0.0.1dev' |
8 | 8 |
|
9 | | -__version__ = '0.0.0' |
10 | 9 |
|
11 | | -def get_include(): #TODO |
12 | | - info = get_paths() |
13 | | - Eigen_path = info['include']+'/../eigen3' |
14 | | - return Eigen_path |
| 10 | +def get_include(): # TODO |
| 11 | + info = get_paths() |
| 12 | + Eigen_path = '/'.join(info['include'].split('/')[:-1]) |
| 13 | + Eigen_path += '/eigen3' |
| 14 | + return Eigen_path |
15 | 15 |
|
16 | | -KR_module = [ |
17 | | - Extension( |
18 | | - 'KRBalancing', |
19 | | - ['src/KRBalancing.cpp'], |
20 | | - include_dirs=[ |
21 | | - # Path to eigen3 headers |
22 | | - get_include(), |
23 | | - ], |
24 | | - language='c++', |
25 | | - extra_compile_args=["-fopenmp"], |
26 | | - extra_link_args=["-fopenmp"] |
27 | | - ) |
28 | | -] |
29 | 16 |
|
| 17 | +sources_list = ['src/KRBalancing.cpp'] |
30 | 18 |
|
31 | | -# As of Python 3.6, CCompiler has a `has_flag` method. |
32 | | -# cf http://bugs.python.org/issue26689 |
33 | | -def has_flag(compiler, flagname): |
34 | | - """Return a boolean indicating whether a flag name is supported on |
35 | | - the specified compiler. |
36 | | - """ |
37 | | - import tempfile |
38 | | - with tempfile.NamedTemporaryFile('w', suffix='.cpp') as f: |
39 | | - f.write('int main (int argc, char **argv) { return 0; }') |
40 | | - try: |
41 | | - compiler.compile([f.name], extra_postargs=[flagname]) |
42 | | - except setuptools.distutils.errors.CompileError: |
43 | | - return False |
44 | | - return True |
| 19 | +kr_module = Extension('KRBalancing', |
| 20 | + sources=sources_list, |
| 21 | + include_dirs=[ |
| 22 | + # Path to eigen3 headers |
| 23 | + get_include() |
| 24 | + ], |
| 25 | + extra_link_args=["-lgomp", "-lm", "-lrt"], |
| 26 | + extra_compile_args=["-fopenmp", "-std=c++11"] |
| 27 | + ) |
45 | 28 |
|
46 | 29 |
|
47 | | -def cpp_flag(compiler): |
48 | | - """Return the -std=c++[11/14] compiler flag. |
49 | | - The c++14 is prefered over c++11 (when it is available). |
50 | | - """ |
51 | | - if has_flag(compiler, '-std=c++14'): |
52 | | - return '-std=c++14' |
53 | | - elif has_flag(compiler, '-std=c++11'): |
54 | | - return '-std=c++11' |
55 | | - else: |
56 | | - raise RuntimeError('Unsupported compiler -- at least C++11 support ' |
57 | | - 'is needed!') |
58 | | - |
59 | | - |
60 | | -class BuildExt(build_ext): |
61 | | - """A custom build extension for adding compiler-specific options.""" |
62 | | - c_opts = { |
63 | | - 'msvc': ['/EHsc'], |
64 | | - 'unix': [], |
65 | | - } |
66 | | - |
67 | | - if sys.platform == 'darwin': |
68 | | - c_opts['unix'] += ['-stdlib=libc++', '-mmacosx-version-min=10.7'] |
69 | | - |
70 | | - def build_extensions(self): |
71 | | - ct = self.compiler.compiler_type |
72 | | - opts = self.c_opts.get(ct, []) |
73 | | - if ct == 'unix': |
74 | | - opts.append('-DVERSION_INFO="%s" ' % self.distribution.get_version()) |
75 | | - opts.append(cpp_flag(self.compiler)) |
76 | | - if has_flag(self.compiler, '-fvisibility=hidden'): |
77 | | - opts.append('-fvisibility=hidden') |
78 | | - elif ct == 'msvc': |
79 | | - opts.append('/DVERSION_INFO=\\"%s\\"' % self.distribution.get_version()) |
80 | | - for ext in self.extensions: |
81 | | - ext.extra_compile_args = opts |
82 | | - build_ext.build_extensions(self) |
83 | | - |
84 | 30 | setup( |
85 | 31 | name='KRBalancing', |
86 | 32 | version=__version__, |
87 | 33 | author='Leily Rabbani', |
88 | 34 | |
89 | 35 | description='A c++ extension for python to balance a matrix using KR method', |
90 | | - ext_modules=KR_module, |
91 | | - install_requires=['pybind11>=2.2'], |
92 | | - cmdclass={'build_ext': BuildExt}, |
93 | | - zip_safe=False, |
| 36 | + ext_modules=[kr_module], |
| 37 | + install_requires=['pybind11>=2.2'] |
94 | 38 | ) |
0 commit comments