Update CMakelists for hiredis/hiredis_ssl builds.

Also rename the SSL option from `HIREDIS_SSL` to `ENABLE_SSL` to conform
with CMake convnetions.
This commit is contained in:
Yossi Gottlieb 2019-09-01 13:47:25 +03:00
parent 5872d818d9
commit dd408e8e3f
3 changed files with 32 additions and 10 deletions

View File

@ -2,7 +2,7 @@ CMAKE_MINIMUM_REQUIRED(VERSION 3.4.0)
INCLUDE(GNUInstallDirs) INCLUDE(GNUInstallDirs)
PROJECT(hiredis) PROJECT(hiredis)
OPTION(HIREDIS_SSL "Link against OpenSSL" OFF) OPTION(ENABLE_SSL "Build hiredis_ssl for SSL support" OFF)
MACRO(getVersionBit name) MACRO(getVersionBit name)
SET(VERSION_REGEX "^#define ${name} (.+)$") SET(VERSION_REGEX "^#define ${name} (.+)$")
@ -29,8 +29,7 @@ ADD_LIBRARY(hiredis SHARED
net.c net.c
read.c read.c
sds.c sds.c
sockcompat.c sockcompat.c)
ssl.c)
SET_TARGET_PROPERTIES(hiredis SET_TARGET_PROPERTIES(hiredis
PROPERTIES PROPERTIES
@ -54,16 +53,27 @@ INSTALL(DIRECTORY adapters
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/hiredis.pc INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/hiredis.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
IF(HIREDIS_SSL) IF(ENABLE_SSL)
IF (NOT OPENSSL_ROOT_DIR) IF (NOT OPENSSL_ROOT_DIR)
IF (APPLE) IF (APPLE)
SET(OPENSSL_ROOT_DIR "/usr/local/opt/openssl") SET(OPENSSL_ROOT_DIR "/usr/local/opt/openssl")
ENDIF() ENDIF()
ENDIF() ENDIF()
FIND_PACKAGE(OpenSSL REQUIRED) FIND_PACKAGE(OpenSSL REQUIRED)
TARGET_COMPILE_DEFINITIONS(hiredis PRIVATE HIREDIS_SSL) ADD_LIBRARY(hiredis_ssl SHARED
TARGET_INCLUDE_DIRECTORIES(hiredis PRIVATE "${OPENSSL_INCLUDE_DIR}") ssl.c)
TARGET_LINK_LIBRARIES(hiredis PRIVATE ${OPENSSL_LIBRARIES}) 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)
ENDIF() ENDIF()
IF(NOT (WIN32 OR MINGW)) IF(NOT (WIN32 OR MINGW))

View File

@ -37,10 +37,10 @@ IF (APPLE)
TARGET_LINK_LIBRARIES(example-macosx hiredis ${CF}) TARGET_LINK_LIBRARIES(example-macosx hiredis ${CF})
ENDIF() ENDIF()
IF (HIREDIS_SSL) IF (ENABLE_SSL)
ADD_EXECUTABLE(example-ssl example-ssl.c) ADD_EXECUTABLE(example-ssl example-ssl.c)
TARGET_LINK_LIBRARIES(example-ssl hiredis) TARGET_LINK_LIBRARIES(example-ssl hiredis hiredis_ssl)
ENDIF() ENDIF()
ADD_EXECUTABLE(example example.c) ADD_EXECUTABLE(example example.c)
TARGET_LINK_LIBRARIES(example hiredis) TARGET_LINK_LIBRARIES(example hiredis)

12
hiredis_ssl.pc.in Normal file
View File

@ -0,0 +1,12 @@
prefix=@CMAKE_INSTALL_PREFIX@
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${prefix}/include
pkgincludedir=${includedir}/hiredis
Name: hiredis_ssl
Description: SSL Support for hiredis.
Version: @PROJECT_VERSION@
Requires: hiredis
Libs: -L${libdir} -lhiredis_ssl
Libs.private: -lssl -lcrypto