Skip to content
Merged
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
2 changes: 2 additions & 0 deletions cmake/android.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,7 @@ endfunction()
function(android_generate)
target_compile_definitions(godot-cpp PUBLIC ANDROID_ENABLED UNIX_ENABLED)

target_link_options(godot-cpp PUBLIC -Wl,--gc-sections)

common_compiler_flags()
endfunction()
4 changes: 3 additions & 1 deletion cmake/common_compiler_flags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ function(common_compiler_flags)

$<${HOT_RELOAD}:$<${IS_GNU}:-fno-gnu-unique>>

$<${NOT_MSVC}:$<$<NOT:$<PLATFORM_ID:Windows>>:-ffunction-sections -fdata-sections>>

# MSVC only
$<${IS_MSVC}:
# /MP isn't valid for clang-cl with msvc frontend
Expand Down Expand Up @@ -185,7 +187,7 @@ function(common_compiler_flags)
$<$<NOT:${DEBUG_SYMBOLS}>:
$<${IS_GNU}:-s>
$<${IS_CLANG}:-s>
$<${IS_APPLECLANG}:-Wl,-S -Wl,-x -Wl,-dead_strip>
$<${IS_APPLECLANG}:-Wl,-S -Wl,-x>
>
PRIVATE
$<${IS_MSVC}:
Expand Down
2 changes: 2 additions & 0 deletions cmake/ios.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,7 @@ endfunction()
function(ios_generate)
target_compile_definitions(godot-cpp PUBLIC IOS_ENABLED UNIX_ENABLED)

target_link_options(godot-cpp PUBLIC -Wl,-dead_strip)

common_compiler_flags()
endfunction()
1 change: 1 addition & 0 deletions cmake/linux.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ function(linux_generate)
target_link_options(
godot-cpp
PUBLIC
-Wl,--gc-sections
$<${STATIC_CPP}:
-static-libgcc
-static-libstdc++
Expand Down
2 changes: 2 additions & 0 deletions cmake/macos.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,7 @@ endfunction()
function(macos_generate)
target_compile_definitions(godot-cpp PUBLIC MACOS_ENABLED UNIX_ENABLED)

target_link_options(godot-cpp PUBLIC -Wl,-dead_strip)

common_compiler_flags()
endfunction()
1 change: 1 addition & 0 deletions cmake/windows.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ function(windows_generate)
PUBLIC
$<${NOT_MSVC}:
-Wl,--no-undefined
-Wl,--gc-sections
$<${STATIC_CPP}:
-static
-static-libgcc
Expand Down
2 changes: 2 additions & 0 deletions tools/android.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ def generate(env):
env.Append(CCFLAGS=arch_info["ccflags"])
env.Append(LINKFLAGS=["--target=" + arch_info["target"] + env["android_api_level"], "-march=" + arch_info["march"]])

env.Append(LINKFLAGS=["-Wl,--gc-sections"])

env.Append(CPPDEFINES=["ANDROID_ENABLED", "UNIX_ENABLED"])

# Refer to https://github.com/godotengine/godot/blob/master/platform/android/detect.py
Expand Down
5 changes: 4 additions & 1 deletion tools/common_compiler_flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ def generate(env):
env.Append(CXXFLAGS=["/EHsc"])

if not env.get("is_msvc", False):
if not env["use_mingw"]:
env.Append(CCFLAGS=["-ffunction-sections", "-fdata-sections"])

if env["symbols_visibility"] == "visible":
env.Append(CCFLAGS=["-fvisibility=default"])
env.Append(LINKFLAGS=["-fvisibility=default"])
Expand Down Expand Up @@ -108,7 +111,7 @@ def generate(env):
else:
if using_clang(env) and not is_vanilla_clang(env) and not env["use_mingw"]:
# Apple Clang, its linker doesn't like -s.
env.Append(LINKFLAGS=["-Wl,-S", "-Wl,-x", "-Wl,-dead_strip"])
env.Append(LINKFLAGS=["-Wl,-S", "-Wl,-x"])
else:
env.Append(LINKFLAGS=["-s"])

Expand Down
2 changes: 2 additions & 0 deletions tools/ios.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ def generate(env):
env.Append(CCFLAGS=["-isysroot", env["IOS_SDK_PATH"]])
env.Append(LINKFLAGS=["-isysroot", env["IOS_SDK_PATH"], "-F" + env["IOS_SDK_PATH"]])

env.Append(LINKFLAGS=["-Wl,-dead_strip"])

env.Append(CPPDEFINES=["IOS_ENABLED", "UNIX_ENABLED"])

# Refer to https://github.com/godotengine/godot/blob/master/platform/ios/detect.py:
Expand Down
2 changes: 2 additions & 0 deletions tools/linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ def generate(env):
env.Append(CCFLAGS=["-march=rv64gc"])
env.Append(LINKFLAGS=["-march=rv64gc"])

env.Append(LINKFLAGS=["-Wl,--gc-sections"])

# Link statically for portability
if env["use_static_cpp"]:
env.Append(LINKFLAGS=["-static-libgcc", "-static-libstdc++"])
Expand Down
2 changes: 2 additions & 0 deletions tools/macos.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ def generate(env):
env.Append(CCFLAGS=["-isysroot", env["macos_sdk_path"]])
env.Append(LINKFLAGS=["-isysroot", env["macos_sdk_path"]])

env.Append(LINKFLAGS=["-Wl,-dead_strip"])

env.Append(CPPDEFINES=["MACOS_ENABLED", "UNIX_ENABLED"])

# Refer to https://github.com/godotengine/godot/blob/master/platform/macos/detect.py
Expand Down
4 changes: 2 additions & 2 deletions tools/windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def generate(env):
env["SHLIBSUFFIX"] = ".dll"

env.Append(CCFLAGS=["-Wwrite-strings"])
env.Append(LINKFLAGS=["-Wl,--no-undefined"])
env.Append(LINKFLAGS=["-Wl,--no-undefined", "-Wl,--gc-sections"])
if env["use_static_cpp"]:
env.Append(
LINKFLAGS=[
Expand Down Expand Up @@ -186,7 +186,7 @@ def generate(env):
env["SHLIBSUFFIX"] = ".dll"

env.Append(CCFLAGS=["-Wwrite-strings"])
env.Append(LINKFLAGS=["-Wl,--no-undefined"])
env.Append(LINKFLAGS=["-Wl,--no-undefined", "-Wl,--gc-sections"])
if env["use_static_cpp"]:
env.Append(
LINKFLAGS=[
Expand Down
Loading