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)
|
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}")
|
|
|
|
|
|
|
|
SET(ENABLE_EXAMPLES OFF CACHE BOOL "Enable building hiredis examples")
|
|
|
|
|
2018-09-25 23:44:58 +00:00
|
|
|
ADD_LIBRARY(hiredis SHARED
|
|
|
|
async.c
|
|
|
|
dict.c
|
|
|
|
hiredis.c
|
|
|
|
net.c
|
|
|
|
read.c
|
2019-02-06 19:14:46 +00:00
|
|
|
sds.c
|
2019-09-01 10:47:25 +00:00
|
|
|
sockcompat.c)
|
2018-09-25 23:44:58 +00:00
|
|
|
|
|
|
|
SET_TARGET_PROPERTIES(hiredis
|
|
|
|
PROPERTIES
|
2019-01-22 21:39:24 +00:00
|
|
|
VERSION "${HIREDIS_SONAME}")
|
2019-03-31 16:17:19 +00:00
|
|
|
IF(WIN32 OR MINGW)
|
|
|
|
TARGET_LINK_LIBRARIES(hiredis PRIVATE ws2_32)
|
|
|
|
ENDIF()
|
2019-03-31 17:15:11 +00:00
|
|
|
TARGET_INCLUDE_DIRECTORIES(hiredis PUBLIC .)
|
2019-01-21 19:42:58 +00:00
|
|
|
|
|
|
|
CONFIGURE_FILE(hiredis.pc.in hiredis.pc @ONLY)
|
2018-09-25 23:44:58 +00:00
|
|
|
|
|
|
|
INSTALL(TARGETS hiredis
|
|
|
|
DESTINATION "${CMAKE_INSTALL_LIBDIR}")
|
|
|
|
|
2019-01-21 19:41:58 +00:00
|
|
|
INSTALL(FILES hiredis.h read.h sds.h async.h
|
2018-09-25 23:44:58 +00:00
|
|
|
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/hiredis)
|
2019-07-17 11:05:06 +00:00
|
|
|
|
|
|
|
INSTALL(DIRECTORY adapters
|
|
|
|
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/hiredis)
|
|
|
|
|
2019-01-21 19:42:58 +00:00
|
|
|
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/hiredis.pc
|
|
|
|
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
|
|
|
|
|
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)
|
2019-09-01 10:47:25 +00:00
|
|
|
ADD_LIBRARY(hiredis_ssl SHARED
|
|
|
|
ssl.c)
|
|
|
|
TARGET_INCLUDE_DIRECTORIES(hiredis_ssl PRIVATE "${OPENSSL_INCLUDE_DIR}")
|
|
|
|
TARGET_LINK_LIBRARIES(hiredis_ssl PRIVATE ${OPENSSL_LIBRARIES})
|
|
|
|
CONFIGURE_FILE(hiredis_ssl.pc.in hiredis_ssl.pc @ONLY)
|
|
|
|
|
|
|
|
INSTALL(TARGETS hiredis_ssl
|
|
|
|
DESTINATION "${CMAKE_INSTALL_LIBDIR}")
|
|
|
|
|
|
|
|
INSTALL(FILES hiredis_ssl.h
|
|
|
|
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/hiredis)
|
|
|
|
|
|
|
|
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/hiredis_ssl.pc
|
|
|
|
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
|
2019-02-06 19:14:46 +00:00
|
|
|
ENDIF()
|
|
|
|
|
2019-11-04 06:00:55 +00:00
|
|
|
IF(NOT (DISABLE_TESTS OR (WIN32 OR MINGW)))
|
2019-03-31 16:17:19 +00:00
|
|
|
ENABLE_TESTING()
|
|
|
|
ADD_EXECUTABLE(hiredis-test test.c)
|
|
|
|
TARGET_LINK_LIBRARIES(hiredis-test hiredis)
|
|
|
|
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)
|