-
-
Notifications
You must be signed in to change notification settings - Fork 22
/
setup.py
57 lines (43 loc) · 1.69 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
import os
import pathlib
from setuptools import setup, Extension
from setuptools.command.build_ext import build_ext
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:
if isinstance(ext, CMakeExtension):
self.build_cmake(ext)
super().run()
def build_cmake(self, ext):
cwd = pathlib.Path().absolute()
build_temp = f"{pathlib.Path(self.build_temp)}/{ext.name}"
os.makedirs(build_temp, exist_ok=True)
extdir = pathlib.Path(self.get_ext_fullpath(ext.name))
extdir.mkdir(parents=True, exist_ok=True)
config = "Debug" if self.debug else "Release"
cmake_args = [
"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=" + str(extdir.parent.absolute()),
"-DCMAKE_BUILD_TYPE=" + config, "-DBUILD_PYTHON=ON",
"-DBUILD_SAMPLE=OFF", "-DENGINE_NCNN_WASM=OFF",
"-DC_API=OFF", "-DBUILD_LUA=OFF", "-DOPENCV_HAS_FREETYPE=OFF",
"-DENGINE_MNN=ON", "-DENGINE_ORT=ON", "-DENGINE_NCNN=ON",
"-DENGINE_TNN=ON", "-DENGINE_OPV=ON", "-DENGINE_PPLite=ON"
]
build_args = [
"--config", config,
"--", "-j8"
]
os.chdir(build_temp)
self.spawn(["cmake", f"{str(cwd)}/{ext.name}"] + cmake_args)
if not self.dry_run:
self.spawn(["cmake", "--build", "."] + build_args)
os.chdir(str(cwd))
setup(
ext_modules=[CMakeExtension('.')],
cmdclass=dict(build_ext=CMakeBuild),
include_package_data=True
)