Skip to content

Commit 125c546

Browse files
committed
cmake: Add a flag to enable LTO
This adds -DLLVM_ENABLE_LTO, rather than forcing people to manually add -flto to the various _FLAGS variables. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@259766 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 50db127 commit 125c546

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

cmake/modules/HandleLLVMOptions.cmake

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,13 @@ 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)
665+
659666
# Plugin support
660667
# FIXME: Make this configurable.
661668
if(WIN32 OR CYGWIN)

docs/CMake.rst

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

350+
**LLVM_ENABLE_LTO**:BOOL
351+
Add the ``-flto`` flag to the compile and link command lines,
352+
enabling link-time optimization. Defaults to OFF.
353+
350354
**LLVM_PARALLEL_COMPILE_JOBS**:STRING
351355
Define the maximum number of concurrent compilation jobs.
352356

0 commit comments

Comments
 (0)