Skip to content

Commit 1d15d57

Browse files
committed
cmake: Accept "thin" or "full" as arguments to -DLLVM_ENABLE_LTO
Mehdi suggested in a review of r259766 that it's also useful to easily set the type of LTO. Augment the cmake variable to support that. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@260143 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 307f4d0 commit 1d15d57

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

cmake/modules/HandleLLVMOptions.cmake

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -656,12 +656,18 @@ append_if(LLVM_BUILD_INSTRUMENTED "-fprofile-instr-generate"
656656
CMAKE_EXE_LINKER_FLAGS
657657
CMAKE_SHARED_LINKER_FLAGS)
658658

659-
option(LLVM_ENABLE_LTO "Enable link-time optimization" OFF)
660-
append_if(LLVM_ENABLE_LTO "-flto"
661-
CMAKE_CXX_FLAGS
662-
CMAKE_C_FLAGS
663-
CMAKE_EXE_LINKER_FLAGS
664-
CMAKE_SHARED_LINKER_FLAGS)
659+
option(LLVM_ENABLE_LTO "Build LLVM with LTO. May be specified as Thin or Full to use a particular kind of LTO" OFF)
660+
string(TOUPPER "${LLVM_ENABLE_LTO}" uppercase_LLVM_ENABLE_LTO)
661+
if(uppercase_LLVM_ENABLE_LTO STREQUAL "THIN")
662+
append("-flto=thin" CMAKE_CXX_FLAGS CMAKE_C_FLAGS
663+
CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS)
664+
elseif(uppercase_LLVM_ENABLE_LTO STREQUAL "FULL")
665+
append("-flto=full" CMAKE_CXX_FLAGS CMAKE_C_FLAGS
666+
CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS)
667+
elseif(LLVM_ENABLE_LTO)
668+
append("-flto" CMAKE_CXX_FLAGS CMAKE_C_FLAGS
669+
CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS)
670+
endif()
665671

666672
# Plugin support
667673
# FIXME: Make this configurable.

docs/CMake.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -351,9 +351,10 @@ LLVM-specific variables
351351
are ``Address``, ``Memory``, ``MemoryWithOrigins``, ``Undefined``, ``Thread``,
352352
and ``Address;Undefined``. Defaults to empty string.
353353

354-
**LLVM_ENABLE_LTO**:BOOL
355-
Add the ``-flto`` flag to the compile and link command lines,
356-
enabling link-time optimization. Defaults to OFF.
354+
**LLVM_ENABLE_LTO**:STRING
355+
Add ``-flto`` or ``-flto=`` flags to the compile and link command
356+
lines, enabling link-time optimization. Possible values are ``Off``,
357+
``On``, ``Thin`` and ``Full``. Defaults to OFF.
357358

358359
**LLVM_PARALLEL_COMPILE_JOBS**:STRING
359360
Define the maximum number of concurrent compilation jobs.

0 commit comments

Comments
 (0)