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
This commit is contained in:
Daniel J. Hofmann 2015-09-04 18:51:18 +02:00
parent 17d8e65c64
commit 941483c14d

View File

@ -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}")