Commit de89bd05 authored by Rafael Kitover's avatar Rafael Kitover
Browse files

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.
parent 268c6384
......@@ -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()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment