From 974dab4e8f3885f70642cb4fad76b7109cafe6d1 Mon Sep 17 00:00:00 2001 From: Justin Bogner Date: Mon, 8 Feb 2016 21:01:24 +0000 Subject: [PATCH] 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. llvm-svn: 260143 --- cmake/modules/HandleLLVMOptions.cmake | 18 ++++++++++++------ docs/CMake.rst | 7 ++++--- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/cmake/modules/HandleLLVMOptions.cmake b/cmake/modules/HandleLLVMOptions.cmake index 99b23180bbb..8156e8c83ae 100644 --- a/cmake/modules/HandleLLVMOptions.cmake +++ b/cmake/modules/HandleLLVMOptions.cmake @@ -656,12 +656,18 @@ append_if(LLVM_BUILD_INSTRUMENTED "-fprofile-instr-generate" CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS) -option(LLVM_ENABLE_LTO "Enable link-time optimization" OFF) -append_if(LLVM_ENABLE_LTO "-flto" - CMAKE_CXX_FLAGS - CMAKE_C_FLAGS - CMAKE_EXE_LINKER_FLAGS - CMAKE_SHARED_LINKER_FLAGS) +option(LLVM_ENABLE_LTO "Build LLVM with LTO. May be specified as Thin or Full to use a particular kind of LTO" OFF) +string(TOUPPER "${LLVM_ENABLE_LTO}" uppercase_LLVM_ENABLE_LTO) +if(uppercase_LLVM_ENABLE_LTO STREQUAL "THIN") + append("-flto=thin" CMAKE_CXX_FLAGS CMAKE_C_FLAGS + CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS) +elseif(uppercase_LLVM_ENABLE_LTO STREQUAL "FULL") + append("-flto=full" CMAKE_CXX_FLAGS CMAKE_C_FLAGS + CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS) +elseif(LLVM_ENABLE_LTO) + append("-flto" CMAKE_CXX_FLAGS CMAKE_C_FLAGS + CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS) +endif() # Plugin support # FIXME: Make this configurable. diff --git a/docs/CMake.rst b/docs/CMake.rst index 12d74ace161..879e4627e41 100644 --- a/docs/CMake.rst +++ b/docs/CMake.rst @@ -351,9 +351,10 @@ LLVM-specific variables are ``Address``, ``Memory``, ``MemoryWithOrigins``, ``Undefined``, ``Thread``, and ``Address;Undefined``. Defaults to empty string. -**LLVM_ENABLE_LTO**:BOOL - Add the ``-flto`` flag to the compile and link command lines, - enabling link-time optimization. Defaults to OFF. +**LLVM_ENABLE_LTO**:STRING + Add ``-flto`` or ``-flto=`` flags to the compile and link command + lines, enabling link-time optimization. Possible values are ``Off``, + ``On``, ``Thin`` and ``Full``. Defaults to OFF. **LLVM_PARALLEL_COMPILE_JOBS**:STRING Define the maximum number of concurrent compilation jobs.