Skip to content

Commit e29e6bc

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

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

cmake/linux.cmake

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,23 @@ 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+
target_link_options(
27+
godot-cpp
28+
PUBLIC
29+
$<${STATIC_CPP}:
30+
-static-libgcc
31+
-static-libstdc++
32+
>
33+
)
34+
2335
common_compiler_flags()
2436
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)