From 39ec1549af7a281f8f431a057a4c860f7b2cfb80 Mon Sep 17 00:00:00 2001 From: Evan Klitzke Date: Wed, 10 Jun 2020 09:21:13 -0700 Subject: [PATCH] Build using LTO if compiler supports it (requires Cmake 3.9) --- CMakeLists.txt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 471f4a63..990c484b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.8) +cmake_minimum_required(VERSION 3.9) project(ccls LANGUAGES CXX) option(USE_SYSTEM_RAPIDJSON "Use system RapidJSON instead of the git submodule if exists" ON) @@ -30,6 +30,13 @@ set_property(TARGET ccls PROPERTY CXX_STANDARD 17) set_property(TARGET ccls PROPERTY CXX_STANDARD_REQUIRED ON) set_property(TARGET ccls PROPERTY CXX_EXTENSIONS OFF) +# Build using LTO if the compiler supports it +include(CheckIPOSupported) +check_ipo_supported(RESULT ipo OUTPUT error) +if (ipo) + set_property(TARGET ccls PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE) +endif() + # CMake sets MSVC for both MSVC and Clang(Windows) if(MSVC) # Common MSVC/Clang(Windows) options