summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomi Valkeinen <tomi.valkeinen@ti.com>2016-05-22 22:22:37 +0300
committerTomi Valkeinen <tomi.valkeinen@ti.com>2016-05-23 09:43:27 +0300
commitbeae6161609c9d418b9e9f03c89f934d99964bdc (patch)
treed95d04d7da1a3dcfdd9bbe6a950f395bfbc87628
parent17b890d342473d4ff0559dc35eea56f5c9ae1ae0 (diff)
Automatically use -flto
-rw-r--r--CMakeLists.txt17
1 files changed, 12 insertions, 5 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 1308650..b968102 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -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)