-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
57 lines (47 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
50
51
52
53
54
55
56
57
from setuptools import setup, Extension
from setuptools.command.build_ext import build_ext
import sys
import os
import subprocess
import platform
class CMakeExtension(Extension):
def __init__(self, name, sourcedir=""):
Extension.__init__(self, name, sources=[])
self.sourcedir = os.path.abspath(sourcedir)
class CMakeBuild(build_ext):
def build_extension(self, ext):
extdir = os.path.abspath(os.path.dirname(self.get_ext_fullpath(ext.name)))
build_temp = os.path.join(self.build_temp, "build")
if not os.path.exists(build_temp):
os.makedirs(build_temp)
# Ensure proper slashes for Windows
extdir = extdir.replace("\\", "/")
cmake_args = [
f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={extdir}",
f"-DPYTHON_EXECUTABLE={sys.executable}",
"-DCMAKE_BUILD_TYPE=Release"
]
build_args = ["--config", "Release"]
env = os.environ.copy()
if platform.system() == "Windows":
build_args += ["--", "/m"]
else:
build_args += ["--", "-j2"]
if not os.path.exists(build_temp):
os.makedirs(build_temp)
subprocess.check_call(
["cmake", ext.sourcedir] + cmake_args,
cwd=build_temp,
env=env
)
subprocess.check_call(
["cmake", "--build", "."] + build_args,
cwd=build_temp,
env=env
)
setup(
packages=["toposolve"],
package_dir={"": "src"},
ext_modules=[CMakeExtension("toposolve._toposolve")],
cmdclass={"build_ext": CMakeBuild},
)