From ada23c87e7edb50cb238c19ec6334f2da01422cc Mon Sep 17 00:00:00 2001 From: Kornel Benko Date: Mon, 22 Apr 2019 18:49:03 +0200 Subject: [PATCH] Cmake build: Use interprocedural optimization if possible With gnu compilers this adds -flto and -fno-fat-lto-objects to compiler and linker flags. --- 3rdparty/hunspell/CMakeLists.txt | 6 +++++- 3rdparty/libiconv/CMakeLists.txt | 7 ++++++- 3rdparty/mythes/CMakeLists.txt | 6 +++++- 3rdparty/zlib/CMakeLists.txt | 7 ++++++- CMakeLists.txt | 12 ++++++++++++ 5 files changed, 34 insertions(+), 4 deletions(-) diff --git a/3rdparty/hunspell/CMakeLists.txt b/3rdparty/hunspell/CMakeLists.txt index 72e5c52133..9dbb56cd79 100644 --- a/3rdparty/hunspell/CMakeLists.txt +++ b/3rdparty/hunspell/CMakeLists.txt @@ -1,5 +1,9 @@ -cmake_minimum_required(VERSION 2.8) +cmake_minimum_required(VERSION 3.1) + +if (POLICY CMP0069) + cmake_policy(SET CMP0069 NEW) +endif() project(hunspell) diff --git a/3rdparty/libiconv/CMakeLists.txt b/3rdparty/libiconv/CMakeLists.txt index 68b7dd76c8..7f5c73bf7f 100644 --- a/3rdparty/libiconv/CMakeLists.txt +++ b/3rdparty/libiconv/CMakeLists.txt @@ -5,7 +5,12 @@ # Please note that the package source code is licensed under its own license. project ( libiconv C ) -cmake_minimum_required ( VERSION 2.8 ) +cmake_minimum_required(VERSION 3.1) + +if (POLICY CMP0069) + cmake_policy(SET CMP0069 NEW) +endif() + set(CMAKE_MODULE_PATH .) include ( configure.cmake ) diff --git a/3rdparty/mythes/CMakeLists.txt b/3rdparty/mythes/CMakeLists.txt index c6d11780d9..9457df2b73 100644 --- a/3rdparty/mythes/CMakeLists.txt +++ b/3rdparty/mythes/CMakeLists.txt @@ -1,4 +1,8 @@ -cmake_minimum_required(VERSION 2.8) +cmake_minimum_required(VERSION 3.1) + +if (POLICY CMP0069) + cmake_policy(SET CMP0069 NEW) +endif() set(VERSION "1.2.5") set(SRCDIR ${CMAKE_CURRENT_SOURCE_DIR}/${VERSION}) diff --git a/3rdparty/zlib/CMakeLists.txt b/3rdparty/zlib/CMakeLists.txt index a9fad6fa54..a8ca489369 100644 --- a/3rdparty/zlib/CMakeLists.txt +++ b/3rdparty/zlib/CMakeLists.txt @@ -1,4 +1,9 @@ -cmake_minimum_required(VERSION 2.4.4) +cmake_minimum_required(VERSION 3.1) + +if (POLICY CMP0069) + cmake_policy(SET CMP0069 NEW) +endif() + set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS ON) project(zlib C) diff --git a/CMakeLists.txt b/CMakeLists.txt index e421c535b9..e8c3c32c94 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -81,6 +81,18 @@ if(NOT help AND NOT HELP) message(FATAL_ERROR "Exiting") endif() endif() + # Enable LTO if supported + if (POLICY CMP0069) + cmake_policy(SET CMP0069 NEW) + include(CheckIPOSupported) + check_ipo_supported(RESULT result OUTPUT reason LANGUAGES CXX) + if(result) + message(STATUS "Setting IPO True") + set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE) + else() + message(STATUS "Not setting IPO , result = ${result}, reason = ${reason}") + endif() + endif() endif() if(UNIX) -- 2.39.5