-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
72 lines (56 loc) · 2.4 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
import os
import platform
from setuptools import setup, Extension
from setuptools.command.build_ext import build_ext
import subprocess
import sys
PACKAGE_NAME = 'pose_extractor'
options = {'--debug': 'OFF'}
if '--debug' in sys.argv:
options['--debug'] = 'ON'
class CMakeExtension(Extension):
def __init__(self, name, cmake_lists_dir=PACKAGE_NAME, **kwargs):
Extension.__init__(self, name, sources=[], **kwargs)
self.cmake_lists_dir = os.path.abspath(cmake_lists_dir)
class CMakeBuild(build_ext):
def build_extensions(self):
try:
subprocess.check_output(['cmake', '--version'])
except OSError:
raise RuntimeError('Cannot find CMake executable')
ext = self.extensions[0]
build_dir = os.path.abspath(os.path.join(PACKAGE_NAME, 'build'))
if not os.path.exists(build_dir):
os.mkdir(build_dir)
tmp_dir = os.path.join(build_dir, 'tmp')
if not os.path.exists(tmp_dir):
os.mkdir(tmp_dir)
cfg = 'Debug' if options['--debug'] == 'ON' else 'Release'
cmake_args = [
'-DCMAKE_BUILD_TYPE={}'.format(cfg),
'-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{}={}'.format(cfg.upper(), build_dir),
'-DCMAKE_ARCHIVE_OUTPUT_DIRECTORY_{}={}'.format(cfg.upper(), tmp_dir),
'-DPYTHON_EXECUTABLE={}'.format(sys.executable)
]
if platform.system() == 'Windows':
platform_type = ('x64' if platform.architecture()[0] == '64bit' else 'Win32')
cmake_args += [
'-DCMAKE_WINDOWS_EXPORT_ALL_SYMBOLS=TRUE',
'-DCMAKE_RUNTIME_OUTPUT_DIRECTORY_{}={}'.format(cfg.upper(), build_dir),
]
if self.compiler.compiler_type == 'msvc':
cmake_args += [
'-DCMAKE_GENERATOR_PLATFORM={}'.format(platform_type),
]
else:
cmake_args += [
'-G', 'MinGW Makefiles',
]
subprocess.check_call(['cmake', ext.cmake_lists_dir] + cmake_args, cwd=tmp_dir)
subprocess.check_call(['cmake', '--build', '.', '--config', cfg], cwd=tmp_dir)
setup(name=PACKAGE_NAME,
packages=[PACKAGE_NAME],
version='1.0',
description='Auxiliary C++ module for fast 2d pose extraction from network output',
ext_modules=[CMakeExtension(PACKAGE_NAME)],
cmdclass={'build_ext': CMakeBuild})