2022-02-13 20:41:29 +08:00
|
|
|
#!/usr/bin/env python
|
2024-06-12 04:19:07 +08:00
|
|
|
from misc.utility.scons_hints import *
|
|
|
|
|
2022-02-13 20:41:29 +08:00
|
|
|
import atexit
|
|
|
|
import sys
|
|
|
|
import time
|
|
|
|
|
2024-05-21 21:14:59 +08:00
|
|
|
import methods
|
|
|
|
|
2024-04-27 01:35:07 +08:00
|
|
|
# Enable ANSI escape code support on Windows 10 and later (for colored console output).
|
|
|
|
# <https://github.com/python/cpython/issues/73245>
|
2024-05-18 23:47:31 +08:00
|
|
|
if sys.stdout.isatty() and sys.platform == "win32":
|
|
|
|
try:
|
2024-05-21 21:14:59 +08:00
|
|
|
from ctypes import WinError, byref, windll # type: ignore
|
2024-05-18 23:47:31 +08:00
|
|
|
from ctypes.wintypes import DWORD # type: ignore
|
2024-04-27 01:35:07 +08:00
|
|
|
|
2024-05-18 23:47:31 +08:00
|
|
|
stdout_handle = windll.kernel32.GetStdHandle(DWORD(-11))
|
|
|
|
mode = DWORD(0)
|
|
|
|
if not windll.kernel32.GetConsoleMode(stdout_handle, byref(mode)):
|
|
|
|
raise WinError()
|
|
|
|
mode = DWORD(mode.value | 4)
|
|
|
|
if not windll.kernel32.SetConsoleMode(stdout_handle, mode):
|
|
|
|
raise WinError()
|
|
|
|
except Exception as e:
|
|
|
|
methods._colorize = False
|
|
|
|
methods.print_error(f"Failed to enable ANSI escape code support, disabling color output.\n{e}")
|
2024-04-27 01:35:07 +08:00
|
|
|
|
2022-02-13 20:41:29 +08:00
|
|
|
# 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)
|
2022-08-25 17:35:30 +08:00
|
|
|
opts.Add(BoolVariable("brotli_enabled", "Use Brotli library", True))
|
2022-02-13 20:41:29 +08:00
|
|
|
opts.Add(BoolVariable("freetype_enabled", "Use FreeType library", True))
|
|
|
|
opts.Add(BoolVariable("msdfgen_enabled", "Use MSDFgen library (require FreeType)", True))
|
2022-06-14 15:29:58 +08:00
|
|
|
opts.Add(BoolVariable("thorvg_enabled", "Use ThorVG library (require FreeType)", True))
|
2022-02-13 20:41:29 +08:00
|
|
|
opts.Add(BoolVariable("verbose", "Enable verbose output for the compilation", False))
|
|
|
|
|
|
|
|
opts.Update(env)
|
|
|
|
|
|
|
|
if not env["verbose"]:
|
2024-04-27 01:35:07 +08:00
|
|
|
methods.no_verbose(env)
|
2022-02-13 20:41:29 +08:00
|
|
|
|
2022-06-14 15:29:58 +08:00
|
|
|
# ThorVG
|
|
|
|
if env["thorvg_enabled"] and env["freetype_enabled"]:
|
|
|
|
env_tvg = env.Clone()
|
|
|
|
env_tvg.disable_warnings()
|
|
|
|
|
|
|
|
thirdparty_tvg_dir = "../../../thirdparty/thorvg/"
|
|
|
|
thirdparty_tvg_sources = [
|
2023-09-29 20:58:36 +08:00
|
|
|
# common
|
|
|
|
"src/common/tvgCompressor.cpp",
|
2024-06-03 02:21:18 +08:00
|
|
|
"src/common/tvgLines.cpp",
|
2023-09-29 20:58:36 +08:00
|
|
|
"src/common/tvgMath.cpp",
|
|
|
|
"src/common/tvgStr.cpp",
|
|
|
|
# SVG parser
|
2022-06-14 15:29:58 +08:00
|
|
|
"src/loaders/svg/tvgSvgCssStyle.cpp",
|
|
|
|
"src/loaders/svg/tvgSvgLoader.cpp",
|
|
|
|
"src/loaders/svg/tvgSvgPath.cpp",
|
|
|
|
"src/loaders/svg/tvgSvgSceneBuilder.cpp",
|
|
|
|
"src/loaders/svg/tvgSvgUtil.cpp",
|
|
|
|
"src/loaders/svg/tvgXmlParser.cpp",
|
2023-09-29 20:58:36 +08:00
|
|
|
"src/loaders/raw/tvgRawLoader.cpp",
|
2024-06-03 02:21:18 +08:00
|
|
|
# image loaders
|
2023-10-13 19:09:33 +08:00
|
|
|
"src/loaders/external_png/tvgPngLoader.cpp",
|
|
|
|
"src/loaders/jpg/tvgJpgd.cpp",
|
|
|
|
"src/loaders/jpg/tvgJpgLoader.cpp",
|
2023-09-29 20:58:36 +08:00
|
|
|
# renderer common
|
|
|
|
"src/renderer/tvgAccessor.cpp",
|
|
|
|
# "src/renderer/tvgAnimation.cpp",
|
|
|
|
"src/renderer/tvgCanvas.cpp",
|
|
|
|
"src/renderer/tvgFill.cpp",
|
|
|
|
# "src/renderer/tvgGlCanvas.cpp",
|
|
|
|
"src/renderer/tvgInitializer.cpp",
|
|
|
|
"src/renderer/tvgLoader.cpp",
|
|
|
|
"src/renderer/tvgPaint.cpp",
|
|
|
|
"src/renderer/tvgPicture.cpp",
|
|
|
|
"src/renderer/tvgRender.cpp",
|
|
|
|
# "src/renderer/tvgSaver.cpp",
|
|
|
|
"src/renderer/tvgScene.cpp",
|
|
|
|
"src/renderer/tvgShape.cpp",
|
|
|
|
"src/renderer/tvgSwCanvas.cpp",
|
|
|
|
"src/renderer/tvgTaskScheduler.cpp",
|
2024-01-06 01:01:00 +08:00
|
|
|
"src/renderer/tvgText.cpp",
|
|
|
|
# "src/renderer/tvgWgCanvas.cpp",
|
2023-09-29 20:58:36 +08:00
|
|
|
# renderer sw_engine
|
|
|
|
"src/renderer/sw_engine/tvgSwFill.cpp",
|
|
|
|
"src/renderer/sw_engine/tvgSwImage.cpp",
|
|
|
|
"src/renderer/sw_engine/tvgSwMath.cpp",
|
|
|
|
"src/renderer/sw_engine/tvgSwMemPool.cpp",
|
|
|
|
"src/renderer/sw_engine/tvgSwRaster.cpp",
|
|
|
|
"src/renderer/sw_engine/tvgSwRenderer.cpp",
|
|
|
|
"src/renderer/sw_engine/tvgSwRle.cpp",
|
|
|
|
"src/renderer/sw_engine/tvgSwShape.cpp",
|
|
|
|
"src/renderer/sw_engine/tvgSwStroke.cpp",
|
2022-06-14 15:29:58 +08:00
|
|
|
]
|
|
|
|
thirdparty_tvg_sources = [thirdparty_tvg_dir + file for file in thirdparty_tvg_sources]
|
|
|
|
|
|
|
|
env_tvg.Append(
|
|
|
|
CPPPATH=[
|
|
|
|
"../../../thirdparty/thorvg/inc",
|
2023-09-29 20:58:36 +08:00
|
|
|
"../../../thirdparty/thorvg/src/common",
|
|
|
|
"../../../thirdparty/thorvg/src/renderer",
|
|
|
|
"../../../thirdparty/thorvg/src/renderer/sw_engine",
|
2023-10-13 19:09:33 +08:00
|
|
|
"../../../thirdparty/thorvg/src/loaders/svg",
|
|
|
|
"../../../thirdparty/thorvg/src/loaders/raw",
|
|
|
|
"../../../thirdparty/thorvg/src/loaders/external_png",
|
|
|
|
"../../../thirdparty/thorvg/src/loaders/jpg",
|
2024-06-03 02:21:18 +08:00
|
|
|
"../../../thirdparty/libpng",
|
2022-06-14 15:29:58 +08:00
|
|
|
]
|
|
|
|
)
|
2023-08-17 19:33:15 +08:00
|
|
|
|
|
|
|
# Enable ThorVG static object linking.
|
|
|
|
env_tvg.Append(CPPDEFINES=["TVG_STATIC"])
|
|
|
|
|
2023-09-18 20:49:04 +08:00
|
|
|
env.Append(
|
|
|
|
CPPPATH=[
|
|
|
|
"../../../thirdparty/thorvg/inc",
|
2023-09-29 20:58:36 +08:00
|
|
|
"../../../thirdparty/thorvg/src/common",
|
|
|
|
"../../../thirdparty/thorvg/src/renderer",
|
2023-09-18 20:49:04 +08:00
|
|
|
]
|
|
|
|
)
|
2022-06-14 15:29:58 +08:00
|
|
|
env.Append(CPPDEFINES=["MODULE_SVG_ENABLED"])
|
|
|
|
|
|
|
|
lib = env_tvg.Library(
|
|
|
|
f'tvg_builtin{env["suffix"]}{env["LIBSUFFIX"]}',
|
|
|
|
thirdparty_tvg_sources,
|
|
|
|
)
|
|
|
|
env.Append(LIBS=[lib])
|
|
|
|
|
2022-02-13 20:41:29 +08:00
|
|
|
# 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/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]
|
|
|
|
|
2024-03-12 16:26:55 +08:00
|
|
|
env_msdfgen.Append(CPPDEFINES=[("MSDFGEN_PUBLIC", "")])
|
2022-02-13 20:41:29 +08:00
|
|
|
env_msdfgen.Append(CPPPATH=["../../../thirdparty/freetype/include", "../../../thirdparty/msdfgen"])
|
|
|
|
env.Append(CPPPATH=["../../../thirdparty/msdfgen"])
|
2024-03-12 16:26:55 +08:00
|
|
|
env.Append(CPPDEFINES=[("MSDFGEN_PUBLIC", "")])
|
2022-02-13 20:41:29 +08:00
|
|
|
env.Append(CPPDEFINES=["MODULE_MSDFGEN_ENABLED"])
|
|
|
|
|
|
|
|
lib = env_msdfgen.Library(
|
2022-10-05 16:20:58 +08:00
|
|
|
f'msdfgen_builtin{env["suffix"]}{env["LIBSUFFIX"]}',
|
2022-02-13 20:41:29 +08:00
|
|
|
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",
|
2022-05-17 23:14:19 +08:00
|
|
|
"src/svg/svg.c",
|
2022-02-13 20:41:29 +08:00
|
|
|
"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",
|
|
|
|
"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]
|
|
|
|
|
2022-08-25 17:35:30 +08:00
|
|
|
if env["brotli_enabled"]:
|
|
|
|
thirdparty_brotli_dir = "../../../thirdparty/brotli/"
|
|
|
|
thirdparty_brotli_sources = [
|
|
|
|
"common/constants.c",
|
|
|
|
"common/context.c",
|
|
|
|
"common/dictionary.c",
|
|
|
|
"common/platform.c",
|
|
|
|
"common/shared_dictionary.c",
|
|
|
|
"common/transform.c",
|
|
|
|
"dec/bit_reader.c",
|
|
|
|
"dec/decode.c",
|
|
|
|
"dec/huffman.c",
|
|
|
|
"dec/state.c",
|
|
|
|
]
|
|
|
|
thirdparty_freetype_sources += [thirdparty_brotli_dir + file for file in thirdparty_brotli_sources]
|
|
|
|
env_freetype.Append(CPPDEFINES=["FT_CONFIG_OPTION_USE_BROTLI"])
|
|
|
|
env_freetype.Prepend(CPPPATH=[thirdparty_brotli_dir + "include"])
|
|
|
|
env.Append(CPPDEFINES=["FT_CONFIG_OPTION_USE_BROTLI"])
|
|
|
|
|
2022-02-13 20:41:29 +08:00
|
|
|
env_freetype.Append(CPPPATH=[thirdparty_freetype_dir + "/include", thirdparty_zlib_dir, thirdparty_png_dir])
|
|
|
|
env.Append(CPPPATH=[thirdparty_freetype_dir + "/include"])
|
|
|
|
|
2022-05-17 23:14:19 +08:00
|
|
|
env_freetype.Append(
|
|
|
|
CPPDEFINES=[
|
|
|
|
"FT2_BUILD_LIBRARY",
|
|
|
|
"FT_CONFIG_OPTION_USE_PNG",
|
|
|
|
"FT_CONFIG_OPTION_SYSTEM_ZLIB",
|
|
|
|
]
|
|
|
|
)
|
SCons: Unify tools/target build type configuration
Implements https://github.com/godotengine/godot-proposals/issues/3371.
New `target` presets
====================
The `tools` option is removed and `target` changes to use three new presets,
which match the builds users are familiar with. These targets control the
default optimization level and enable editor-specific and debugging code:
- `editor`: Replaces `tools=yes target=release_debug`.
* Defines: `TOOLS_ENABLED`, `DEBUG_ENABLED`, `-O2`/`/O2`
- `template_debug`: Replaces `tools=no target=release_debug`.
* Defines: `DEBUG_ENABLED`, `-O2`/`/O2`
- `template_release`: Replaces `tools=no target=release`.
* Defines: `-O3`/`/O2`
New `dev_build` option
======================
The previous `target=debug` is now replaced by a separate `dev_build=yes`
option, which can be used in combination with either of the three targets,
and changes the following:
- `dev_build`: Defines `DEV_ENABLED`, disables optimization (`-O0`/`/0d`),
enables generating debug symbols, does not define `NDEBUG` so `assert()`
works in thirdparty libraries, adds a `.dev` suffix to the binary name.
Note: Unlike previously, `dev_build` defaults to off so that users who
compile Godot from source get an optimized and small build by default.
Engine contributors should now set `dev_build=yes` in their build scripts or
IDE configuration manually.
Changed binary names
====================
The name of generated binaries and object files are changed too, to follow
this format:
`godot.<platform>.<target>[.dev][.double].<arch>[.<extra_suffix>][.<ext>]`
For example:
- `godot.linuxbsd.editor.dev.arm64`
- `godot.windows.template_release.double.x86_64.mono.exe`
Be sure to update your links/scripts/IDE config accordingly.
More flexible `optimize` and `debug_symbols` options
====================================================
The optimization level and whether to generate debug symbols can be further
specified with the `optimize` and `debug_symbols` options. So the default
values listed above for the various `target` and `dev_build` combinations
are indicative and can be replaced when compiling, e.g.:
`scons p=linuxbsd target=template_debug dev_build=yes optimize=debug`
will make a "debug" export template with dev-only code enabled, `-Og`
optimization level for GCC/Clang, and debug symbols. Perfect for debugging
complex crashes at runtime in an exported project.
2022-09-22 14:28:55 +08:00
|
|
|
if env.dev_build:
|
2022-02-13 20:41:29 +08:00
|
|
|
env_freetype.Append(CPPDEFINES=["ZLIB_DEBUG"])
|
|
|
|
|
|
|
|
env.Append(CPPDEFINES=["MODULE_FREETYPE_ENABLED"])
|
|
|
|
|
|
|
|
lib = env_freetype.Library(
|
2022-10-05 16:20:58 +08:00
|
|
|
f'freetype_builtin{env["suffix"]}{env["LIBSUFFIX"]}',
|
2022-02-13 20:41:29 +08:00
|
|
|
thirdparty_freetype_sources,
|
|
|
|
)
|
|
|
|
env.Append(LIBS=[lib])
|
|
|
|
|
|
|
|
|
|
|
|
env.Append(CPPDEFINES=["GDEXTENSION"])
|
|
|
|
env.Append(CPPPATH=["../"])
|
|
|
|
sources = Glob("../*.cpp")
|
|
|
|
|
2022-07-20 14:28:22 +08:00
|
|
|
if env["platform"] == "macos":
|
|
|
|
methods.write_macos_plist(
|
|
|
|
f'./bin/libtextserver_fallback.macos.{env["target"]}.framework',
|
|
|
|
f'libtextserver_fallback.macos.{env["target"]}',
|
2022-02-13 20:41:29 +08:00
|
|
|
"org.godotengine.textserver_fallback",
|
|
|
|
"Fallback Text Server",
|
|
|
|
)
|
|
|
|
library = env.SharedLibrary(
|
2022-07-20 14:28:22 +08:00
|
|
|
f'./bin/libtextserver_fallback.macos.{env["target"]}.framework/libtextserver_fallback.macos.{env["target"]}',
|
2022-02-13 20:41:29 +08:00
|
|
|
source=sources,
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
library = env.SharedLibrary(
|
2022-10-05 16:20:58 +08:00
|
|
|
f'./bin/libtextserver_fallback{env["suffix"]}{env["SHLIBSUFFIX"]}',
|
2022-02-13 20:41:29 +08:00
|
|
|
source=sources,
|
|
|
|
)
|
|
|
|
|
|
|
|
Default(library)
|
|
|
|
|
|
|
|
|
|
|
|
def print_elapsed_time():
|
2024-04-27 01:35:07 +08:00
|
|
|
elapsed_time_sec = round(time.time() - time_at_start, 2)
|
|
|
|
time_centiseconds = round((elapsed_time_sec % 1) * 100)
|
|
|
|
print(
|
|
|
|
"{}[Time elapsed: {}.{:02}]{}".format(
|
|
|
|
methods.ANSI.GRAY,
|
|
|
|
time.strftime("%H:%M:%S", time.gmtime(elapsed_time_sec)),
|
|
|
|
time_centiseconds,
|
|
|
|
methods.ANSI.RESET,
|
|
|
|
)
|
|
|
|
)
|
2022-02-13 20:41:29 +08:00
|
|
|
|
|
|
|
|
|
|
|
atexit.register(print_elapsed_time)
|