From d51d75c3ed216a0a462800d2c7a5addd96548e67 Mon Sep 17 00:00:00 2001 From: Swung0x48 Date: Mon, 10 Nov 2025 14:24:58 +0800 Subject: [PATCH] [Fix] (CMakeLists): detect and enable LTO through CMake --- CMakeLists.txt | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c54c4b6b..09b57eea 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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()