-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup.py
49 lines (39 loc) · 1.61 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
import os
import sys
import platform
import subprocess
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):
try:
subprocess.check_output(['cmake', '--version'])
except OSError:
raise RuntimeError("CMake must be installed to build this extension")
for ext in self.extensions:
self.build_extension(ext)
def build_extension(self, ext):
extdir = os.path.abspath(os.path.dirname(self.get_ext_fullpath(ext.name)))
cmake_args = [
f'-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={extdir}',
f'-DPYTHON_EXECUTABLE={sys.executable}',
f'-DCMAKE_BUILD_TYPE={"Debug" if self.debug else "Release"}'
]
build_args = ['--config', 'Debug' if self.debug else 'Release']
if platform.system() == "Windows":
cmake_args += ['-A', 'x64'] if sys.maxsize > 2**32 else []
build_args += ['--', '/m']
else:
build_args += ['--', '-j2']
build_temp = os.path.join(self.build_temp, ext.name)
os.makedirs(build_temp, exist_ok=True)
subprocess.check_call(['cmake', ext.sourcedir] + cmake_args, cwd=build_temp)
subprocess.check_call(['cmake', '--build', '.'] + build_args, cwd=build_temp)
setup(
ext_modules=[CMakeExtension('nnpycgal/nnpycgal')],
cmdclass={'build_ext': CMakeBuild},
)