-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathsetup.py
94 lines (74 loc) · 2.76 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
84
85
86
87
88
89
90
91
92
93
94
import os
import pathlib
import sys
from setuptools import setup, Extension
from setuptools.command.build_ext import build_ext as build_ext_orig
class CMakeExtension(Extension):
def __init__(self, name):
super().__init__(name, sources=[])
class build_ext(build_ext_orig):
user_options = build_ext_orig.user_options + \
[('generator=', None, 'The CMake generator to use.'),
('opengl=', None, 'Whether to build with OpenGL visualization.'),
('examples=', None, 'Whether to build examples.')]
def initialize_options(self):
super().initialize_options()
self.generator = None
self.opengl = "OFF"
self.examples = "OFF"
def finalize_options(self):
super().finalize_options()
self.generator = self.distribution.get_command_obj('build_ext').generator
self.opengl = self.distribution.get_command_obj('build_ext').opengl
self.examples = self.distribution.get_command_obj('build_ext').examples
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))
extdir.mkdir(parents=True, exist_ok=True)
# Config
config = 'Debug' if self.debug else 'Release'
cmake_args = [
'-DCMAKE_BUILD_TYPE=' + config,
]
# OpenGL
cmake_args.append('-DOPENGL_VISUALIZATION=' + self.opengl)
# Examples
cmake_args.append('-DBUILD_EXAMPLES=' + self.examples)
# Output Directory
if sys.platform == 'win32':
cmake_args.extend([
'-DCMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG=' + str(extdir.parent.absolute()),
'-DCMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE=' + str(extdir.parent.absolute())
])
else:
cmake_args.extend([
'-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=' + str(extdir.parent.absolute())
])
# Generator
if self.generator is not None:
cmake_args.append('-G' + self.generator)
build_args = [
'--config', config,
'--parallel', '8',
]
os.chdir(str(build_temp))
self.spawn(['cmake', str(cwd)] + cmake_args)
if not self.dry_run:
self.spawn(['cmake', '--build', '.'] + build_args)
os.chdir(str(cwd))
setup(
name='ggems',
version='1.2',
packages=['ggems'],
package_dir={'ggems': 'python_module'},
ext_modules=[CMakeExtension('.')],
cmdclass={
'build_ext': build_ext,
}
)