-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
107 lines (91 loc) · 2.86 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
105
106
107
#! /usr/bin/env python
import os
import platform
import subprocess
import multiprocessing
from setuptools import setup, Extension
from setuptools.command.build_ext import build_ext
def read_version(
header_file='./include/info.h'
):
version = "0.0.0"
with open(header_file, "r") as fp:
for line in fp.readlines():
if "#define" in line and "FIT2X_VERSION" in line:
version = line.split()[-1]
return version.replace('"', '')
NAME = "fit2x"
VERSION = read_version()
LICENSE = 'Mozilla Public License 2.0 (MPL 2.0)'
class CMakeExtension(Extension):
def __init__(self, name, sourcedir=''):
Extension.__init__(self, name, sources=[])
self.sourcedir = os.path.abspath(sourcedir)
class CMakeBuild(build_ext):
def run(self):
for ext in self.extensions:
self.build_extension(ext)
def build_extension(self, ext):
extdir = os.path.abspath(
os.path.dirname(
self.get_ext_fullpath(ext.name)
)
).replace('\\', '/')
cmake_args = [
'-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=' + extdir,
'-DCMAKE_SWIG_OUTDIR=' + extdir
]
cfg = 'Debug' if self.debug else 'Release'
build_args = ['--config', cfg]
cmake_args += ['-DCMAKE_BUILD_TYPE=' + cfg]
if platform.system() == "Windows":
cmake_args += [
'-DBUILD_PYTHON_INTERFACE=ON',
'-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{}={}'.format(cfg.upper(), extdir),
'-GVisual Studio 14 2015 Win64'
]
else:
build_args += [
'--',
'-j%s' % int(multiprocessing.cpu_count() * 1.5)
]
env = os.environ.copy()
if not os.path.exists(self.build_temp):
os.makedirs(self.build_temp)
print("BUILDING::CMAKE: " + " ".join(cmake_args))
subprocess.check_call(
['cmake', ext.sourcedir] + cmake_args,
cwd=self.build_temp,
env=env
)
subprocess.check_call(
['cmake', '--build', '.'] + build_args,
cwd=self.build_temp
)
setup(
name=NAME,
version=VERSION,
license=LICENSE,
author='Thomas-Otavio Peulen',
author_email='thomas.otavio.peulen@gmail.com',
ext_modules=[
CMakeExtension('fit2x')
],
cmdclass={
'build_ext': CMakeBuild
},
install_requires=[
'numpy'
],
zip_safe=False,
classifiers=[
'Development Status :: 2 - Pre-Alpha',
'Intended Audience :: Science/Research',
'License :: OSI Approved :: MIT License',
'Natural Language :: English',
'Operating System :: Microsoft :: Windows',
'Operating System :: POSIX :: Linux',
'Programming Language :: Python',
'Topic :: Scientific/Engineering',
]
)