[Fix] (CMakeLists): detect and enable LTO through CMake

This commit is contained in:
2025-11-10 14:24:58 +08:00
parent c30ce008ca
commit d51d75c3ed
+8 -3
View File
@@ -5,12 +5,17 @@ project("MobileGL")
option(MOBILEGL_FORCE_RELEASE_OPT "Enable Release optimization flags in Debug build" OFF)
if (NOT CMAKE_BUILD_TYPE STREQUAL "Debug" OR MOBILEGL_FORCE_RELEASE_OPT)
include(CheckIPOSupported)
check_ipo_supported(RESULT LTOSupported OUTPUT LTOError)
if (LTOSupported)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
endif()
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang|AppleClang")
add_compile_options(-O3 -ffunction-sections -fdata-sections -flto=thin)
add_link_options(-flto=thin -Wl,--gc-sections)
add_compile_options(-O3 -ffunction-sections -fdata-sections)
add_link_options(-Wl,--gc-sections)
elseif (CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
add_compile_options(/O2 /GL)
add_link_options(/LTCG)
endif()
endif()