From c19fb8956bd2e9fa0f7d0b8574d84f4bdcbbc457 Mon Sep 17 00:00:00 2001 From: Mike Sardonini Date: Sun, 11 Sep 2022 16:57:19 -0700 Subject: [PATCH 1/3] The static version of redis++ now links to the static version of hiredis --- CMakeLists.txt | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 58eba29a..e96cccee 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -127,6 +127,8 @@ if(hiredis_FOUND) if(REDIS_PLUS_PLUS_USE_TLS) find_package(hiredis_ssl REQUIRED) list(APPEND REDIS_PLUS_PLUS_HIREDIS_LIBS hiredis::hiredis_ssl) + find_package(OpenSSL REQUIRED) + list(APPEND REDIS_PLUS_PLUS_HIREDIS_LIBS ${OPENSSL_LIBRARIES}) endif() else() find_path(HIREDIS_HEADER hiredis) @@ -136,6 +138,8 @@ else() if(REDIS_PLUS_PLUS_USE_TLS) find_library(HIREDIS_TLS_LIB hiredis_ssl) list(APPEND REDIS_PLUS_PLUS_HIREDIS_LIBS ${HIREDIS_TLS_LIB}) + find_package(OpenSSL REQUIRED) + list(APPEND REDIS_PLUS_PLUS_HIREDIS_LIBS ${OPENSSL_LIBRARIES}) endif() endif() @@ -146,6 +150,15 @@ message(STATUS "redis-plus-plus build static library: ${REDIS_PLUS_PLUS_BUILD_ST if(REDIS_PLUS_PLUS_BUILD_STATIC) set(STATIC_LIB redis++_static) + # For the static build, link to the static version of hiredis + set(REDIS_PLUS_PLUS_HIREDIS_LIBS_STATIC ${REDIS_PLUS_PLUS_HIREDIS_LIBS}) + string(REPLACE "hiredis::hiredis" "hiredis::hiredis_static" REDIS_PLUS_PLUS_HIREDIS_LIBS_STATIC + "${REDIS_PLUS_PLUS_HIREDIS_LIBS_STATIC}") + + # If SSL is not enabled, this line will have no effect + string(REPLACE "hiredis::hiredis_ssl" "hiredis::hiredis_ssl_static" REDIS_PLUS_PLUS_HIREDIS_LIBS_STATIC + "${REDIS_PLUS_PLUS_HIREDIS_LIBS_STATIC}") + add_library(${STATIC_LIB} STATIC ${REDIS_PLUS_PLUS_SOURCES}) add_library(redis++::${STATIC_LIB} ALIAS ${STATIC_LIB}) @@ -159,7 +172,7 @@ if(REDIS_PLUS_PLUS_BUILD_STATIC) if(hiredis_FOUND) target_include_directories(${STATIC_LIB} PUBLIC $) - target_link_libraries(${STATIC_LIB} PUBLIC ${REDIS_PLUS_PLUS_HIREDIS_LIBS}) + target_link_libraries(${STATIC_LIB} PUBLIC ${REDIS_PLUS_PLUS_HIREDIS_LIBS_STATIC}) else() target_include_directories(${STATIC_LIB} PUBLIC $) endif() @@ -201,7 +214,7 @@ if(REDIS_PLUS_PLUS_BUILD_SHARED) add_library(${SHARED_LIB} SHARED ${REDIS_PLUS_PLUS_SOURCES}) add_library(redis++::${SHARED_LIB} ALIAS ${SHARED_LIB}) - + list(APPEND REDIS_PLUS_PLUS_TARGETS ${SHARED_LIB}) target_include_directories(${SHARED_LIB} PUBLIC From ba04dab2eb3fab70d15550c1e24a52c7a09c6387 Mon Sep 17 00:00:00 2001 From: Mike Sardonini Date: Sun, 11 Sep 2022 17:01:03 -0700 Subject: [PATCH 2/3] removed whitespace that was unintentionally added --- CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e96cccee..f6856ac1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -214,7 +214,6 @@ if(REDIS_PLUS_PLUS_BUILD_SHARED) add_library(${SHARED_LIB} SHARED ${REDIS_PLUS_PLUS_SOURCES}) add_library(redis++::${SHARED_LIB} ALIAS ${SHARED_LIB}) - list(APPEND REDIS_PLUS_PLUS_TARGETS ${SHARED_LIB}) target_include_directories(${SHARED_LIB} PUBLIC From 257ce2e8c62d7ad9ed010d8c712501ecab5c92e5 Mon Sep 17 00:00:00 2001 From: Mike Sardonini Date: Tue, 13 Sep 2022 21:35:22 -0700 Subject: [PATCH 3/3] added checks that hiredis targets exist before trying to link to to them. If the checks fail, default behavior is used --- CMakeLists.txt | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f6856ac1..6d564467 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -152,12 +152,17 @@ if(REDIS_PLUS_PLUS_BUILD_STATIC) # For the static build, link to the static version of hiredis set(REDIS_PLUS_PLUS_HIREDIS_LIBS_STATIC ${REDIS_PLUS_PLUS_HIREDIS_LIBS}) - string(REPLACE "hiredis::hiredis" "hiredis::hiredis_static" REDIS_PLUS_PLUS_HIREDIS_LIBS_STATIC - "${REDIS_PLUS_PLUS_HIREDIS_LIBS_STATIC}") - # If SSL is not enabled, this line will have no effect - string(REPLACE "hiredis::hiredis_ssl" "hiredis::hiredis_ssl_static" REDIS_PLUS_PLUS_HIREDIS_LIBS_STATIC - "${REDIS_PLUS_PLUS_HIREDIS_LIBS_STATIC}") + if (TARGET hiredis::hiredis_static) + string(REPLACE "hiredis::hiredis" "hiredis::hiredis_static" REDIS_PLUS_PLUS_HIREDIS_LIBS_STATIC + "${REDIS_PLUS_PLUS_HIREDIS_LIBS_STATIC}") + endif() + + if (TARGET hiredis::hiredis_ssl_static) + # If SSL is not enabled, this line will have no effect + string(REPLACE "hiredis::hiredis_ssl" "hiredis::hiredis_ssl_static" REDIS_PLUS_PLUS_HIREDIS_LIBS_STATIC + "${REDIS_PLUS_PLUS_HIREDIS_LIBS_STATIC}") + endif() add_library(${STATIC_LIB} STATIC ${REDIS_PLUS_PLUS_SOURCES}) add_library(redis++::${STATIC_LIB} ALIAS ${STATIC_LIB})