2019-03-31 16:17:19 +00:00
|
|
|
CMAKE_MINIMUM_REQUIRED(VERSION 3.4.0)
|
2018-09-25 23:44:58 +00:00
|
|
|
INCLUDE(GNUInstallDirs)
|
2019-02-06 19:14:46 +00:00
|
|
|
PROJECT(hiredis)
|
|
|
|
|
2019-09-01 10:47:25 +00:00
|
|
|
OPTION(ENABLE_SSL "Build hiredis_ssl for SSL support" OFF)
|
2019-11-04 06:00:55 +00:00
|
|
|
OPTION(DISABLE_TESTS "If tests should be compiled or not" OFF)
|
2020-07-29 18:53:03 +00:00
|
|
|
OPTION(ENABLE_SSL_TESTS, "Should we test SSL connections" OFF)
|
2018-09-25 23:44:58 +00:00
|
|
|
|
|
|
|
MACRO(getVersionBit name)
|
2019-01-21 19:57:11 +00:00
|
|
|
SET(VERSION_REGEX "^#define ${name} (.+)$")
|
|
|
|
FILE(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/hiredis.h"
|
|
|
|
VERSION_BIT REGEX ${VERSION_REGEX})
|
|
|
|
STRING(REGEX REPLACE ${VERSION_REGEX} "\\1" ${name} "${VERSION_BIT}")
|
2018-09-25 23:44:58 +00:00
|
|
|
ENDMACRO(getVersionBit)
|
|
|
|
|
|
|
|
getVersionBit(HIREDIS_MAJOR)
|
|
|
|
getVersionBit(HIREDIS_MINOR)
|
|
|
|
getVersionBit(HIREDIS_PATCH)
|
2019-01-22 21:39:24 +00:00
|
|
|
getVersionBit(HIREDIS_SONAME)
|
2019-01-21 19:42:58 +00:00
|
|
|
SET(VERSION "${HIREDIS_MAJOR}.${HIREDIS_MINOR}.${HIREDIS_PATCH}")
|
|
|
|
MESSAGE("Detected version: ${VERSION}")
|
2018-09-25 23:44:58 +00:00
|
|
|
|
2019-01-21 19:57:11 +00:00
|
|
|
PROJECT(hiredis VERSION "${VERSION}")
|
|
|
|
|
2020-08-28 19:35:01 +00:00
|
|
|
# Hiredis requires C99
|
|
|
|
SET(CMAKE_C_STANDARD 99)
|
2020-09-09 16:27:28 +00:00
|
|
|
SET(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
2020-09-09 17:11:05 +00:00
|
|
|
SET(CMAKE_DEBUG_POSTFIX d)
|
2020-08-28 19:35:01 +00:00
|
|
|
|
2019-01-21 19:57:11 +00:00
|
|
|
SET(ENABLE_EXAMPLES OFF CACHE BOOL "Enable building hiredis examples")
|
|
|
|
|
2020-02-28 05:29:05 +00:00
|
|
|
SET(hiredis_sources
|
2020-05-22 16:27:49 +00:00
|
|
|
alloc.c
|
2018-09-25 23:44:58 +00:00
|
|
|
async.c
|
|
|
|
dict.c
|
|
|
|
hiredis.c
|
|
|
|
net.c
|
|
|
|
read.c
|
2019-02-06 19:14:46 +00:00
|
|
|
sds.c
|
2020-05-22 16:27:49 +00:00
|
|
|
sockcompat.c)
|
2018-09-25 23:44:58 +00:00
|
|
|
|
2020-04-09 15:05:14 +00:00
|
|
|
SET(hiredis_sources ${hiredis_sources})
|
|
|
|
|
|
|
|
IF(WIN32)
|
|
|
|
ADD_COMPILE_DEFINITIONS(_CRT_SECURE_NO_WARNINGS WIN32_LEAN_AND_MEAN)
|
|
|
|
ENDIF()
|
|
|
|
|
2020-02-28 05:29:05 +00:00
|
|
|
ADD_LIBRARY(hiredis SHARED ${hiredis_sources})
|
2020-07-22 13:23:53 +00:00
|
|
|
ADD_LIBRARY(hiredis_static STATIC ${hiredis_sources})
|
2020-02-28 05:29:05 +00:00
|
|
|
|
2018-09-25 23:44:58 +00:00
|
|
|
SET_TARGET_PROPERTIES(hiredis
|
2020-04-03 05:41:34 +00:00
|
|
|
PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS TRUE
|
2019-01-22 21:39:24 +00:00
|
|
|
VERSION "${HIREDIS_SONAME}")
|
2020-09-09 17:11:05 +00:00
|
|
|
SET_TARGET_PROPERTIES(hiredis_static
|
|
|
|
PROPERTIES COMPILE_PDB_NAME hiredis_static)
|
|
|
|
SET_TARGET_PROPERTIES(hiredis_static
|
|
|
|
PROPERTIES COMPILE_PDB_NAME_DEBUG hiredis_static${CMAKE_DEBUG_POSTFIX})
|
2019-03-31 16:17:19 +00:00
|
|
|
IF(WIN32 OR MINGW)
|
2020-09-04 08:37:11 +00:00
|
|
|
TARGET_LINK_LIBRARIES(hiredis PUBLIC ws2_32 crypt32)
|
|
|
|
TARGET_LINK_LIBRARIES(hiredis_static PUBLIC ws2_32 crypt32)
|
2019-03-31 16:17:19 +00:00
|
|
|
ENDIF()
|
2020-04-09 15:05:14 +00:00
|
|
|
|
2020-07-22 13:23:53 +00:00
|
|
|
TARGET_INCLUDE_DIRECTORIES(hiredis PUBLIC $<INSTALL_INTERFACE:include> $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
|
|
|
|
TARGET_INCLUDE_DIRECTORIES(hiredis_static PUBLIC $<INSTALL_INTERFACE:include> $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
|
2019-01-21 19:42:58 +00:00
|
|
|
|
|
|
|
CONFIGURE_FILE(hiredis.pc.in hiredis.pc @ONLY)
|
2018-09-25 23:44:58 +00:00
|
|
|
|
2020-07-22 13:23:53 +00:00
|
|
|
set(CPACK_PACKAGE_VENDOR "Redis")
|
|
|
|
set(CPACK_PACKAGE_DESCRIPTION "\
|
|
|
|
Hiredis is a minimalistic C client library for the Redis database.
|
|
|
|
|
|
|
|
It is minimalistic because it just adds minimal support for the protocol, \
|
|
|
|
but at the same time it uses a high level printf-alike API in order to make \
|
|
|
|
it much higher level than otherwise suggested by its minimal code base and the \
|
|
|
|
lack of explicit bindings for every Redis command.
|
|
|
|
|
|
|
|
Apart from supporting sending commands and receiving replies, it comes with a \
|
|
|
|
reply parser that is decoupled from the I/O layer. It is a stream parser designed \
|
|
|
|
for easy reusability, which can for instance be used in higher level language bindings \
|
|
|
|
for efficient reply parsing.
|
|
|
|
|
|
|
|
Hiredis only supports the binary-safe Redis protocol, so you can use it with any Redis \
|
|
|
|
version >= 1.2.0.
|
|
|
|
|
|
|
|
The library comes with multiple APIs. There is the synchronous API, the asynchronous API \
|
|
|
|
and the reply parsing API.")
|
|
|
|
set(CPACK_PACKAGE_HOMEPAGE_URL "https://github.com/redis/hiredis")
|
|
|
|
set(CPACK_PACKAGE_CONTACT "michael dot grunder at gmail dot com")
|
|
|
|
set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
|
|
|
|
set(CPACK_RPM_PACKAGE_AUTOREQPROV ON)
|
|
|
|
|
|
|
|
include(CPack)
|
|
|
|
|
|
|
|
INSTALL(TARGETS hiredis hiredis_static
|
2020-04-09 15:05:14 +00:00
|
|
|
EXPORT hiredis-targets
|
|
|
|
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
|
|
|
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
|
|
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
2018-09-25 23:44:58 +00:00
|
|
|
|
2020-09-09 17:11:05 +00:00
|
|
|
if (MSVC)
|
|
|
|
INSTALL(FILES $<TARGET_PDB_FILE:hiredis>
|
|
|
|
DESTINATION ${CMAKE_INSTALL_BINDIR}
|
|
|
|
CONFIGURATIONS Debug RelWithDebInfo)
|
|
|
|
INSTALL(FILES $<TARGET_FILE_DIR:hiredis_static>/$<TARGET_FILE_BASE_NAME:hiredis_static>.pdb
|
|
|
|
DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
|
|
CONFIGURATIONS Debug RelWithDebInfo)
|
|
|
|
endif()
|
|
|
|
|
2020-07-22 13:23:53 +00:00
|
|
|
# For NuGet packages
|
|
|
|
INSTALL(FILES hiredis.targets
|
|
|
|
DESTINATION build/native)
|
|
|
|
|
2020-02-28 05:29:05 +00:00
|
|
|
INSTALL(FILES hiredis.h read.h sds.h async.h alloc.h
|
2018-09-25 23:44:58 +00:00
|
|
|
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/hiredis)
|
2020-07-30 23:55:48 +00:00
|
|
|
|
2019-07-17 11:05:06 +00:00
|
|
|
INSTALL(DIRECTORY adapters
|
|
|
|
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/hiredis)
|
2020-07-30 23:55:48 +00:00
|
|
|
|
2019-01-21 19:42:58 +00:00
|
|
|
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/hiredis.pc
|
|
|
|
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
|
|
|
|
|
2020-04-09 15:05:14 +00:00
|
|
|
export(EXPORT hiredis-targets
|
|
|
|
FILE "${CMAKE_CURRENT_BINARY_DIR}/hiredis-targets.cmake"
|
|
|
|
NAMESPACE hiredis::)
|
|
|
|
|
|
|
|
SET(CMAKE_CONF_INSTALL_DIR share/hiredis)
|
|
|
|
SET(INCLUDE_INSTALL_DIR include)
|
|
|
|
include(CMakePackageConfigHelpers)
|
|
|
|
configure_package_config_file(hiredis-config.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/hiredis-config.cmake
|
|
|
|
INSTALL_DESTINATION ${CMAKE_CONF_INSTALL_DIR}
|
|
|
|
PATH_VARS INCLUDE_INSTALL_DIR)
|
|
|
|
|
|
|
|
INSTALL(EXPORT hiredis-targets
|
|
|
|
FILE hiredis-targets.cmake
|
|
|
|
NAMESPACE hiredis::
|
|
|
|
DESTINATION ${CMAKE_CONF_INSTALL_DIR})
|
|
|
|
|
|
|
|
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/hiredis-config.cmake
|
|
|
|
DESTINATION ${CMAKE_CONF_INSTALL_DIR})
|
|
|
|
|
|
|
|
|
2019-09-01 10:47:25 +00:00
|
|
|
IF(ENABLE_SSL)
|
2019-02-06 19:14:46 +00:00
|
|
|
IF (NOT OPENSSL_ROOT_DIR)
|
|
|
|
IF (APPLE)
|
|
|
|
SET(OPENSSL_ROOT_DIR "/usr/local/opt/openssl")
|
|
|
|
ENDIF()
|
|
|
|
ENDIF()
|
|
|
|
FIND_PACKAGE(OpenSSL REQUIRED)
|
2020-07-30 23:55:48 +00:00
|
|
|
SET(hiredis_ssl_sources
|
2019-09-01 10:47:25 +00:00
|
|
|
ssl.c)
|
2020-04-09 15:05:14 +00:00
|
|
|
ADD_LIBRARY(hiredis_ssl SHARED
|
|
|
|
${hiredis_ssl_sources})
|
2020-07-22 13:23:53 +00:00
|
|
|
ADD_LIBRARY(hiredis_ssl_static STATIC
|
|
|
|
${hiredis_ssl_sources})
|
2020-04-13 16:32:32 +00:00
|
|
|
|
|
|
|
IF (APPLE)
|
|
|
|
SET_PROPERTY(TARGET hiredis_ssl PROPERTY LINK_FLAGS "-Wl,-undefined -Wl,dynamic_lookup")
|
|
|
|
ENDIF()
|
|
|
|
|
2020-04-07 18:19:00 +00:00
|
|
|
SET_TARGET_PROPERTIES(hiredis_ssl
|
2020-04-13 16:32:32 +00:00
|
|
|
PROPERTIES
|
|
|
|
WINDOWS_EXPORT_ALL_SYMBOLS TRUE
|
2020-04-07 18:19:00 +00:00
|
|
|
VERSION "${HIREDIS_SONAME}")
|
2020-09-09 17:11:05 +00:00
|
|
|
SET_TARGET_PROPERTIES(hiredis_ssl_static
|
|
|
|
PROPERTIES COMPILE_PDB_NAME hiredis_ssl_static)
|
|
|
|
SET_TARGET_PROPERTIES(hiredis_ssl_static
|
|
|
|
PROPERTIES COMPILE_PDB_NAME_DEBUG hiredis_ssl_static${CMAKE_DEBUG_POSTFIX})
|
2020-04-09 15:05:14 +00:00
|
|
|
|
2019-09-01 10:47:25 +00:00
|
|
|
TARGET_INCLUDE_DIRECTORIES(hiredis_ssl PRIVATE "${OPENSSL_INCLUDE_DIR}")
|
2020-07-22 13:23:53 +00:00
|
|
|
TARGET_INCLUDE_DIRECTORIES(hiredis_ssl_static PRIVATE "${OPENSSL_INCLUDE_DIR}")
|
2020-09-08 00:47:50 +00:00
|
|
|
|
2019-09-01 10:47:25 +00:00
|
|
|
TARGET_LINK_LIBRARIES(hiredis_ssl PRIVATE ${OPENSSL_LIBRARIES})
|
2020-04-09 15:05:14 +00:00
|
|
|
IF (WIN32 OR MINGW)
|
|
|
|
TARGET_LINK_LIBRARIES(hiredis_ssl PRIVATE hiredis)
|
2020-09-04 08:37:11 +00:00
|
|
|
TARGET_LINK_LIBRARIES(hiredis_ssl_static PUBLIC hiredis_static)
|
2020-04-09 15:05:14 +00:00
|
|
|
ENDIF()
|
2019-09-01 10:47:25 +00:00
|
|
|
CONFIGURE_FILE(hiredis_ssl.pc.in hiredis_ssl.pc @ONLY)
|
|
|
|
|
2020-07-22 13:23:53 +00:00
|
|
|
INSTALL(TARGETS hiredis_ssl hiredis_ssl_static
|
2020-04-09 15:05:14 +00:00
|
|
|
EXPORT hiredis_ssl-targets
|
|
|
|
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
|
|
|
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
|
|
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
2019-09-01 10:47:25 +00:00
|
|
|
|
2020-09-09 17:11:05 +00:00
|
|
|
if (MSVC)
|
|
|
|
INSTALL(FILES $<TARGET_PDB_FILE:hiredis_ssl>
|
|
|
|
DESTINATION ${CMAKE_INSTALL_BINDIR}
|
|
|
|
CONFIGURATIONS Debug RelWithDebInfo)
|
|
|
|
INSTALL(FILES $<TARGET_FILE_DIR:hiredis_ssl_static>/$<TARGET_FILE_BASE_NAME:hiredis_ssl_static>.pdb
|
|
|
|
DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
|
|
CONFIGURATIONS Debug RelWithDebInfo)
|
|
|
|
endif()
|
|
|
|
|
2019-09-01 10:47:25 +00:00
|
|
|
INSTALL(FILES hiredis_ssl.h
|
|
|
|
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/hiredis)
|
2020-07-30 23:55:48 +00:00
|
|
|
|
2019-09-01 10:47:25 +00:00
|
|
|
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/hiredis_ssl.pc
|
|
|
|
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
|
2020-04-09 15:05:14 +00:00
|
|
|
|
|
|
|
export(EXPORT hiredis_ssl-targets
|
|
|
|
FILE "${CMAKE_CURRENT_BINARY_DIR}/hiredis_ssl-targets.cmake"
|
|
|
|
NAMESPACE hiredis::)
|
|
|
|
|
|
|
|
SET(CMAKE_CONF_INSTALL_DIR share/hiredis_ssl)
|
|
|
|
configure_package_config_file(hiredis_ssl-config.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/hiredis_ssl-config.cmake
|
|
|
|
INSTALL_DESTINATION ${CMAKE_CONF_INSTALL_DIR}
|
|
|
|
PATH_VARS INCLUDE_INSTALL_DIR)
|
|
|
|
|
|
|
|
INSTALL(EXPORT hiredis_ssl-targets
|
|
|
|
FILE hiredis_ssl-targets.cmake
|
|
|
|
NAMESPACE hiredis::
|
|
|
|
DESTINATION ${CMAKE_CONF_INSTALL_DIR})
|
|
|
|
|
|
|
|
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/hiredis_ssl-config.cmake
|
|
|
|
DESTINATION ${CMAKE_CONF_INSTALL_DIR})
|
2019-02-06 19:14:46 +00:00
|
|
|
ENDIF()
|
|
|
|
|
2020-04-03 05:41:34 +00:00
|
|
|
IF(NOT DISABLE_TESTS)
|
2019-03-31 16:17:19 +00:00
|
|
|
ENABLE_TESTING()
|
|
|
|
ADD_EXECUTABLE(hiredis-test test.c)
|
2020-07-29 18:53:03 +00:00
|
|
|
IF(ENABLE_SSL_TESTS)
|
|
|
|
ADD_DEFINITIONS(-DHIREDIS_TEST_SSL=1)
|
|
|
|
TARGET_LINK_LIBRARIES(hiredis-test hiredis hiredis_ssl)
|
|
|
|
ELSE()
|
|
|
|
TARGET_LINK_LIBRARIES(hiredis-test hiredis)
|
|
|
|
ENDIF()
|
2019-03-31 16:17:19 +00:00
|
|
|
ADD_TEST(NAME hiredis-test
|
|
|
|
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/test.sh)
|
|
|
|
ENDIF()
|
2018-09-25 23:44:58 +00:00
|
|
|
|
|
|
|
# Add examples
|
2019-01-21 21:05:04 +00:00
|
|
|
IF(ENABLE_EXAMPLES)
|
|
|
|
ADD_SUBDIRECTORY(examples)
|
|
|
|
ENDIF(ENABLE_EXAMPLES)
|