Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compile Godot Engine as a library. #62490

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,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 @@ -184,6 +183,14 @@ opts.Add(BoolVariable("custom_modules_recursive", "Detect custom modules recursi
opts.Add(BoolVariable("use_volk", "Use the volk library to load the Vulkan loader dynamically", True))

# Advanced options
opts.Add(
EnumVariable(
"library_type",
"Build library type",
"executable",
("executable", "static_library", "shared_library"),
)
)
opts.Add(BoolVariable("dev", "If yes, alias for verbose=yes warnings=extra werror=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 @@ -246,6 +253,16 @@ opts.Update(env_base)

selected_platform = ""

if env_base["library_type"] == "static_library":
env_base.__class__.add_program = methods.add_library
env_base.Append(CPPDEFINES=["LIBRARY_ENABLED"])
elif env_base["library_type"] == "shared_library":
env_base.__class__.add_program = methods.add_shared_library
env_base.Append(CPPDEFINES=["LIBRARY_ENABLED"])
env_base.env_base(CCFLAGS=["-fPIC"])
else:
env_base.__class__.add_program = methods.add_program

if env_base["platform"] != "":
selected_platform = env_base["platform"]
elif env_base["p"] != "":
Expand Down
4 changes: 4 additions & 0 deletions platform/linuxbsd/godot_linuxbsd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@
#include "main/main.h"
#include "os_linuxbsd.h"

#if defined(LIBRARY_ENABLED)
extern "C" int godot_main(int argc, char *argv[]) {
#else
int main(int argc, char *argv[]) {
#endif
#if defined(SANITIZERS_ENABLED)
// Note: Set stack size to be at least 30 MB (vs 8 MB default) to avoid overflow, address sanitizer can increase stack usage up to 3 times.
struct rlimit stack_lim = { 0x1E00000, 0x1E00000 };
Expand Down
4 changes: 4 additions & 0 deletions platform/macos/godot_main_macos.mm
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@
#include <sys/resource.h>
#endif

#if defined(LIBRARY_ENABLED)
extern "C" int godot_main(int argc, char *argv[]) {
#else
int main(int argc, char **argv) {
#endif
#if defined(VULKAN_ENABLED)
// MoltenVK - enable full component swizzling support.
setenv("MVK_CONFIG_FULL_IMAGE_VIEW_SWIZZLE", "1", 1);
Expand Down
6 changes: 6 additions & 0 deletions platform/windows/godot_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,11 @@ int _main() {
return result;
}

#if defined(LIBRARY_ENABLED)
extern "C" __declspec(dllexport) int godot_main(int argc, char *argv[]) {
#else
int main(int argc, char **argv) {
#endif
// override the arguments for the test handler / if symbol is provided
// TEST_MAIN_OVERRIDE

Expand All @@ -223,7 +227,9 @@ int main(int argc, char **argv) {

HINSTANCE godot_hinstance = nullptr;

#if !defined(LIBRARY_ENABLED)
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
godot_hinstance = hInstance;
return main(0, nullptr);
}
#endif