From 941483c14d766a8ca347f4819ec5bac8fd8083fc Mon Sep 17 00:00:00 2001 From: "Daniel J. Hofmann" Date: Fri, 4 Sep 2015 18:51:18 +0200 Subject: [PATCH] Parallelize optimization and code generation for link time optimization. This parallelizes the `-flto` feature resulting in parallel optimization and code generation for link time optimization based on the number of logical processors available. Note: this has the side-effect of using more memory during linking. References: - https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html (see: -flto) - http://www.cmake.org/cmake/help/v3.0/module/ProcessorCount.htmMC --- CMakeLists.txt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b4523a551..b7940fab0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -124,14 +124,16 @@ endif() if(CMAKE_BUILD_TYPE MATCHES Release) message(STATUS "Configuring OSRM in release mode") # Check if LTO is available + include(ProcessorCount) + ProcessorCount(NPROC) set(LTO_FLAGS "") - check_cxx_compiler_flag("-flto" LTO_AVAILABLE) + check_cxx_compiler_flag("-flto=${NPROC}" LTO_AVAILABLE) if(LTO_AVAILABLE) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -flto") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -flto=${NPROC}") set(CHECK_LTO_SRC "int main(){return 0;}") check_cxx_source_compiles("${CHECK_LTO_SRC}" LTO_WORKS) if(LTO_WORKS) - message(STATUS "LTO working") + message(STATUS "LTO working") else() message(STATUS "LTO broken") set(CMAKE_CXX_FLAGS "${OLD_CXX_FLAGS}")