Skip to content

Commit

Permalink
LibGodot
Browse files Browse the repository at this point in the history
  • Loading branch information
Faolan-Rad committed Mar 29, 2024
1 parent fe01776 commit 4f6b621
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 25 deletions.
18 changes: 17 additions & 1 deletion SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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"] != "":
Expand Down
7 changes: 6 additions & 1 deletion platform/linuxbsd/SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -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))
7 changes: 6 additions & 1 deletion platform/macos/SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
49 changes: 28 additions & 21 deletions platform/windows/SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -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"]:
Expand Down
2 changes: 1 addition & 1 deletion platform/windows/detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down

0 comments on commit 4f6b621

Please sign in to comment.