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()