-
Notifications
You must be signed in to change notification settings - Fork 26
/
setup.py
91 lines (78 loc) · 2.56 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
#!/usr/bin/env python
import sys
from setuptools import setup, Extension
from distutils.errors import DistutilsError
from setuptools.command.build_py import build_py as _build
from setuptools.command.develop import develop as _develop
import subprocess as sp
import os, sys
# Get numpy include directory (works across versions)
import numpy
try:
numpy_include = numpy.get_include()
except AttributeError:
numpy_include = numpy.get_numpy_include()
c_compile_args=''
if '--enable-fftw-pthreads' in sys.argv:
sys.argv.pop(sys.argv.index('--enable-fftw-pthreads'))
FFTW_LIBS = ['fftw3', 'fftw3_threads', 'pthread']
c_compile_args+='--enable-fftw-pthreads '
else:
FFTW_LIBS = ['fftw3', 'fftw3_omp']
if '--disable-openmp' in sys.argv:
sys.argv.pop(sys.argv.index('--disable-openmp'))
USE_OPENMP = False
c_compile_args+='--disable-openmp '
else:
USE_OPENMP = True
libs = ['cfitsio', 'gsl', 'gslcblas', 'm'] + FFTW_LIBS
use_icc = False
if use_icc:
extra = []
if USE_OPENMP:
libs += ['gomp', 'iomp5']
extra += ['-openmp']
else:
extra = ['-O4']
if USE_OPENMP:
libs += ['gomp']
extra += ['-fopenmp']
def _compile_libchealpix():
if not os.path.exists('_deps/lib/libchealpix.a'):
try:
sp.check_call('./scripts/install_libchealpix.sh',
shell=True)
except:
raise DistutilsError('Failed to install libchealpix.')
def _compile_libnmt():
if not os.path.exists('_deps/lib/libnmt.a'):
try:
sp.check_call('./scripts/install_libnmt.sh ' +
c_compile_args, shell=True)
except:
raise DistutilsError('Failed to compile C library.')
class build(_build):
"""Specialized Python source builder."""
def run(self):
_compile_libchealpix()
_compile_libnmt()
_build.run(self)
class develop(_develop):
"""Specialized Python develop mode."""
def run(self):
_compile_libchealpix()
_compile_libnmt()
_develop.run(self)
_nmtlib = Extension("_nmtlib",
["pymaster/namaster_wrap.c"],
extra_objects=["./_deps/lib/libnmt.a", "./_deps/lib/libchealpix.a"],
libraries=libs,
library_dirs=["./_deps/lib/"],
include_dirs=[numpy_include, "./src/","./_deps/include/"],
extra_compile_args=extra,
extra_link_args=extra
)
setup(
cmdclass={'build_py': build, 'develop': develop},
ext_modules=[_nmtlib],
)