-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
139 lines (116 loc) · 3.06 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import os
import sys
import subprocess
from glob import glob
from Cython.Build import cythonize
from setuptools import Extension, setup
from setuptools.command.build_ext import build_ext as _build_ext
# options
release = False
build_libs = False
annotate = False
force = False
quiet = False
# build_ext from cmake
# cmake -E make_directory build
# cmake -E chdir build cmake ..
# cmake --build build
class build_ext(_build_ext):
def run(self):
self.build_cmake()
super().run()
def build_cmake(self):
cwd = os.getcwd()
env = os.environ.copy()
print(self.build_temp)
subprocess.check_call(
["cmake", "-E", "make_directory", self.build_temp],
env=env,
)
subprocess.check_call(
["cmake", "-E", "chdir", self.build_temp, "cmake", cwd],
env=env,
)
subprocess.check_call(
["cmake", "--build", self.build_temp],
env=env,
)
os.environ["CC"] = "clang"
# general --------------------------------------
files = []
for dirpath, _, filenames in os.walk("cyclone"):
for filename in filenames:
if filename.endswith("pyx"):
ext_path = os.path.join(dirpath, filename)
ext_name = ext_path.replace("/", ".").replace(".pyx", "")
files.append((ext_name, ext_path))
include_dirs = [
"deps/glfw/include",
"deps/glad/include",
"deps/cglm/include",
"deps/stb",
"deps/freetype/include",
"deps/freetype/include/freetype",
]
library_dirs = [
"lib",
]
runtime_library_dirs = [
sys.prefix + "/lib", # for non-editable install
os.getcwd() + "/lib", # for editable install
]
libraries = [
"glfw",
"glad",
"freetype",
]
macros = [
("STB_IMAGE_IMPLEMENTATION", None),
("CGLM_DEFINE_PRINTS", None),
("CFF_CONFIG_OPTION_OLD_ENGINE", None),
]
# compiler -------------------------------------
language = "c++"
debug_args = ["-std=c++20", "-w", "-O0"]
release_args = ["-std=c++20", "-w", "-O3"]
if release:
args = release_args
else:
args = debug_args
# setup ----------------------------------------
extensions = []
for ext_name, ext_path in files:
ext = Extension(
name=ext_name,
sources=[ext_path],
include_dirs=include_dirs,
library_dirs=library_dirs,
libraries=libraries,
define_macros=macros,
runtime_library_dirs=runtime_library_dirs,
language=language,
extra_compile_args=args,
)
extensions.append(ext)
packages = [
"cyclone",
"cyclone.shaders",
]
package_data = {"cyclone.shaders": ["*"]}
data_files = [("lib", glob("lib/*"))]
setup(
name="cyclone",
version="0.1.0",
description="Python 2D Graphics Library",
ext_modules=cythonize(
module_list=extensions,
annotate=annotate,
compiler_directives={"language_level": "3"},
force=force,
quiet=quiet,
),
cmdclass={"build_ext": build_ext if build_libs else _build_ext},
packages=packages,
package_data=package_data,
data_files=data_files,
)