Skip to content

Commit

Permalink
Add LTO/IPO compile support (#764)
Browse files Browse the repository at this point in the history
Co-authored-by: PragmaTwice <twice.mliu@gmail.com>
Co-authored-by: tison <wander4096@gmail.com>
  • Loading branch information
3 people authored Nov 20, 2022
1 parent 0c4d4b7 commit bf13335
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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})
Expand Down

0 comments on commit bf13335

Please sign in to comment.