-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathSConstruct
executable file
·211 lines (167 loc) · 5.34 KB
/
SConstruct
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#!python
env = Environment()
AddOption(
'--tovedebug',
action='store_true',
help='build for debugging',
default=False)
AddOption(
'--static',
action='store_true',
help='build static library',
default=False)
AddOption(
'--arch',
dest='arch',
type='string',
nargs=1,
action='store',
help='CPU architecture to use (e.g. sandybridge, haswell)',
default=None)
AddOption(
'--f16c',
action='store_true',
help='assume hardware support for 16-bit floating point numbers',
default=False)
sources = [
"src/cpp/version.cpp",
"src/cpp/interface/api.cpp",
"src/cpp/graphics.cpp",
"src/cpp/nsvg.cpp",
"src/cpp/paint.cpp",
"src/cpp/path.cpp",
"src/cpp/references.cpp",
"src/cpp/subpath.cpp",
"src/cpp/mesh/flatten.cpp",
"src/cpp/mesh/mesh.cpp",
"src/cpp/mesh/meshifier.cpp",
"src/cpp/mesh/partition.cpp",
"src/cpp/mesh/triangles.cpp",
"src/cpp/gpux/curve_data.cpp",
"src/cpp/gpux/geometry_data.cpp",
"src/cpp/gpux/geometry_feed.cpp",
"src/cpp/shader/gen.cpp",
"src/thirdparty/clipper.cpp",
"src/thirdparty/polypartition/src/polypartition.cpp",
"src/thirdparty/tinyxml2/tinyxml2.cpp",
"src/cpp/warn.cpp"]
if env["PLATFORM"] == 'win32':
env["CCFLAGS"] = ' /EHsc /std:c++17 '
if not GetOption('tovedebug'):
env["CCFLAGS"] += ' /Oi /Ot /Oy /Ob2 /GF /Gy /fp:fast '
# enabling /O2 (or /Og) will crash demos/retro for some reason.
# concering CPU architectures and AVX:
# by default, we do not specify a value for /arch - even though in theory, /arch:AVX should be
# fine for processors not older than 2011 (https://en.wikipedia.org/wiki/Advanced_Vector_Extensions),
# in practice setting AVX causes issues (see https://github.com/poke1024/tove2d/issues/24).
# for /arch:AVX2, we even need Haswell architectures.
# the main benefit for enabling AVX2 would probably be src/thirdparty/nanosvg/tove/svgrast.cpp,
# where various dithering operations are optimizable for SIMD (AVX can then be seen in asm code).
arch = GetOption('arch')
if arch == 'sandybridge':
env["CCFLAGS"] += ' /arch:AVX '
elif arch == 'haswell':
env["CCFLAGS"] += ' /arch:AVX2 '
elif arch is not None:
raise RuntimeError("please specify sandybridge or haswell for arch")
env["LINKFLAGS"] = ' /OPT:REF '
else:
env["CCFLAGS"] += ' /DEBUG:FULL '
env["LINKFLAGS"] = ' /DEBUG:FULL '
else:
# -Wreorder -Wunused-variable
CCFLAGS = ' -std=c++17 -fvisibility=hidden -funsafe-math-optimizations '
if GetOption('arch'):
CCFLAGS += ' -march=%s ' % GetOption('arch')
if GetOption('tovedebug'):
CCFLAGS += '-g '
else:
CCFLAGS += '-O3 '
if env["PLATFORM"] == 'posix' and GetOption('f16c'):
CCFLAGS += ' -mf16c '
if GetOption('f16c'):
CCFLAGS += ' -DTOVE_F16C=1 '
env["CCFLAGS"] = CCFLAGS
env["CPPPATH"] = "src/thirdparty/fp16/include"
# prepare git hash based version string.
import subprocess
import datetime
import traceback
import re
import os
import sys
def get_version_string():
try:
os.chdir(Dir('.').abspath)
args = ['git', 'describe', '--tags', '--long']
res = subprocess.check_output(args).strip()
if sys.version_info >= (3, 0):
res = res.decode("utf8")
return res
except:
print("failed to determine tove version.")
traceback.print_exc()
return "unknown"
with open("src/cpp/version.in.cpp", "r") as v_in:
with open("src/cpp/version.cpp", "w") as v_out:
v_out.write(v_in.read().replace("TOVE_VERSION", get_version_string()))
def minify_lua(target, source, env):
# glue together the lua library.
include_pattern = re.compile("\s*--!!\s*include\s*\"([^\"]+)\"\s*")
import_pattern = re.compile("\s*--!!\s*import\s*\"([^\"]+)\"\s*as\s*(\w+)\s*")
def lua_import(path):
source = []
basepath, _ = os.path.split(path)
filename, ext = os.path.splitext(path)
with open(path) as f:
lines = f.readlines()
for line in lines:
m = include_pattern.match(line)
if m:
included_path = os.path.join(basepath, m.group(1))
source.extend(lua_import(included_path))
continue
m = import_pattern.match(line)
if m:
imported_path = os.path.join(basepath, m.group(1))
source.append("local %s = (function()\n" % m.group(2))
source.extend(lua_import(imported_path))
source.append("end)()\n")
continue
if ext == ".lua" and (line.strip().startswith("-- ") or line.strip() == "--"):
line = None
if ext == ".h":
line = re.sub("^EXPORT ", "", line)
if line:
source.append(line)
return source
assert len(target) == 1
with open(target[0].abspath, "w") as f:
f.write("-- This file has been autogenerated. DO NOT CHANGE IT.\n--\n")
for s in source:
if os.path.split(s.abspath)[1] == "main.lua":
f.write("".join(lua_import(s.abspath)))
def package_sl(target, source, env):
with open(source[0].abspath, "r") as sl:
with open(target[0].abspath, "w") as out:
out.write('w << R"GLSL(\n')
out.write(sl.read())
out.write(')GLSL";\n')
env.Append(BUILDERS={
'MinifyLua':Builder(action=minify_lua),
'PackageSL':Builder(action=package_sl)})
env.PackageSL(
'src/glsl/fill.frag.inc',
Glob('src/glsl/fill.frag'))
env.PackageSL(
'src/glsl/line.vert.inc',
Glob('src/glsl/line.vert'))
if not GetOption('static'):
lib = env.SharedLibrary(target='tove/libTove', source=sources)
else:
lib = env.StaticLibrary(target="tove/libtove", source=sources)
env.MinifyLua('tove/init.lua',
Glob("src/cpp/interface/api.h") +
Glob("src/cpp/interface/types.h") +
Glob("src/lua/*.lua") +
Glob("src/lua/core/*.lua"))