Automatically use -flto
authorTomi Valkeinen <tomi.valkeinen@ti.com>
Sun, 22 May 2016 19:22:37 +0000 (22:22 +0300)
committerTomi Valkeinen <tomi.valkeinen@ti.com>
Mon, 23 May 2016 06:43:27 +0000 (09:43 +0300)
CMakeLists.txt

index 13086508ca82ea2720c67592274298f7cfca1a8c..b968102bdfd8e537d198ee4a28b1b16ba7bf495d 100644 (file)
@@ -1,15 +1,18 @@
 cmake_minimum_required(VERSION 2.8)
 project(kms++)
 
+include(CheckCXXCompilerFlag)
+
 IF(NOT CMAKE_BUILD_TYPE)
     message(STATUS "Setting build type to 'Release' as none was specified.")
     SET(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
     set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
 ENDIF()
 
+string(TOUPPER "${CMAKE_BUILD_TYPE}" U_CMAKE_BUILD_TYPE)
+
 set(LIBKMS_ENABLE_PYTHON ON CACHE BOOL "Enable Python wrappers")
 set(LIBKMS_ENABLE_KMSCUBE OFF CACHE BOOL "Enable kmscube")
-set(LIBKMS_ENABLE_LTO OFF CACHE BOOL "Enable LTO")
 
 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall")
 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wextra -Wno-unused-parameter")
@@ -19,10 +22,14 @@ set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
 # static link libc
 # set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++")
 
-if(LIBKMS_ENABLE_LTO)
-       set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -flto -fwhole-program")
-       set(CMAKE_AR gcc-ar)
-       set(CMAKE_RANLIB gcc-ranlib)
+if (NOT ${U_CMAKE_BUILD_TYPE} MATCHES DEBUG)
+    CHECK_CXX_COMPILER_FLAG("-flto" HAS_LTO_FLAG)
+
+    if (HAS_LTO_FLAG)
+        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -flto")
+        set(CMAKE_AR gcc-ar)
+        set(CMAKE_RANLIB gcc-ranlib)
+    endif()
 endif()
 
 find_package(PkgConfig REQUIRED)