use num cpu cores to parallelize LTO link with gcc

Use the `cmake` `ProcessorCount` module to determine the number of CPU
threads, and set the `-flto` flag for gcc to `-flto=${num_cpus}` if the
number of CPU threads is detected and is greater than `1`.

clang does not support this.
This commit is contained in:
Rafael Kitover 2017-09-19 06:58:48 -07:00
parent 268c638456
commit de89bd0561
1 changed files with 8 additions and 1 deletions

View File

@ -307,13 +307,20 @@ IF(WIN32)
ENDIF()
ENDIF()
include(ProcessorCount)
ProcessorCount(num_cpus)
# Compiler flags
IF(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID STREQUAL Clang)
SET(LTO_FLAGS "")
IF(ENABLE_LTO)
IF(CMAKE_COMPILER_IS_GNUCXX)
SET(LTO_FLAGS -flto=10 -ffat-lto-objects)
if(num_cpus GREATER 1)
SET(LTO_FLAGS -flto=${num_cpus} -ffat-lto-objects)
else()
SET(LTO_FLAGS -flto -ffat-lto-objects)
endif()
ELSE()
SET(LTO_FLAGS -flto)
ENDIF()