#!/usr/bin/env python
import os
import sys
from methods import print_error
libname = "dc_terrain"
localEnv = Environment(tools=["default"], PLATFORM="")
customs = ["custom.py"]
customs = [os.path.abspath(path) for path in customs]
opts = Variables(customs, ARGUMENTS)
opts.Update(localEnv)
Help(opts.GenerateHelpText(localEnv))
env = localEnv.Clone()
if not (os.path.isdir("godot-cpp") and os.listdir("godot-cpp")):
print_error("""godot-cpp is not available within this folder.
Either clone it as a submodule or symlink it:
git submodule update --init --recursive
# or
ln -s /path/to/godot-cpp godot-cpp""")
sys.exit(1)
env = SConscript("godot-cpp/SConstruct", {"env": env, "customs": customs})
if os.environ.get("CC"):
env["CC"] = os.environ["CC"]
if os.environ.get("CXX"):
env["CXX"] = os.environ["CXX"]
if "zig" in os.environ.get("CC", ""):
env["SHOBJSUFFIX"] = ".o"
# ../proc-nodes/src/shared holds erosion_filter.inc + erosion_cpp_shim.h: THE
# erosion filter, compiled here as C++ and by proc-nodes as GLSL from the same
# text. It is a godot-free math header, so this does not make dc-terrain depend
# on proc-nodes' classes — but it does mean proc-nodes must be checked out
# beside dc-terrain to build. See erosion_filter.inc's header for why the
# alternative (three hand-maintained copies) was not survivable.
env.Append(CPPPATH=["src/", "libdc/include/", "thirdparty/meshoptimizer/",
"../proc-nodes/src/shared/"])
# OpenMP for parallel density grid fill. mingw-w64 ships libgomp, so Windows gets
# it too — but ONLY with the posix-threads variant of the toolchain; the win32
# variant has no libgomp and no std::thread either. If a Windows build fails on
# omp.h or on <thread>, that is the alternative to check first:
# update-alternatives --config x86_64-w64-mingw32-g++
if env["platform"] in ("linux", "windows"):
env.Append(CCFLAGS=["-fopenmp"])
env.Append(LINKFLAGS=["-fopenmp"])
if env["platform"] == "windows":
# Vulkan headers. On Linux these come from the system (libvulkan-dev) on the
# default include path, which is why nothing here mentions them. A mingw cross
# build has no such path — and adding /usr/include would let host glibc
# headers shadow mingw's own, which is a worse problem than the missing
# header. So take an explicit path to a vendored copy; Godot bundles
# Vulkan-Headers for exactly this reason, and they are OS-independent.
# scons platform=windows vulkan_include=/path/to/Vulkan-Headers/include
vulkan_include = ARGUMENTS.get(
"vulkan_include",
"/storage/projects/code/godot/nvidia-rtx-godot/thirdparty/vulkan/include",
)
if not os.path.isfile(os.path.join(vulkan_include, "vulkan", "vulkan.h")):
print("ERROR: no vulkan/vulkan.h under " + vulkan_include)
print(" pass vulkan_include=<dir> pointing at Vulkan-Headers/include")
Exit(1)
env.Append(CPPPATH=[vulkan_include])
if env["platform"] == "linux":
# libdl for dladdr() — used to resolve the compute-shader dir relative to
# this .so at runtime (see _shader_dir in dc_gpu_mesh_pipeline.cpp) so the
# shaders load on any host, not just the build box.
#
# Windows needs no equivalent link: GetModuleHandleEx/GetModuleFileName do
# the same job and live in kernel32, which is always linked.
env.Append(LIBS=["dl"])
sources = Glob("src/*.cpp") + Glob("libdc/src/*.cpp") + Glob("libdc/src/generators/*.cpp") + Glob("thirdparty/meshoptimizer/*.cpp")
if env["target"] in ["editor", "template_debug"]:
try:
doc_data = env.GodotCPPDocData("src/gen/doc_data.gen.cpp", source=Glob("doc_classes/*.xml"))
sources.append(doc_data)
except AttributeError:
print("Not including class reference as we're targeting a pre-4.3 baseline.")
suffix = env["suffix"].replace(".dev", "").replace(".universal", "")
lib_filename = "{}{}{}{}".format(
env.subst("$SHLIBPREFIX"), libname, suffix, env.subst("$SHLIBSUFFIX")
)
library = env.SharedLibrary(
"bin/{}/{}".format(env["platform"], lib_filename),
source=sources,
)
Default(library)