summaryrefslogtreecommitdiff
path: root/modules/text_server_fb/gdextension_build/SConstruct
blob: de0a5499004f4549aa2103706a4646c3bdad4420 (plain)
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
212
213
#!/usr/bin/env python
import atexit
import os
import sys
import methods
import time

# For the reference:
# - CCFLAGS are compilation flags shared between C and C++
# - CFLAGS are for C-specific compilation flags
# - CXXFLAGS are for C++-specific compilation flags
# - CPPFLAGS are for pre-processor flags
# - CPPDEFINES are for pre-processor defines
# - LINKFLAGS are for linking flags

time_at_start = time.time()

env = SConscript("./godot-cpp/SConstruct")
env.__class__.disable_warnings = methods.disable_warnings

opts = Variables([], ARGUMENTS)
opts.Add(BoolVariable("freetype_enabled", "Use FreeType library", True))
opts.Add(BoolVariable("msdfgen_enabled", "Use MSDFgen library (require FreeType)", True))
opts.Add(BoolVariable("verbose", "Enable verbose output for the compilation", False))

opts.Update(env)

if not env["verbose"]:
    methods.no_verbose(sys, env)

# MSDFGEN
if env["msdfgen_enabled"] and env["freetype_enabled"]:
    env_msdfgen = env.Clone()
    env_msdfgen.disable_warnings()

    thirdparty_msdfgen_dir = "../../../thirdparty/msdfgen/"
    thirdparty_msdfgen_sources = [
        "core/Contour.cpp",
        "core/EdgeHolder.cpp",
        "core/MSDFErrorCorrection.cpp",
        "core/Projection.cpp",
        "core/Scanline.cpp",
        "core/Shape.cpp",
        "core/SignedDistance.cpp",
        "core/Vector2.cpp",
        "core/contour-combiners.cpp",
        "core/edge-coloring.cpp",
        "core/edge-segments.cpp",
        "core/edge-selectors.cpp",
        "core/equation-solver.cpp",
        "core/msdf-error-correction.cpp",
        "core/msdfgen.cpp",
        "core/rasterization.cpp",
        "core/render-sdf.cpp",
        "core/sdf-error-estimation.cpp",
        "core/shape-description.cpp",
    ]
    thirdparty_msdfgen_sources = [thirdparty_msdfgen_dir + file for file in thirdparty_msdfgen_sources]

    env_msdfgen.Append(CPPPATH=["../../../thirdparty/freetype/include", "../../../thirdparty/msdfgen"])
    env.Append(CPPPATH=["../../../thirdparty/msdfgen"])
    env.Append(CPPDEFINES=["MODULE_MSDFGEN_ENABLED"])

    lib = env_msdfgen.Library(
        f'msdfgen_builtin.{env["platform"]}.{env["target"]}.{env["arch_suffix"]}{env["LIBSUFFIX"]}',
        thirdparty_msdfgen_sources,
    )
    env.Append(LIBS=[lib])

