Skip to content
7 changes: 6 additions & 1 deletion SConstruct
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
#!/usr/bin/env python

import os
import sys

# Add godot-cpp folder to sys.path, so that we can import local modules.
sys.path.append(Dir(".").srcnode().abspath)


EnsureSConsVersion(4, 0)
EnsurePythonVersion(3, 8)
Expand All @@ -27,7 +32,7 @@ if profile:
elif os.path.isfile(profile + ".py"):
customs.append(profile + ".py")
opts = Variables(customs, ARGUMENTS)
cpp_tool = Tool("godotcpp", toolpath=["tools"])
cpp_tool = Tool("godotcpp", toolpath=[Dir("tools").srcnode().abspath])
cpp_tool.options(opts, env)
opts.Update(env)

Expand Down
19 changes: 11 additions & 8 deletions cmake/godotcpp.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -319,18 +319,20 @@ function(godotcpp_generate)
set(DEBUG_FEATURES "$<NOT:$<STREQUAL:${GODOTCPP_TARGET},template_release>>")
set(HOT_RELOAD "$<IF:${HOT_RELOAD-UNSET},${DEBUG_FEATURES},$<BOOL:${GODOTCPP_USE_HOT_RELOAD}>>")

# Suffix
# Suffix Generator Expression
string(
CONCAT
GODOTCPP_SUFFIX
"$<1:.${SYSTEM_NAME}>"
GODOTCPP_SUFFIX_GENEX
"$<1:${SYSTEM_NAME}>"
"$<1:.${GODOTCPP_TARGET}>"
"$<${IS_DEV_BUILD}:.dev>"
"$<$<STREQUAL:${GODOTCPP_PRECISION},double>:.double>"
"$<1:.${ARCH_NAME}>"
# TODO IOS_SIMULATOR
"$<$<NOT:${THREADS_ENABLED}>:.nothreads>"
)
# The same as above, but with a leading '.' to maintain backwards compatibility.
set(GODOTCPP_SUFFIX ".${GODOTCPP_SUFFIX_GENEX}")

# the godot-cpp.* library targets
add_library(godot-cpp STATIC)
Expand Down Expand Up @@ -370,11 +372,12 @@ function(godotcpp_generate)
ARCHIVE_OUTPUT_DIRECTORY "$<1:${CMAKE_BINARY_DIR}/bin>"

# Things that are handy to know for dependent targets
GODOTCPP_PLATFORM "${SYSTEM_NAME}"
GODOTCPP_TARGET "${GODOTCPP_TARGET}"
GODOTCPP_ARCH "${ARCH_NAME}"
GODOTCPP_PRECISION "${GODOTCPP_PRECISION}"
GODOTCPP_SUFFIX "${GODOTCPP_SUFFIX}"
GODOTCPP_PLATFORM "${SYSTEM_NAME}"
GODOTCPP_TARGET "${GODOTCPP_TARGET}"
GODOTCPP_ARCH "${ARCH_NAME}"
GODOTCPP_PRECISION "${GODOTCPP_PRECISION}"
GODOTCPP_SUFFIX "${GODOTCPP_SUFFIX}"
GODOTCPP_SUFFIX_GENEX "${GODOTCPP_SUFFIX_GENEX}"

