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 committed Jul 24, 2024
1 parent 2921303 commit 01b3346
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 01b3346

Please sign in to comment.