# FreeType
if env["freetype_enabled"]:
    env_freetype = env.Clone()
    env_freetype.disable_warnings()

    thirdparty_freetype_dir = "../../../thirdparty/freetype/"
    thirdparty_freetype_sources = [
        "src/autofit/autofit.c",
        "src/base/ftbase.c",
        "src/base/ftbbox.c",
        "src/base/ftbdf.c",
        "src/base/ftbitmap.c",
        "src/base/ftcid.c",
        "src/base/ftdebug.c",
        "src/base/ftfstype.c",
        "src/base/ftgasp.c",
        "src/base/ftglyph.c",
        "src/base/ftgxval.c",
        "src/base/ftinit.c",
        "src/base/ftmm.c",
        "src/base/ftotval.c",
        "src/base/ftpatent.c",
        "src/base/ftpfr.c",
        "src/base/ftstroke.c",
        "src/base/ftsynth.c",
        "src/base/ftsystem.c",
        "src/base/fttype1.c",
        "src/base/ftwinfnt.c",
        "src/bdf/bdf.c",
        "src/bzip2/ftbzip2.c",
        "src/cache/ftcache.c",
        "src/cff/cff.c",
        "src/cid/type1cid.c",
        "src/gxvalid/gxvalid.c",
        "src/gzip/ftgzip.c",
        "src/lzw/ftlzw.c",
        "src/otvalid/otvalid.c",
        "src/pcf/pcf.c",
        "src/pfr/pfr.c",
        "src/psaux/psaux.c",
        "src/pshinter/pshinter.c",
        "src/psnames/psnames.c",
        "src/raster/raster.c",
        "src/sdf/sdf.c",
        "src/svg/svg.c",
        "src/smooth/smooth.c",
        "src/truetype/truetype.c",
        "src/type1/type1.c",
        "src/type42/type42.c",
        "src/winfonts/winfnt.c",
        "src/sfnt/sfnt.c",
    ]
    thirdparty_freetype_sources = [thirdparty_freetype_dir + file for file in thirdparty_freetype_sources]

    thirdparty_png_dir = "../../../thirdparty/libpng/"
    thirdparty_png_sources = [
        "png.c",
        "pngerror.c",
        "pngget.c",
        "pngmem.c",
        "pngpread.c",
        "pngread.c",
        "pngrio.c",
        "pngrtran.c",
        "pngrutil.c",
        "pngset.c",
        "pngtrans.c",
        "pngwio.c",
        "pngwrite.c",
        "pngwtran.c",
        "pngwutil.c",
    ]
    thirdparty_freetype_sources += [thirdparty_png_dir + file for file in thirdparty_png_sources]

    thirdparty_zlib_dir = "../../../thirdparty/zlib/"
    thirdparty_zlib_sources = [
        "adler32.c",
        "compress.c",
        "crc32.c",
        "deflate.c",
        "infback.c",
        "inffast.c",
        "inflate.c",
        "inftrees.c",
        "trees.c",
        "uncompr.c",
        "zutil.c",
    ]
    thirdparty_freetype_sources += [thirdparty_zlib_dir + file for file in thirdparty_zlib_sources]

    env_freetype.Append(CPPPATH=[thirdparty_freetype_dir + "/include", thirdparty_zlib_dir, thirdparty_png_dir])
    env.Append(CPPPATH=[thirdparty_freetype_dir + "/include"])

    env_freetype.Append(
        CPPDEFINES=[
            "FT2_BUILD_LIBRARY",
            "FT_CONFIG_OPTION_USE_PNG",
            ("PNG_ARM_NEON_OPT", 0),
            "FT_CONFIG_OPTION_SYSTEM_ZLIB",
        ]
    )
    if env["target"] == "debug":
        env_freetype.Append(CPPDEFINES=["ZLIB_DEBUG"])

    env.Append(CPPDEFINES=["MODULE_FREETYPE_ENABLED"])

    lib = env_freetype.Library(
        f'freetype_builtin.{env["platform"]}.{env["target"]}.{env["arch_suffix"]}{env["LIBSUFFIX"]}',
        thirdparty_freetype_sources,
    )
    env.Append(LIBS=[lib])


env.Append(CPPDEFINES=["GDEXTENSION"])
env.Append(CPPPATH=["../"])
sources = Glob("../*.cpp")

if env["platform"] == "macos":
    methods.write_macos_plist(
        f'./bin/libtextserver_fallback.macos.{env["target"]}.framework',
        f'libtextserver_fallback.macos.{env["target"]}',
        "org.godotengine.textserver_fallback",
        "Fallback Text Server",
    )
    library = env.SharedLibrary(
        f'./bin/libtextserver_fallback.macos.{env["target"]}.framework/libtextserver_fallback.macos.{env["target"]}',
        source=sources,
    )
else:
    library = env.SharedLibrary(
        f'./bin/libtextserver_fallback.{env["platform"]}.{env["target"]}.{env["arch_suffix"]}{env["SHLIBSUFFIX"]}',
        source=sources,
    )

Default(library)


def print_elapsed_time():
    elapsed_time_sec = round(time.time() - time_at_start, 3)
    time_ms = round((elapsed_time_sec % 1) * 1000)
    print("[Time elapsed: {}.{:03}]".format(time.strftime("%H:%M:%S", time.gmtime(elapsed_time_sec)), time_ms))


atexit.register(print_elapsed_time)