-
Notifications
You must be signed in to change notification settings - Fork 16
/
setup.py
75 lines (63 loc) · 2.77 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
import os
import sys
import shutil
import subprocess
from setuptools import setup, Extension
from setuptools.command.build_ext import build_ext
class CMakeExtension(Extension):
def __init__(self, name, sourcedir=''):
super().__init__(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(self.build_lib)
cfg = 'Debug' if self.debug else 'Release'
cpu_count = os.cpu_count()
build_args = ['--config', cfg, '-j', str(cpu_count)]
print("Building signalflow version " + self.distribution.get_version())
print("Detected %d CPUs" % os.cpu_count())
cmake_args = [
'-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=' + extdir,
'-DCMAKE_BUILD_PYTHON=1',
'-DCMAKE_BUILD_TYPE=' + cfg,
'-DSIGNALFLOW_VERSION=' + self.distribution.get_version()
]
if 'CMAKE_OSX_ARCHITECTURES' in os.environ:
cmake_args += ['-DCMAKE_OSX_ARCHITECTURES=%s' % os.environ['CMAKE_OSX_ARCHITECTURES']]
env = os.environ.copy()
if not os.path.exists(self.build_temp):
os.makedirs(self.build_temp)
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)
# --------------------------------------------------------------------------------
# On Windows, bundle the .pyd into a package.
# This will also contain the .dlls after repairing the wheel with delvewheel.
# --------------------------------------------------------------------------------
if os.name == "nt":
libname = "signalflow.pyd"
shutil.copy(os.path.join(self.build_temp, cfg, libname), "auxiliary/libs/signalflow")
signalflow_packages = [
'signalflow-stubs',
'signalflow_midi',
'signalflow_cli',
'signalflow_examples',
'signalflow_visualisation',
'signalflow_analysis',
]
signalflow_package_data = []
if sys.platform == 'win32':
# --------------------------------------------------------------------------------
# On Linux and macOS, the bare .so file is packaged directly via ext_modules.
# On Windows, a separate package is created, into which the .pyd file and DLLs
# are copied.
# --------------------------------------------------------------------------------
signalflow_packages = ['signalflow'] + signalflow_packages
signalflow_package_data = ['*.pyd']
setup(
packages=signalflow_packages,
ext_modules=[CMakeExtension('signalflow')],
cmdclass=dict(build_ext=CMakeBuild),
)