forked from jwiggins/blend2d-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
84 lines (72 loc) · 2.91 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
import os
import os.path as op
import platform
import subprocess
import sys
from setuptools import setup, Extension
from setuptools.command.build_ext import build_ext
# Set to 'Release' when building a release
BUILD_TYPE = "Release"
class CMakeExtension(Extension):
def __init__(self, name, cmake_lists_dir=".", sources=None, **kwa):
sources = [] if sources is None else sources
Extension.__init__(self, name, sources=sources, **kwa)
self.cmake_lists_dir = os.path.abspath(cmake_lists_dir)
class cmake_build_ext(build_ext):
def build_extensions(self):
try:
subprocess.check_output(["cmake", "--version"])
except OSError:
raise RuntimeError("Cannot find CMake executable")
for ext in self.extensions:
extpath = self.get_ext_fullpath(ext.name)
extdir = op.abspath(op.dirname(extpath))
extfile = op.splitext(op.basename(extpath))[0]
tmpdir = self.build_temp
cmake_args = [
"-DBLEND2D_STATIC=TRUE",
"-DBLEND2DPY_TARGET_NAME={}".format(extfile),
"-DCMAKE_BUILD_TYPE={}".format(BUILD_TYPE),
"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{}={}".format(
BUILD_TYPE.upper(), extdir
),
"-DCMAKE_ARCHIVE_OUTPUT_DIRECTORY_{}={}".format(
BUILD_TYPE.upper(), extdir
),
"-DPYTHON_EXECUTABLE={}".format(sys.executable),
]
if platform.system() == "Windows":
plat = "x64" if platform.architecture()[0] == "64bit" else "Win32"
cmake_args += [
"-DCMAKE_WINDOWS_EXPORT_ALL_SYMBOLS=TRUE",
"-DCMAKE_RUNTIME_OUTPUT_DIRECTORY_{}={}".format(
BUILD_TYPE.upper(), extdir
),
]
if self.compiler.compiler_type == "msvc":
cmake_args += [
"-DCMAKE_GENERATOR_PLATFORM={}".format(plat),
]
else:
cmake_args += [
"-G",
"MinGW Makefiles",
]
elif platform.system() == "Linux":
cmake_args += [
"-DCMAKE_C_FLAGS=-fPIC",
"-DCMAKE_CXX_FLAGS=-fPIC",
]
if not op.exists(tmpdir):
os.makedirs(tmpdir)
# Config and build the extension
cmd = ["cmake", ext.cmake_lists_dir] + cmake_args
subprocess.check_call(cmd, cwd=tmpdir)
cmd = ["cmake", "--build", ".", "--config", BUILD_TYPE]
subprocess.check_call(cmd, cwd=tmpdir)
if __name__ == "__main__":
# See setup.cfg for package metadata
setup(
ext_modules=[CMakeExtension("blend2d._capi")],
cmdclass={"build_ext": cmake_build_ext},
)