Skip to content
Closed
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
20 changes: 20 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,26 @@ endif()

endif() # NOT MATSDK_USE_VCPKG_DEPS (compiler flags)

# --- Dead-strip enablement (applies in BOTH vendored and vcpkg modes) ---------
# Split functions/data into separate COMDATs/sections so a consumer's linker can
# drop unreferenced SDK code: MSVC /OPT:REF + /OPT:ICF, GNU/Clang --gc-sections,
# Apple ld -dead_strip. The vendored-deps flag block above sets these only when
# NOT MATSDK_USE_VCPKG_DEPS, and never sets /Gy at all on MSVC -- so the vcpkg
# build (the one packaged for downstream consumers) and every MSVC build link
Comment on lines +209 to +214
# whole .obj files instead of individual functions. This block closes that gap
# and matches the MSBuild Release projects, which already enable
# FunctionLevelLinking + OptimizeReferences + EnableCOMDATFolding.
if(MSVC)
add_compile_options(/Gy /Gw)
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang")
# -fdata-sections historically conflicted with bitcode on AppleClang, and the
# mach-o linker already dead-strips at symbol granularity with -dead_strip.
add_compile_options(-ffunction-sections)
Comment on lines +220 to +223
else()
# GCC / Clang (Linux, Android, MinGW)
add_compile_options(-ffunction-sections -fdata-sections)
endif()

include(tools/Utils.cmake)
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
Expand Down
Loading