From bcde3b0e5396f3ea560d3429b8fab1d69a18a55a Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Thu, 14 Jul 2016 12:54:41 +0100 Subject: [PATCH] [Feature] Use -flto if possible when optimizations are enabled --- CMakeLists.txt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 22704af4e..5d126659d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -793,7 +793,13 @@ ENDIF(SUPPORT_FPIC) # Optimization flags IF(NOT CMAKE_C_OPT_FLAGS) IF(ENABLE_OPTIMIZATION MATCHES "ON") - SET(CMAKE_C_OPT_FLAGS "-O3 -fstrict-aliasing") + CHECK_C_COMPILER_FLAG(-flto SUPPORT_FLTO) + IF(SUPPORT_FLTO) + SET(CMAKE_C_OPT_FLAGS "-O3 -fstrict-aliasing -flto") + SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -flto") + ELSE() + SET(CMAKE_C_OPT_FLAGS "-O3 -fstrict-aliasing") + ENDIF() ELSE(ENABLE_OPTIMIZATION MATCHES "ON") IF(DEBUG_MODE MATCHES "ON") SET(CMAKE_C_OPT_FLAGS "-g -O0 -fstrict-aliasing") -- 2.39.5