-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
73 lines (61 loc) · 1.92 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
from distutils.core import setup
from Cython.Distutils import Extension
from Cython.Distutils import build_ext
import numpy
import os, tempfile, subprocess, shutil
# see http://openmp.org/wp/openmp-compilers/
omp_test = r"""#include <omp.h>
#include <stdio.h>
int main() {
#pragma omp parallel
printf("Hello from thread %d, nthreads %d\n", omp_get_thread_num(), omp_get_num_threads());
}
"""
def has_openmp():
tmpdir = tempfile.mkdtemp()
curdir = os.getcwd()
os.chdir(tmpdir)
filename = r'test.c'
file = open(filename,'w', 0)
file.write(omp_test)
with open(os.devnull, 'w') as fnull:
result = subprocess.call(['cc', '-fopenmp', filename], stdout=fnull,
stderr=fnull)
file.close
os.chdir(curdir)
#clean up
shutil.rmtree(tmpdir)
return result == 0
ceres_include = "/usr/local/include/ceres/"
ceres_lib = "/usr/local/lib/"
gflags_lib = "/usr/local/lib/"
glog_lib = "/usr/local/lib/"
cholmod_lib = amd_lib = camd_lib = colamd_lib = "/usr/local/lib/"
cxsparse_lib = "/usr/local/lib/"
extra_compile_args = ['-O3']
extra_link_args = []
if has_openmp():
extra_compile_args = ['-fopenmp']
extra_link_args = ['-lgomp']
ext_modules = [
Extension(
"cyres",
["cyres/src/cyres.pyx", "cyres/src/cyres.pxd", "cyres/src/ceres.pxd"],
language="c++",
include_dirs=[ceres_include, numpy.get_include()],
libraries=['ceres', 'gflags', 'glog', "cholmod", "camd", "amd", "colamd", "cxsparse"],
library_dirs=[ceres_lib, gflags_lib, glog_lib, cholmod_lib, amd_lib, camd_lib, colamd_lib, cxsparse_lib],
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args,
)
]
setup(
name = 'cyres',
version='0.0.1',
cmdclass = {'build_ext': build_ext},
ext_package = 'cyres',
ext_modules = ext_modules,
packages= ['cyres'],
package_data={'cyres': ['src/*.pxd']},
scripts=['scripts/cyresc']
)