diff --git a/SConstruct b/SConstruct index 64d335b5d..3ebdff941 100644 --- a/SConstruct +++ b/SConstruct @@ -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) @@ -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) diff --git a/cmake/godotcpp.cmake b/cmake/godotcpp.cmake index a0c544fc4..7c4ea686b 100644 --- a/cmake/godotcpp.cmake +++ b/cmake/godotcpp.cmake @@ -319,11 +319,11 @@ function(godotcpp_generate) set(DEBUG_FEATURES "$>") set(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>" "$<$:.double>" @@ -331,6 +331,8 @@ function(godotcpp_generate) # TODO IOS_SIMULATOR "$<$:.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) @@ -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" diff --git a/include/godot_cpp/classes/wrapped.hpp b/include/godot_cpp/classes/wrapped.hpp index f54544bcc..f1edf66ab 100644 --- a/include/godot_cpp/classes/wrapped.hpp +++ b/include/godot_cpp/classes/wrapped.hpp @@ -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() {} diff --git a/include/godot_cpp/core/defs.hpp b/include/godot_cpp/core/defs.hpp index 9395f2013..fddfa51d5 100644 --- a/include/godot_cpp/core/defs.hpp +++ b/include/godot_cpp/core/defs.hpp @@ -32,6 +32,7 @@ #include #include +#include #include namespace godot { diff --git a/include/godot_cpp/core/math_defs.hpp b/include/godot_cpp/core/math_defs.hpp index 73d861489..89b383c71 100644 --- a/include/godot_cpp/core/math_defs.hpp +++ b/include/godot_cpp/core/math_defs.hpp @@ -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 diff --git a/src/classes/wrapped.cpp b/src/classes/wrapped.cpp index e729ba020..c5a8cc9fd 100644 --- a/src/classes/wrapped.cpp +++ b/src/classes/wrapped.cpp @@ -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; diff --git a/src/godot.cpp b/src/godot.cpp index 31a64c462..e73554b90 100644 --- a/src/godot.cpp +++ b/src/godot.cpp @@ -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; diff --git a/tools/common_compiler_flags.py b/tools/common_compiler_flags.py index e645f390f..05f95d7a3 100644 --- a/tools/common_compiler_flags.py +++ b/tools/common_compiler_flags.py @@ -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"]) @@ -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"]) diff --git a/tools/godotcpp.py b/tools/godotcpp.py index 63df0ad54..7be96247b 100644 --- a/tools/godotcpp.py +++ b/tools/godotcpp.py @@ -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. @@ -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): @@ -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): @@ -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 @@ -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("."), [ @@ -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"]