From b0f41909e0c9deddb7f0829fa3f3d1062b81ee94 Mon Sep 17 00:00:00 2001 From: unvermuthet <40361609+unvermuthet@users.noreply.github.com> Date: Tue, 18 Mar 2025 18:44:28 +0100 Subject: [PATCH] Implement `use_static_cpp` flag for Linux --- cmake/linux.cmake | 14 ++++++++++++++ tools/linux.py | 5 +++++ 2 files changed, 19 insertions(+) diff --git a/cmake/linux.cmake b/cmake/linux.cmake index 89289d754..f01d75da9 100644 --- a/cmake/linux.cmake +++ b/cmake/linux.cmake @@ -14,11 +14,25 @@ function(linux_options) Not implemented as compiler selection is managed by CMake. Look to doc/cmake.rst for examples. ]] + option(GODOTCPP_USE_STATIC_CPP "Link libgcc and libstdc++ statically for better portability" ON) endfunction() #[===========================[ Target Generation ]===========================] function(linux_generate) + set(STATIC_CPP "$") + target_compile_definitions(godot-cpp PUBLIC LINUX_ENABLED UNIX_ENABLED) + # gersemi: off + target_link_options( + godot-cpp + PUBLIC + $<${STATIC_CPP}: + -static-libgcc + -static-libstdc++ + > + ) + # gersemi: on + common_compiler_flags() endfunction() diff --git a/tools/linux.py b/tools/linux.py index 9e85d8803..ae8019877 100644 --- a/tools/linux.py +++ b/tools/linux.py @@ -5,6 +5,7 @@ def options(opts): opts.Add(BoolVariable("use_llvm", "Use the LLVM compiler - only effective when targeting Linux", False)) + opts.Add(BoolVariable("use_static_cpp", "Link libgcc and libstdc++ statically for better portability", True)) def exists(env): @@ -37,6 +38,10 @@ def generate(env): env.Append(CCFLAGS=["-march=rv64gc"]) env.Append(LINKFLAGS=["-march=rv64gc"]) + # Link statically for portability + if env["use_static_cpp"]: + env.Append(LINKFLAGS=["-static-libgcc", "-static-libstdc++"]) + env.Append(CPPDEFINES=["LINUX_ENABLED", "UNIX_ENABLED"]) # Refer to https://github.com/godotengine/godot/blob/master/platform/linuxbsd/detect.py