Skip to content

Commit b0f4190

Browse files
committed
Implement use_static_cpp flag for Linux
1 parent f08e781 commit b0f4190

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

cmake/linux.cmake

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,25 @@ function(linux_options)
1414
Not implemented as compiler selection is managed by CMake. Look to
1515
doc/cmake.rst for examples.
1616
]]
17+
option(GODOTCPP_USE_STATIC_CPP "Link libgcc and libstdc++ statically for better portability" ON)
1718
endfunction()
1819

1920
#[===========================[ Target Generation ]===========================]
2021
function(linux_generate)
22+
set(STATIC_CPP "$<BOOL:${GODOTCPP_USE_STATIC_CPP}>")
23+
2124
target_compile_definitions(godot-cpp PUBLIC LINUX_ENABLED UNIX_ENABLED)
2225

26+
# gersemi: off
27+
target_link_options(
28+
godot-cpp
29+
PUBLIC
30+
$<${STATIC_CPP}:
31+
-static-libgcc
32+
-static-libstdc++
33+
>
34+
)
35+
# gersemi: on
36+
2337
common_compiler_flags()
2438
endfunction()

tools/linux.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
def options(opts):
77
opts.Add(BoolVariable("use_llvm", "Use the LLVM compiler - only effective when targeting Linux", False))
8+
opts.Add(BoolVariable("use_static_cpp", "Link libgcc and libstdc++ statically for better portability", True))
89

910

1011
def exists(env):
@@ -37,6 +38,10 @@ def generate(env):
3738
env.Append(CCFLAGS=["-march=rv64gc"])
3839
env.Append(LINKFLAGS=["-march=rv64gc"])
3940

41+
# Link statically for portability
42+
if env["use_static_cpp"]:
43+
env.Append(LINKFLAGS=["-static-libgcc", "-static-libstdc++"])
44+
4045
env.Append(CPPDEFINES=["LINUX_ENABLED", "UNIX_ENABLED"])
4146

4247
# Refer to https://github.com/godotengine/godot/blob/master/platform/linuxbsd/detect.py

0 commit comments

Comments
 (0)