From bb23a9b9f2c32a1557378fd2234273e705789eb9 Mon Sep 17 00:00:00 2001 From: Matt Clarkson Date: Thu, 30 Apr 2015 14:10:52 +0100 Subject: [PATCH] Compile with link time optimisation Can provide speed improvements --- CMakeLists.txt | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 65d807d0..6a9a4493 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,6 +2,7 @@ cmake_minimum_required (VERSION 2.8.11) project (benchmark) option(BENCHMARK_ENABLE_TESTING "Enable testing of the benchmark library." ON) +option(BENCHMARK_ENABLE_LTO "Enable link time optimisation of the benchmark library." OFF) # Make sure we can import out CMake functions list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") @@ -41,9 +42,25 @@ add_cxx_compiler_flag(-pedantic-errors) add_cxx_compiler_flag(-Wshorten-64-to-32) add_cxx_compiler_flag(-Wfloat-equal) add_cxx_compiler_flag(-Wzero-as-null-pointer-constant) + # Release flags add_cxx_compiler_flag(-fno-strict-aliasing RELEASE) +# Link time optimisation +if (BENCHMARK_ENABLE_LTO) + add_cxx_compiler_flag(-flto) + if ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU") + find_program(GCC_AR gcc-ar) + if (GCC_AR) + set(CMAKE_AR ${GCC_AR}) + endif() + find_program(GCC_RANLIB gcc-ranlib) + if (GCC_RANLIB) + set(CMAKE_RANLIB ${GCC_RANLIB}) + endif() + endif() +endif() + add_cxx_compiler_flag(-Wthread-safety) if (HAVE_WTHREAD_SAFETY) add_definitions(-DHAVE_WTHREAD_SAFETY)