-
Notifications
You must be signed in to change notification settings - Fork 38
/
setup.py
62 lines (48 loc) · 1.41 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
import os
import subprocess
from setuptools import setup, Extension
from setuptools.command.build_ext import build_ext
cwd = os.getcwd()
WINDOWS = (os.name == 'nt')
buildFolder = "build"
nativeSources = os.path.join(cwd, "pythonfmu", "pythonfmu-export")
class CMakeExtension(Extension):
def __init__(self, name):
super().__init__(name, sources=[])
class CMakeBuild(build_ext):
def run(self):
for ext in self.extensions:
self.build_extension(ext)
super().run()
def build_extension(self, ext):
os.chdir(nativeSources)
if not os.path.exists(buildFolder):
os.mkdir(buildFolder)
build_type = 'Release'
# configure
cmake_args = [
'cmake',
'.',
'-B',
buildFolder,
'-DCMAKE_BUILD_TYPE={}'.format(build_type),
]
if WINDOWS:
cmake_args.extend(['-A', 'x64'])
subprocess.check_call(cmake_args)
cmake_args_build = [
'cmake',
'--build',
buildFolder
]
if WINDOWS:
cmake_args_build.extend(['--config', 'Release'])
subprocess.check_call(cmake_args_build)
os.chdir(cwd)
def binary_suffix():
return ".exe" if WINDOWS else ""
# See setup.cfg for Python package parameters
setup(
ext_modules=[CMakeExtension('.')],
cmdclass=dict(build_ext=CMakeBuild)
)