# Some IDE's respect this property to logically group targets
FOLDER "godot-cpp"
Expand Down
2 changes: 1 addition & 1 deletion include/godot_cpp/classes/wrapped.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class Wrapped {

void _postinitialize();

Wrapped(const StringName p_godot_class);
Wrapped(const StringName &p_godot_class);
Wrapped(GodotObject *p_godot_object);
virtual ~Wrapped() {}

Expand Down
1 change: 1 addition & 0 deletions include/godot_cpp/core/defs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

#include <cstddef>
#include <cstdint>
#include <type_traits>
#include <utility>

namespace godot {
Expand Down
2 changes: 2 additions & 0 deletions include/godot_cpp/core/math_defs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ namespace godot {
#define Math_TAU 6.2831853071795864769252867666
#define Math_PI 3.1415926535897932384626433833
#define Math_E 2.7182818284590452353602874714
#define Math_INF INFINITY
#define Math_NAN NAN

#ifdef DEBUG_ENABLED
#define MATH_CHECKS
Expand Down
2 changes: 1 addition & 1 deletion src/classes/wrapped.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void Wrapped::_postinitialize() {
}
}

Wrapped::Wrapped(const StringName p_godot_class) {
Wrapped::Wrapped(const StringName &p_godot_class) {
#ifdef HOT_RELOAD_ENABLED
if (unlikely(Wrapped::_constructing_recreate_owner)) {
_owner = Wrapped::_constructing_recreate_owner;
Expand Down
2 changes: 1 addition & 1 deletion src/godot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ GDExtensionBool GDExtensionBinding::init(GDExtensionInterfaceGetProcAddress p_ge

// Make sure we weren't passed the legacy struct.
uint32_t *raw_interface = (uint32_t *)(void *)p_get_proc_address;
if (raw_interface[0] == 4 && raw_interface[1] == 0) {
if (uintptr_t(p_get_proc_address) % alignof(LegacyGDExtensionInterface) == 0 && raw_interface[0] == 4 && raw_interface[1] == 0) {
// Use the legacy interface only to give a nice error.
LegacyGDExtensionInterface *legacy_interface = (LegacyGDExtensionInterface *)p_get_proc_address;
internal::gdextension_interface_print_error = (GDExtensionInterfacePrintError)legacy_interface->print_error;
Expand Down
12 changes: 11 additions & 1 deletion tools/common_compiler_flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
import subprocess


def using_emcc(env):
return "emcc" in os.path.basename(env["CC"])


def using_clang(env):
return "clang" in os.path.basename(env["CC"])

Expand Down Expand Up @@ -89,7 +93,13 @@ def generate(env):
# Adding dwarf-4 explicitly makes stacktraces work with clang builds,
# otherwise addr2line doesn't understand them.
env.Append(CCFLAGS=["-gdwarf-4"])
if env.dev_build:
if using_emcc(env):
# Emscripten only produces dwarf symbols when using "-g3".
env.AppendUnique(CCFLAGS=["-g3"])
# Emscripten linker needs debug symbols options too.
env.AppendUnique(LINKFLAGS=["-gdwarf-4"])
env.AppendUnique(LINKFLAGS=["-g3"])
elif env.dev_build:
env.Append(CCFLAGS=["-g3"])
else:
env.Append(CCFLAGS=["-g2"])
Expand Down
53 changes: 34 additions & 19 deletions tools/godotcpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@
from doc_source_generator import scons_generate_doc_source


def add_sources(sources, dir, extension):
for f in os.listdir(dir):
if f.endswith("." + extension):
sources.append(dir + "/" + f)


def get_cmdline_bool(option, default):
"""We use `ARGUMENTS.get()` to check if options were manually overridden on the command line,
and SCons' _text2bool helper to convert them to booleans, otherwise they're handled as strings.
Expand All @@ -34,7 +28,12 @@ def get_cmdline_bool(option, default):


def normalize_path(val, env):
return val if os.path.isabs(val) else os.path.join(env.Dir("#").abspath, val)
"""Normalize a path that was provided by the user on the command line
and is thus either an absolute path, or relative to the top level directory (#)
where the command was run.
"""
# If val is an absolute path, it will not be joined.
return os.path.join(env.Dir("#").abspath, val)


def validate_file(key, val, env):
Expand All @@ -54,9 +53,10 @@ def validate_parent_dir(key, val, env):

def get_platform_tools_paths(env):
path = env.get("custom_tools", None)
tools_path = env.Dir("tools").srcnode().abspath
if path is None:
return ["tools"]
return [normalize_path(path, env), "tools"]
return [tools_path]
return [normalize_path(path, env), tools_path]


def get_custom_platforms(env):
Expand Down Expand Up @@ -141,7 +141,12 @@ def scons_emit_files(target, source, env):
env.Clean(target, [env.File(f) for f in get_file_list(str(source[0]), target[0].abspath, True, True)])

api = generate_trimmed_api(str(source[0]), profile_filepath)
files = [env.File(f) for f in _get_file_list(api, target[0].abspath, True, True)]
files = []
for f in _get_file_list(api, target[0].abspath, True, True):
file = env.File(f)
if profile_filepath:
env.Depends(file, profile_filepath)
files.append(file)
env["godot_cpp_gen_dir"] = target[0].abspath
return files, source

Expand Down Expand Up @@ -530,8 +535,11 @@ def generate(env):


def _godot_cpp(env):
extension_dir = normalize_path(env.get("gdextension_dir", env.Dir("gdextension").abspath), env)
api_file = normalize_path(env.get("custom_api_file", env.File(extension_dir + "/extension_api.json").abspath), env)
extension_dir = normalize_path(env.get("gdextension_dir", default=env.Dir("gdextension").srcnode().abspath), env)
api_file = normalize_path(
env.get("custom_api_file", default=os.path.join(extension_dir, "extension_api.json")), env
)

bindings = env.GodotCPPBindings(
env.Dir("."),
[
Expand All @@ -546,15 +554,22 @@ def _godot_cpp(env):
env.NoCache(bindings)

# Sources to compile
sources = []
add_sources(sources, "src", "cpp")
add_sources(sources, "src/classes", "cpp")
add_sources(sources, "src/core", "cpp")
add_sources(sources, "src/variant", "cpp")
sources.extend([f for f in bindings if str(f).endswith(".cpp")])
sources = [
*env.Glob("src/*.cpp"),
*env.Glob("src/classes/*.cpp"),
*env.Glob("src/core/*.cpp"),
*env.Glob("src/variant/*.cpp"),
*tuple(f for f in bindings if str(f).endswith(".cpp")),
]

# Includes
env.AppendUnique(CPPPATH=[env.Dir(d) for d in [extension_dir, "include", "gen/include"]])
env.AppendUnique(
CPPPATH=[
env.Dir(extension_dir),
env.Dir("include").srcnode(),
env.Dir("gen/include"),
]
)

library = None
library_name = "libgodot-cpp" + env["suffix"] + env["LIBSUFFIX"]
Expand Down
Loading