From 4f6b62161ed27379495245776ae3ae727d25dadb Mon Sep 17 00:00:00 2001 From: Jacob Sanders <46481567+Faolan-Rad@users.noreply.github.com> Date: Fri, 29 Mar 2024 13:18:57 -0400 Subject: [PATCH] LibGodot --- SConstruct | 18 +++++++++++++- platform/linuxbsd/SCsub | 7 +++++- platform/macos/SCsub | 7 +++++- platform/windows/SCsub | 49 ++++++++++++++++++++++---------------- platform/windows/detect.py | 2 +- 5 files changed, 58 insertions(+), 25 deletions(-) diff --git a/SConstruct b/SConstruct index 753cea40e33c..24d5d932d116 100644 --- a/SConstruct +++ b/SConstruct @@ -140,7 +140,6 @@ env_base.__class__.use_windows_spawn_fix = methods.use_windows_spawn_fix env_base.__class__.add_shared_library = methods.add_shared_library env_base.__class__.add_library = methods.add_library -env_base.__class__.add_program = methods.add_program env_base.__class__.CommandNoCache = methods.CommandNoCache env_base.__class__.Run = methods.Run env_base.__class__.disable_warnings = methods.disable_warnings @@ -200,6 +199,14 @@ opts.Add("custom_modules", "A list of comma-separated directory paths containing opts.Add(BoolVariable("custom_modules_recursive", "Detect custom modules recursively for each specified path.", True)) # Advanced options +opts.Add( + EnumVariable( + "library_type", + "Build library type", + "executable", + ("executable", "static_library", "shared_library"), + ) +) opts.Add(BoolVariable("dev_mode", "Alias for dev options: verbose=yes warnings=extra werror=yes tests=yes", False)) opts.Add(BoolVariable("tests", "Build the unit tests", False)) opts.Add(BoolVariable("fast_unsafe", "Enable unsafe options for faster rebuilds", False)) @@ -284,6 +291,15 @@ if env_base["import_env_vars"]: selected_platform = "" +if env_base["library_type"] == "static_library": + env_base.Append(CPPDEFINES=["LIBRARY_ENABLED"]) +elif env_base["library_type"] == "shared_library": + env_base.Append(CPPDEFINES=["LIBRARY_ENABLED"]) + env_base.Append(CCFLAGS=["-fPIC"]) + env_base.Append(STATIC_AND_SHARED_OBJECTS_ARE_THE_SAME=True) +else: + env_base.__class__.add_program = methods.add_program + if env_base["platform"] != "": selected_platform = env_base["platform"] elif env_base["p"] != "": diff --git a/platform/linuxbsd/SCsub b/platform/linuxbsd/SCsub index 0802b528f4b0..051296f46e95 100644 --- a/platform/linuxbsd/SCsub +++ b/platform/linuxbsd/SCsub @@ -38,7 +38,12 @@ if env["dbus"]: if env["use_sowrap"]: common_linuxbsd.append("dbus-so_wrap.c") -prog = env.add_program("#bin/godot", ["godot_linuxbsd.cpp"] + common_linuxbsd) +if env["library_type"] == "static_library": + prog = env.add_library("#bin/godot", ["godot_linuxbsd.cpp"] + common_linuxbsd) +elif env["library_type"] == "shared_library": + prog = env.add_shared_library("#bin/godot", ["godot_linuxbsd.cpp"] + common_linuxbsd) +else: + prog = env.add_program("#bin/godot", ["godot_linuxbsd.cpp"] + common_linuxbsd) if env["debug_symbols"] and env["separate_debug_symbols"]: env.AddPostAction(prog, env.Run(platform_linuxbsd_builders.make_debug_linuxbsd)) diff --git a/platform/macos/SCsub b/platform/macos/SCsub index 59ef4ee85c4f..48e81fde25e9 100644 --- a/platform/macos/SCsub +++ b/platform/macos/SCsub @@ -122,7 +122,12 @@ files = [ "gl_manager_macos_legacy.mm", ] -prog = env.add_program("#bin/godot", files) +if env["library_type"] == "static_library": + prog = env.add_library("#bin/godot", files) +elif env["library_type"] == "shared_library": + prog = env.add_shared_library("#bin/godot", files) +else: + prog = env.add_program("#bin/godot", files) if env["debug_symbols"] and env["separate_debug_symbols"]: env.AddPostAction(prog, env.Run(platform_macos_builders.make_debug_macos)) diff --git a/platform/windows/SCsub b/platform/windows/SCsub index cf6416b8dad6..5f3c8d5f0705 100644 --- a/platform/windows/SCsub +++ b/platform/windows/SCsub @@ -48,27 +48,34 @@ res_obj = env.RES(res_target, res_file) env.add_source_files(sources, common_win) sources += res_obj -prog = env.add_program("#bin/godot", sources, PROGSUFFIX=env["PROGSUFFIX"]) -arrange_program_clean(prog) - -# Build console wrapper app. -if env["windows_subsystem"] == "gui": - env_wrap = env.Clone() - res_wrap_file = "godot_res_wrap.rc" - res_wrap_target = "godot_res_wrap" + env["OBJSUFFIX"] - res_wrap_obj = env_wrap.RES(res_wrap_target, res_wrap_file) - - if env.msvc: - env_wrap.Append(LINKFLAGS=["/SUBSYSTEM:CONSOLE"]) - env_wrap.Append(LINKFLAGS=["version.lib"]) - else: - env_wrap.Append(LINKFLAGS=["-Wl,--subsystem,console"]) - env_wrap.Append(LIBS=["version"]) - - prog_wrap = env_wrap.add_program("#bin/godot", common_win_wrap + res_wrap_obj, PROGSUFFIX=env["PROGSUFFIX_WRAP"]) - arrange_program_clean(prog_wrap) - env_wrap.Depends(prog_wrap, prog) - sources += common_win_wrap + res_wrap_obj +if env["library_type"] == "static_library": + prog = env.add_library("#bin/godot", sources, PROGSUFFIX=env["PROGSUFFIX"]) +elif env["library_type"] == "shared_library": + prog = env.add_shared_library("#bin/godot", sources, PROGSUFFIX=env["PROGSUFFIX"]) +else: + prog = env.add_program("#bin/godot", sources, PROGSUFFIX=env["PROGSUFFIX"]) + arrange_program_clean(prog) + + # Build console wrapper app. + if env["windows_subsystem"] == "gui": + env_wrap = env.Clone() + res_wrap_file = "godot_res_wrap.rc" + res_wrap_target = "godot_res_wrap" + env["OBJSUFFIX"] + res_wrap_obj = env_wrap.RES(res_wrap_target, res_wrap_file) + + if env.msvc: + env_wrap.Append(LINKFLAGS=["/SUBSYSTEM:CONSOLE"]) + env_wrap.Append(LINKFLAGS=["version.lib"]) + else: + env_wrap.Append(LINKFLAGS=["-Wl,--subsystem,console"]) + env_wrap.Append(LIBS=["version"]) + + prog_wrap = env_wrap.add_program( + "#bin/godot", common_win_wrap + res_wrap_obj, PROGSUFFIX=env["PROGSUFFIX_WRAP"] + ) + arrange_program_clean(prog_wrap) + env_wrap.Depends(prog_wrap, prog) + sources += common_win_wrap + res_wrap_obj # Microsoft Visual Studio Project Generation if env["vsproj"]: diff --git a/platform/windows/detect.py b/platform/windows/detect.py index 196beb423f47..6d89c5ca6508 100644 --- a/platform/windows/detect.py +++ b/platform/windows/detect.py @@ -384,7 +384,7 @@ def configure_msvc(env: "SConsEnvironment", vcvars_msvc_config): ## Build type # TODO: Re-evaluate the need for this / streamline with common config. - if env["target"] == "template_release": + if env["target"] == "template_release" and env["library_type"] == "executable": env.Append(LINKFLAGS=["/ENTRY:mainCRTStartup"]) if env["windows_subsystem"] == "gui":