This is an automated email from the ASF dual-hosted git repository.

hulk pushed a commit to branch unstable
in repository https://gitbox.apache.org/repos/asf/incubator-kvrocks.git


The following commit(s) were added to refs/heads/unstable by this push:
     new bf13335a Add LTO/IPO compile support (#764)
bf13335a is described below

commit bf13335a3ef1aa295c66c3c07d2430fff4741768
Author: Ted Mostly <[email protected]>
AuthorDate: Sun Nov 20 20:38:37 2022 +0800

    Add LTO/IPO compile support (#764)
    
    Co-authored-by: PragmaTwice <[email protected]>
    Co-authored-by: tison <[email protected]>
---
 CMakeLists.txt | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8435c0ae..9177509b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -27,6 +27,7 @@ option(ASAN_WITH_LSAN "enable leak santinizer while address 
santinizer is enable
 option(ENABLE_STATIC_LIBSTDCXX "link kvrocks with static library of libstd++ 
instead of shared library" ON)
 option(USE_LUAJIT "use luaJIT instead of lua" OFF)
 option(ENABLE_OPENSSL "enable openssl to support tls connection" OFF)
+option(ENABLE_IPO "enable interprocedural optimization" ON)
 option(ENABLE_UNWIND "enable libunwind in glog" ON)
 
 if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
@@ -186,6 +187,20 @@ if(ENABLE_OPENSSL)
     target_compile_definitions(kvrocks_objs PUBLIC ENABLE_OPENSSL)
 endif()
 
+if(ENABLE_IPO)
+    include(CheckIPOSupported)
+    check_ipo_supported(RESULT ipo_result OUTPUT ipo_output LANGUAGES CXX)
+
+    if(ipo_result)
+        set_property(TARGET kvrocks_objs PROPERTY INTERPROCEDURAL_OPTIMIZATION 
TRUE)
+        if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
+            target_link_libraries(kvrocks_objs PUBLIC "-fuse-ld=lld")
+        endif()
+    else()
+        message(WARNING "IPO is not supported: ${ipo_output}")
+    endif()
+endif()
+
 # kvrocks main target
 add_executable(kvrocks src/main.cc)
 target_link_libraries(kvrocks PRIVATE kvrocks_objs ${EXTERNAL_LIBS})

Reply via email to