From 729d4bb91da9458df2da05ca5c214ee1ab331aa9 Mon Sep 17 00:00:00 2001 From: Zachary Michaels Date: Wed, 6 Aug 2014 12:52:25 -0400 Subject: User setting to turn LTO on and off This isn't currently working on mingw --- CMakeLists.txt | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ecb166661..857e927ff 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -92,11 +92,6 @@ else() else() set(WARNINGS "${WARNINGS} -Wlogical-op -Wno-error=maybe-uninitialized") endif() - # Since gcc 4.9 the LTO format is non-standard (slim), so we need the gcc-specific ar and ranlib binaries - if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9.0)) - set(CMAKE_AR "gcc-ar") - set(CMAKE_RANLIB "gcc-ranlib") - endif() if(MINGW) set(WARNINGS "${WARNINGS} -Wno-error=unused-value -Wno-error=unused-but-set-variable") set(MINGW_FLAG "${MINGW_FLAG} -DWIN32_LEAN_AND_MEAN") @@ -121,14 +116,23 @@ else() else() set(DEBUG_FLAGS "-g3 -O0") endif() + set(RELEASE_FLAGS "-Ofast -DNDEBUG -Wno-unused-variable") - if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + + set(USE_LTO false CACHE BOOL "Use Link-Time Optimization (Release mode only)") + if(USE_LTO) # There is a clang bug that does not allow to compile code that uses AES-NI intrinsics if -flto is enabled set(RELEASE_FLAGS "${RELEASE_FLAGS} -flto") + if(STATIC) + set(RELEASE_FLAGS "${RELEASE_FLAGS} -ffat-lto-objects") + endif() + # Since gcc 4.9 the LTO format is non-standard (slim), so we need the gcc-specific ar and ranlib binaries + if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9.0)) + set(CMAKE_AR "gcc-ar") + set(CMAKE_RANLIB "gcc-ranlib") + endif() endif() - #if(CMAKE_C_COMPILER_ID STREQUAL "GNU" AND NOT MINGW) - # set(RELEASE_FLAGS "${RELEASE_FLAGS} -fno-fat-lto-objects") - #endif() + set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${DEBUG_FLAGS}") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${DEBUG_FLAGS}") set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${RELEASE_FLAGS}") -- cgit v1.2.3