forked from bonfus/muLFC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
104 lines (87 loc) · 2.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
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
#!/usr/bin/env python
import sys
from os import path
from setuptools import setup, Extension
from setuptools.command.build_ext import build_ext
desc = """Local Field Components (or lighting fast calculator) at
muon sites for the muesr package."""
with open('README.md','r') as file:
long_desc = file.read()
# ugly hack to keep tests under the python folder
sys.path.insert(0, path.join(path.dirname(__file__),'python'))
sources = ['simplesum.c', \
'rotatesum.c', \
'fastincommsum.c', \
'vec3.c', \
'mat3.c', \
'pile.c', \
'dipolartensor.c']
src_sources = []
for s in sources:
src_sources.append(
path.join('.','src',s)
)
openmp_compile_args = []
openmp_link_args = []
## In case of missing numpy array headers
try:
from numpy import get_include as numpy_get_include
numpy_include_dir = [numpy_get_include()]
except:
numpy_include_dir = []
print("Warning: could not add numpy include dir.")
# Ugly hack to set compiler flags
COMPILE_ARGS = {'msvc':[],'gcc':[],'unix':[]}
LINK_ARGS = {'msvc':[],'gcc':[],'unix':[]}
for compiler, args in [
('msvc', ['/EHsc', '/DHUNSPELL_STATIC']),
('gcc', ['-O3', '-g0']),
('unix', ['-O3', '-g0'])]:
COMPILE_ARGS[compiler] += args
# add math lib if needed
for compiler, args in [
('msvc', []),
('unix', ['-lm']),
('gcc', ['-lm'])]:
LINK_ARGS[compiler] += args
# Ugly hack to have openMP as option
if "--with-openmp" in sys.argv:
for compiler, args in [
('msvc', ['/openmp']),
('unix', ['-fopenmp']),
('gcc', ['-fopenmp'])]:
COMPILE_ARGS[compiler] += args
for compiler, args in [
('msvc', []),
('unix', ['-lgomp']),
('gcc', ['-lgomp'])]:
LINK_ARGS[compiler] += args
sys.argv.remove("--with-openmp")
class build_ext_compiler_check(build_ext):
def build_extensions(self):
compiler = self.compiler.compiler_type
cargs = COMPILE_ARGS[compiler]
for ext in self.extensions:
ext.extra_compile_args = cargs
largs = LINK_ARGS[compiler]
for ext in self.extensions:
ext.extra_link_args = largs
build_ext.build_extensions(self)
setup(name='mulfc',
version='0.0.2',
description=desc,
long_description=long_desc,
author='Pietro Bonfa',
author_email='[email protected]',
url='https://github.com/bonfus/muLFC',
packages=['mulfc',],
ext_modules=[Extension('lfclib', sources = ['python/lfclib.c',]+src_sources,
libraries=[],
include_dirs=numpy_include_dir + [path.join('.','src')])],
package_dir={'mulfc': 'python' },
install_requires=[
'numpy >= 1.8',
],
test_suite="tests",
cmdclass={ 'build_ext': build_ext_compiler_check }
)