Skip to content

Commit

Permalink
Add cmake support for RDMA
Browse files Browse the repository at this point in the history
Signed-off-by: zhenwei pi <[email protected]>
  • Loading branch information
pizhenwei authored and michael-grunder committed Aug 1, 2024
1 parent b58fe2f commit 35e0ec2
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
48 changes: 48 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ OPTION(DISABLE_TESTS "If tests should be compiled or not" OFF)
OPTION(ENABLE_EXAMPLES "Enable building valkey examples" OFF)
option(ENABLE_IPV6_TESTS "Enable IPv6 tests requiring special prerequisites" OFF)
OPTION(ENABLE_NUGET "Install NuGET packaging details" OFF)
OPTION(ENABLE_RDMA "Build valkey_rdma for RDMA support" OFF)

# valkey requires C99
SET(CMAKE_C_STANDARD 99)
Expand Down Expand Up @@ -227,6 +228,53 @@ IF(ENABLE_SSL)
DESTINATION ${CMAKE_CONF_INSTALL_DIR})
ENDIF()

if(ENABLE_RDMA)
find_library(RDMACM_LIBRARIES rdmacm)
find_library(IBVERBS_LIBRARIES ibverbs)
set(valkey_rdma_sources src/rdma.c)
add_library(valkey_rdma ${valkey_rdma_sources})
add_library(valkey::valkey_rdma ALIAS valkey_rdma)

target_link_libraries(valkey_rdma LINK_PRIVATE ${RDMACM_LIBRARIES} ${IBVERBS_LIBRARIES})
target_include_directories(valkey_rdma
PRIVATE
$<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/valkey>
)

set_target_properties(valkey_rdma
PROPERTIES
WINDOWS_EXPORT_ALL_SYMBOLS TRUE
VERSION "${LIBVALKEY_SONAME}")
configure_file(valkey_rdma.pc.in valkey_rdma.pc @ONLY)

install(TARGETS valkey_rdma
EXPORT valkey_rdma-targets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})

install(FILES ${CMAKE_CURRENT_BINARY_DIR}/valkey_rdma.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)

export(EXPORT valkey_rdma-targets
FILE "${CMAKE_CURRENT_BINARY_DIR}/valkey_rdma-targets.cmake"
NAMESPACE valkey::)

set(CMAKE_CONF_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/valkey_rdma)
configure_package_config_file(valkey_rdma-config.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/valkey_rdma-config.cmake
INSTALL_DESTINATION ${CMAKE_CONF_INSTALL_DIR}
PATH_VARS INCLUDE_INSTALL_DIR)

install(EXPORT valkey_rdma-targets
FILE valkey_rdma-targets.cmake
NAMESPACE valkey::
DESTINATION ${CMAKE_CONF_INSTALL_DIR})

install(FILES ${CMAKE_CURRENT_BINARY_DIR}/valkey_rdma-config.cmake
DESTINATION ${CMAKE_CONF_INSTALL_DIR})
endif()

# Add tests
if(NOT DISABLE_TESTS)
# Make sure ctest prints the output when a test fails.
Expand Down
5 changes: 5 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ endif()
if(SSL_LIBRARY)
set_property(TEST client_test PROPERTY ENVIRONMENT "TEST_SSL=1")
endif()
if(ENABLE_RDMA)
target_compile_definitions(client_test PUBLIC VALKEY_TEST_RDMA=1)
target_link_libraries(client_test valkey_rdma)
set_property(TEST client_test PROPERTY ENVIRONMENT "TEST_RDMA=1")
endif()

# Add cluster tests if we have libevent
if (LIBEVENT_LIBRARY)
Expand Down
13 changes: 13 additions & 0 deletions valkey_rdma-config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
@PACKAGE_INIT@

set_and_check(valkey_rdma_INCLUDEDIR "@PACKAGE_INCLUDE_INSTALL_DIR@")

if(NOT TARGET valkey::valkey_rdma)
INCLUDE(${CMAKE_CURRENT_LIST_DIR}/valkey_rdma-targets.cmake)
endif()

set(valkey_rdma_LIBRARIES valkey::valkey_rdma)
set(valkey_rdma_INCLUDE_DIRS ${valkey_rdma_INCLUDEDIR})

check_required_components(valkey_rdma)

0 comments on commit 35e0ec2

Please sign in to comment.