aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzhou13 <broken.zhou@gmail.com>2018-07-22 18:22:14 -0700
committerJustin M. Keyes <justinkz@gmail.com>2018-07-23 03:22:14 +0200
commitc8e7a447c5694e7e2a58f2b112530d896efa30ba (patch)
treeca72b62bf9f6ee42f5f100e94b2c0a7545d5476e
parent2000b6a64a9c1fe47d07d8441620abceaf545094 (diff)
downloadrneovim-c8e7a447c5694e7e2a58f2b112530d896efa30ba.tar.gz
rneovim-c8e7a447c5694e7e2a58f2b112530d896efa30ba.tar.bz2
rneovim-c8e7a447c5694e7e2a58f2b112530d896efa30ba.zip
build: Enable LTO (Link Time Optimization) #8654
-rw-r--r--CMakeLists.txt8
-rw-r--r--src/nvim/CMakeLists.txt12
2 files changed, 20 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 27cc02bd65..3c2e40ab8b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -85,6 +85,14 @@ endif()
option(ENABLE_LIBINTL "enable libintl" ON)
option(ENABLE_LIBICONV "enable libiconv" ON)
+if (MINGW)
+ # Disable LTO by default as it may not compile
+ # See https://github.com/Alexpux/MINGW-packages/issues/3516
+ # and https://github.com/neovim/neovim/pull/8654#issuecomment-402316672
+ option(ENABLE_LTO "enable link time optimization" OFF)
+else()
+ option(ENABLE_LTO "enable link time optimization" ON)
+endif()
# Set default build type.
if(NOT CMAKE_BUILD_TYPE)
diff --git a/src/nvim/CMakeLists.txt b/src/nvim/CMakeLists.txt
index 7106f76a6e..b32d54b28e 100644
--- a/src/nvim/CMakeLists.txt
+++ b/src/nvim/CMakeLists.txt
@@ -399,6 +399,10 @@ if(JEMALLOC_FOUND)
list(APPEND NVIM_EXEC_LINK_LIBRARIES ${JEMALLOC_LIBRARIES})
endif()
+if(POLICY CMP0069)
+ cmake_policy(SET CMP0069 NEW)
+endif()
+
add_executable(nvim ${NVIM_GENERATED_FOR_SOURCES} ${NVIM_GENERATED_FOR_HEADERS}
${NVIM_GENERATED_SOURCES} ${NVIM_SOURCES} ${NVIM_HEADERS})
target_link_libraries(nvim ${NVIM_EXEC_LINK_LIBRARIES})
@@ -407,6 +411,14 @@ install_helper(TARGETS nvim)
set_property(TARGET nvim APPEND PROPERTY
INCLUDE_DIRECTORIES ${LUA_PREFERRED_INCLUDE_DIRS})
+if(ENABLE_LTO AND (POLICY CMP0069))
+ include(CheckIPOSupported)
+ check_ipo_supported(RESULT IPO_SUPPORTED)
+ if(IPO_SUPPORTED AND (NOT CMAKE_BUILD_TYPE MATCHES Debug))
+ set_property(TARGET nvim PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
+ endif()
+endif()
+
if(WIN32)
# Copy DLLs and third-party tools to bin/ and install them along with nvim
add_custom_target(nvim_runtime_deps ALL