Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit dffa09f

Browse files
committed
Merge pull request #7 from gottesmm/add-support-for-enable-lto
Add support for -DLLVM_ENABLE_LTO
2 parents 752e143 + a4b7bbb commit dffa09f

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

cmake/modules/HandleLLVMOptions.cmake

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,19 @@ append_if(LLVM_BUILD_INSTRUMENTED "-fprofile-instr-generate"
635635
CMAKE_EXE_LINKER_FLAGS
636636
CMAKE_SHARED_LINKER_FLAGS)
637637

638+
set(LLVM_ENABLE_LTO OFF CACHE STRING "Build LLVM with LTO. May be specified as Thin or Full to use a particular kind of LTO")
639+
string(TOUPPER "${LLVM_ENABLE_LTO}" uppercase_LLVM_ENABLE_LTO)
640+
if(uppercase_LLVM_ENABLE_LTO STREQUAL "THIN")
641+
append("-flto=thin" CMAKE_CXX_FLAGS CMAKE_C_FLAGS
642+
CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS)
643+
elseif(uppercase_LLVM_ENABLE_LTO STREQUAL "FULL")
644+
append("-flto=full" CMAKE_CXX_FLAGS CMAKE_C_FLAGS
645+
CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS)
646+
elseif(LLVM_ENABLE_LTO)
647+
append("-flto" CMAKE_CXX_FLAGS CMAKE_C_FLAGS
648+
CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS)
649+
endif()
650+
638651
# Plugin support
639652
# FIXME: Make this configurable.
640653
if(WIN32 OR CYGWIN)

docs/CMake.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,11 @@ LLVM-specific variables
347347
are ``Address``, ``Memory``, ``MemoryWithOrigins``, ``Undefined``, ``Thread``,
348348
and ``Address;Undefined``. Defaults to empty string.
349349

350+
**LLVM_ENABLE_LTO**:STRING
351+
Add ``-flto`` or ``-flto=`` flags to the compile and link command
352+
lines, enabling link-time optimization. Possible values are ``Off``,
353+
``On``, ``Thin`` and ``Full``. Defaults to OFF.
354+
350355
**LLVM_PARALLEL_COMPILE_JOBS**:STRING
351356
Define the maximum number of concurrent compilation jobs.
352357

0 commit comments

Comments
 (0)