Skip to content

Commit

Permalink
Rework build system to build unified library.
Browse files Browse the repository at this point in the history
* Update Makefile  and CMakeLists.txt to build both standalone and
  cluster code.
* Update dict API to make the API non-static for cluster usage.
* Minor changes to a few examples and tests/test.c to get everything
  compiling.
* Use CMake pkg-config .in files in the Makefile

Fixes #22
  • Loading branch information
michael-grunder committed Jun 24, 2024
1 parent 00f5f24 commit a0fcb70
Show file tree
Hide file tree
Showing 10 changed files with 301 additions and 340 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
obj
lib
compile_commands.json
.cache
69 changes: 43 additions & 26 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ CMAKE_MINIMUM_REQUIRED(VERSION 3.0.0)

MACRO(getVersionBit name)
SET(VERSION_REGEX "^#define ${name} (.+)$")
FILE(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/valkey.h"
FILE(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/include/valkey/valkey.h"
VERSION_BIT REGEX ${VERSION_REGEX})
STRING(REGEX REPLACE ${VERSION_REGEX} "\\1" ${name} "${VERSION_BIT}")
ENDMACRO(getVersionBit)
Expand Down Expand Up @@ -32,13 +32,20 @@ SET(CMAKE_C_STANDARD 99)
SET(CMAKE_DEBUG_POSTFIX d)

SET(valkey_sources
alloc.c
async.c
valkey.c
net.c
read.c
sds.c
sockcompat.c)
src/adlist.c
src/alloc.c
src/async.c
src/command.c
src/crc16.c
src/dict.c
src/net.c
src/read.c
src/sds.c
src/sockcompat.c
src/valkey.c
src/valkeycluster.c
src/vkarray.c
src/vkutil.c)

SET(valkey_sources ${valkey_sources})

Expand Down Expand Up @@ -66,7 +73,11 @@ ELSEIF(CMAKE_SYSTEM_NAME MATCHES "SunOS")
TARGET_LINK_LIBRARIES(valkey PUBLIC socket)
ENDIF()

TARGET_INCLUDE_DIRECTORIES(valkey PUBLIC $<INSTALL_INTERFACE:include> $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
TARGET_INCLUDE_DIRECTORIES(valkey
PUBLIC
$<INSTALL_INTERFACE:include/valkey>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/valkey>
)

CONFIGURE_FILE(valkey.pc.in valkey.pc @ONLY)

Expand Down Expand Up @@ -158,10 +169,16 @@ IF(ENABLE_SSL)
ENDIF()
FIND_PACKAGE(OpenSSL REQUIRED)
SET(valkey_ssl_sources
ssl.c)
src/ssl.c)
ADD_LIBRARY(valkey_ssl ${valkey_ssl_sources})
ADD_LIBRARY(valkey::valkey_ssl ALIAS valkey_ssl)

TARGET_INCLUDE_DIRECTORIES(valkey_ssl
PRIVATE
$<INSTALL_INTERFACE:include/valkey>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/valkey>
)

IF (APPLE AND BUILD_SHARED_LIBS)
SET_PROPERTY(TARGET valkey_ssl PROPERTY LINK_FLAGS "-Wl,-undefined -Wl,dynamic_lookup")
ENDIF()
Expand Down Expand Up @@ -192,7 +209,7 @@ IF(ENABLE_SSL)
CONFIGURATIONS Debug RelWithDebInfo)
endif()

INSTALL(FILES valkey_ssl.h
INSTALL(FILES valkey_ssl.h valkeycluster_ssl.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/valkey)

INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/valkey_ssl.pc
Expand Down Expand Up @@ -220,21 +237,21 @@ IF(ENABLE_SSL)
DESTINATION ${CMAKE_CONF_INSTALL_DIR})
ENDIF()

IF(NOT DISABLE_TESTS)
ENABLE_TESTING()
ADD_EXECUTABLE(libvalkey-test test.c)
TARGET_LINK_LIBRARIES(libvalkey-test valkey)
IF(ENABLE_SSL_TESTS)
ADD_DEFINITIONS(-DVALKEY_TEST_SSL=1)
TARGET_LINK_LIBRARIES(libvalkey-test valkey_ssl)
ENDIF()
IF(ENABLE_ASYNC_TESTS)
ADD_DEFINITIONS(-DVALKEY_TEST_ASYNC=1)
TARGET_LINK_LIBRARIES(libvalkey-test event)
ENDIF()
ADD_TEST(NAME libvalkey-test
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/test.sh)
ENDIF()
#IF(NOT DISABLE_TESTS)
# ENABLE_TESTING()
# ADD_EXECUTABLE(libvalkey-test test.c)
# TARGET_LINK_LIBRARIES(libvalkey-test valkey)
# IF(ENABLE_SSL_TESTS)
# ADD_DEFINITIONS(-DVALKEY_TEST_SSL=1)
# TARGET_LINK_LIBRARIES(libvalkey-test valkey_ssl)
# ENDIF()
# IF(ENABLE_ASYNC_TESTS)
# ADD_DEFINITIONS(-DVALKEY_TEST_ASYNC=1)
# TARGET_LINK_LIBRARIES(libvalkey-test event)
# ENDIF()
# ADD_TEST(NAME libvalkey-test
# COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/test.sh)
#ENDIF()

# Add examples
IF(ENABLE_EXAMPLES)
Expand Down
Loading

0 comments on commit a0fcb70

Please sign in to comment.