mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-09-12 14:18:31 +09:00
[Chore] (CMake): Use ThinLTO with priority if possible.
This commit is contained in:
@@ -13,11 +13,30 @@ if (ANDROID)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (NOT CMAKE_BUILD_TYPE STREQUAL "Debug" OR MOBILEGL_FORCE_RELEASE_OPT)
|
if (NOT CMAKE_BUILD_TYPE STREQUAL "Debug" OR MOBILEGL_FORCE_RELEASE_OPT)
|
||||||
|
# Check if ThinLTO or LTO is suppported
|
||||||
include(CheckIPOSupported)
|
include(CheckIPOSupported)
|
||||||
|
include(CheckCCompilerFlag)
|
||||||
|
include(CheckCXXCompilerFlag)
|
||||||
|
|
||||||
check_ipo_supported(RESULT LTOSupported OUTPUT LTOError)
|
check_ipo_supported(RESULT LTOSupported OUTPUT LTOError)
|
||||||
|
|
||||||
if (LTOSupported)
|
if (LTOSupported)
|
||||||
|
# Check ThinLTO
|
||||||
|
check_c_compiler_flag("-flto=thin" HAS_THINLTO_C)
|
||||||
|
check_cxx_compiler_flag("-flto=thin" HAS_THINLTO_CXX)
|
||||||
|
if (HAS_THINLTO_C AND HAS_THINLTO_CXX)
|
||||||
|
message(STATUS "ThinLTO supported, using -flto=thin")
|
||||||
|
|
||||||
|
add_compile_options(-flto=thin)
|
||||||
|
add_link_options(-flto=thin)
|
||||||
|
else()
|
||||||
|
# ThinLTO is not supported
|
||||||
|
message(STATUS "ThinLTO not available, fallback to CMAKE IPO")
|
||||||
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
|
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
|
||||||
endif()
|
endif()
|
||||||
|
else()
|
||||||
|
message(STATUS "IPO not supported: ${LTOError}")
|
||||||
|
endif()
|
||||||
|
|
||||||
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang" AND NOT MATCHES "AppleClang")
|
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang" AND NOT MATCHES "AppleClang")
|
||||||
add_compile_options(-O3 -ffunction-sections -fdata-sections)
|
add_compile_options(-O3 -ffunction-sections -fdata-sections)
|
||||||
|
|||||||
Reference in New Issue
Block a user