Skip to content

Commit

Permalink
Build all examples successfully with CMake
Browse files Browse the repository at this point in the history
Signed-off-by: Björn Svensson <[email protected]>
  • Loading branch information
bjosv committed Jun 26, 2024
1 parent 3d9805e commit 194ccf3
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 62 deletions.
5 changes: 2 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ SET(valkey_sources
src/vkarray.c
src/vkutil.c)

SET(valkey_sources ${valkey_sources})

IF(WIN32)
ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS -DWIN32_LEAN_AND_MEAN)
ENDIF()
Expand Down Expand Up @@ -168,7 +166,8 @@ IF(ENABLE_SSL)
ENDIF()
FIND_PACKAGE(OpenSSL REQUIRED)
SET(valkey_ssl_sources
src/ssl.c)
src/ssl.c
src/valkeycluster_ssl.c)
ADD_LIBRARY(valkey_ssl ${valkey_ssl_sources})
ADD_LIBRARY(valkey::valkey_ssl ALIAS valkey_ssl)

Expand Down
146 changes: 87 additions & 59 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,61 +1,89 @@
INCLUDE(FindPkgConfig)
cmake_minimum_required(VERSION 3.0.0)
project(examples LANGUAGES C)

# Add path to enable <valkey/x.h> includes
include_directories(${CMAKE_SOURCE_DIR}/include)

# Check for GLib
include(FindPkgConfig)
pkg_check_modules(GLIB2 glib-2.0)
if(GLIB2_FOUND)
add_executable(example-async-glib async-glib.c)
target_include_directories(example-async-glib PUBLIC ${GLIB2_INCLUDE_DIRS})
target_link_libraries(example-async-glib valkey ${GLIB2_LIBRARIES})
endif()

find_path(LIBEV ev.h
HINTS /usr/local /usr/opt/local
ENV LIBEV_INCLUDE_DIR)
if(LIBEV)
add_executable(example-async-libev async-libev.c)
target_link_libraries(example-async-libev valkey ev)
endif()

find_path(LIBEVENT event.h)
if(LIBEVENT)
add_executable(example-async-libevent async-libevent.c)
target_link_libraries(example-async-libevent valkey event)

if(ENABLE_SSL)
add_executable(example-async-libevent-ssl async-libevent-ssl.c)
target_link_libraries(example-async-libevent-ssl valkey valkey_ssl event)
endif()
endif()

find_path(LIBHV hv/hv.h)
if(LIBHV)
add_executable(example-async-libhv async-libhv.c)
target_link_libraries(example-async-libhv valkey hv)
endif()

find_path(LIBUV uv.h)
if(LIBUV)
add_executable(example-async-libuv async-libuv.c)
target_link_libraries(example-async-libuv valkey uv)
endif()

find_path(LIBSDEVENT systemd/sd-event.h)
if(LIBSDEVENT)
add_executable(example-async-libsdevent async-libsdevent.c)
target_link_libraries(example-async-libsdevent valkey systemd)
endif()

if(APPLE)
find_library(CF CoreFoundation)
add_executable(example-async-macosx async-macosx.c)
target_link_libraries(example-async-macosx valkey ${CF})
endif()

if(ENABLE_SSL)
add_executable(example-blocking-ssl blocking-ssl.c)
target_link_libraries(example-blocking-ssl valkey valkey_ssl)
endif()

add_executable(example-blocking blocking.c)
target_link_libraries(example-blocking valkey)

add_executable(example-blocking-push blocking-push.c)
target_link_libraries(example-blocking-push valkey)

if(LIBEVENT)
add_executable(example-cluster-async cluster-async.c)
target_link_libraries(example-cluster-async valkey event)

if(ENABLE_SSL)
add_executable(example-cluster-async-tls cluster-async-tls.c)
target_link_libraries(example-cluster-async-tls valkey valkey_ssl event)
endif()

add_executable(example-cluster-clientside-caching-async cluster-clientside-caching-async.c)
target_link_libraries(example-cluster-clientside-caching-async valkey event)
endif()

add_executable(example-cluster-simple cluster-simple.c)
target_link_libraries(example-cluster-simple valkey)

PKG_CHECK_MODULES(GLIB2 glib-2.0)
if (GLIB2_FOUND)
INCLUDE_DIRECTORIES(${GLIB2_INCLUDE_DIRS})
LINK_DIRECTORIES(${GLIB2_LIBRARY_DIRS})
ADD_EXECUTABLE(async-glib async-glib.c)
TARGET_LINK_LIBRARIES(async-glib valkey ${GLIB2_LIBRARIES})
ENDIF(GLIB2_FOUND)

FIND_PATH(LIBEV ev.h
HINTS /usr/local /usr/opt/local
ENV LIBEV_INCLUDE_DIR)

if (LIBEV)
# Just compile and link with libev
ADD_EXECUTABLE(async-libev async-libev.c)
TARGET_LINK_LIBRARIES(async-libev valkey ev)
ENDIF()

FIND_PATH(LIBEVENT event.h)
if (LIBEVENT)
ADD_EXECUTABLE(async-libevent async-libevent.c)
TARGET_LINK_LIBRARIES(async-libevent valkey event)
ENDIF()

FIND_PATH(LIBHV hv/hv.h)
IF (LIBHV)
ADD_EXECUTABLE(async-libhv async-libhv.c)
TARGET_LINK_LIBRARIES(async-libhv valkey hv)
ENDIF()

FIND_PATH(LIBUV uv.h)
IF (LIBUV)
ADD_EXECUTABLE(async-libuv async-libuv.c)
TARGET_LINK_LIBRARIES(async-libuv valkey uv)
ENDIF()

FIND_PATH(LIBSDEVENT systemd/sd-event.h)
IF (LIBSDEVENT)
ADD_EXECUTABLE(async-libsdevent async-libsdevent.c)
TARGET_LINK_LIBRARIES(async-libsdevent valkey systemd)
ENDIF()

IF (APPLE)
FIND_LIBRARY(CF CoreFoundation)
ADD_EXECUTABLE(async-macosx async-macosx.c)
TARGET_LINK_LIBRARIES(async-macosx valkey ${CF})
ENDIF()

IF (ENABLE_SSL)
ADD_EXECUTABLE(example-ssl example-ssl.c)
TARGET_LINK_LIBRARIES(example-ssl valkey valkey_ssl)
ENDIF()

ADD_EXECUTABLE(example blocking.c)
TARGET_LINK_LIBRARIES(example valkey)

ADD_EXECUTABLE(blocking-push blocking-push.c)
TARGET_LINK_LIBRARIES(blocking-push valkey)
if(ENABLE_SSL)
add_executable(example-cluster-tls cluster-tls.c)
target_link_libraries(example-cluster-tls valkey valkey_ssl)
endif()

0 comments on commit 194ccf3

Please sign in to comment.