-
Notifications
You must be signed in to change notification settings - Fork 45
/
setup.py
83 lines (60 loc) · 2.25 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
# Copyright (c) 2020, Yung-Yu Chen <[email protected]>
# BSD-style license; see COPYING
import pathlib
import subprocess
from setuptools import setup, Extension
from setuptools.command.build_ext import build_ext
# Taken from https://stackoverflow.com/a/48015772
class CMakeExtension(Extension):
def __init__(self, name, **kwa):
super().__init__(name, sources=[])
class cmake_build_ext(build_ext):
user_options = build_ext.user_options + [
('cmake-args=', None, 'arguments to cmake'),
('make-args=', None, 'arguments to make'),
]
def initialize_options(self):
super().initialize_options()
self.cmake_args = ''
self.make_args = ''
def finalize_options(self):
super().finalize_options()
def run(self):
for ext in self.extensions:
self.build_cmake(ext)
super().run()
def build_cmake(self, ext):
cwd = pathlib.Path().absolute()
build_temp = pathlib.Path(self.build_temp)
build_temp.mkdir(parents=True, exist_ok=True)
extdir = pathlib.Path(self.get_ext_fullpath(ext.name)).parent
extdir.mkdir(parents=True, exist_ok=True)
local_cmake_args = '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={}'.format(
str(extdir.absolute()))
cmd = 'cmake {} {} {}'.format(cwd, local_cmake_args, self.cmake_args)
proc = subprocess.run(cmd, shell=True, cwd=str(build_temp))
if 0 != proc.returncode:
raise RuntimeError('{} return {}'.format(cmd, proc.returncode))
target_name = ext.name.split('.')[-1]
cmd = 'make {} {}'.format(target_name, self.make_args)
proc = subprocess.run(cmd, shell=True, cwd=str(build_temp))
if 0 != proc.returncode:
raise RuntimeError('{} return {}'.format(cmd, proc.returncode))
def main():
setup(
name="modmesh",
version="0.0",
packages=[
'modmesh',
'modmesh.onedim',
'modmesh.app',
'modmesh.gui',
'modmesh.pilot',
'modmesh.pilot.airfoil',
],
ext_modules=[CMakeExtension("_modmesh")],
cmdclass={'build_ext': cmake_build_ext},
)
if __name__ == '__main__':
main()
# vim: set ff=unix fenc=utf8 et sw=4 ts=4 sts=4: