[hiredis] Support building static (#9388)

* [hiredis] Support building static

* update baseline

* update baseline
This commit is contained in:
Jack·Boos·Yu 2019-12-24 04:18:50 +08:00 committed by Robert Schumacher
parent c0d22c88ea
commit f3c11016ef
5 changed files with 111 additions and 7 deletions

View File

@ -1,5 +1,5 @@
Source: hiredis
Version: 2019-11-1
Version: 2019-11-2
Homepage: https://github.com/redis/hiredis
Description: Hiredis is a minimalistic C client library for the Redis database.
@ -8,4 +8,5 @@ Description: Build hiredis_ssl for SSL support
Build-Depends: openssl
Feature: example
Description: Build example
Description: Build example
Build-Depends: libevent, pthread

View File

@ -0,0 +1,76 @@
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
index dd3a313..0df75d5 100644
--- a/examples/CMakeLists.txt
+++ b/examples/CMakeLists.txt
@@ -19,10 +19,17 @@ if (LIBEV)
TARGET_LINK_LIBRARIES(example-libev hiredis ev)
ENDIF()
-FIND_PATH(LIBEVENT event.h)
-if (LIBEVENT)
+FIND_PACKAGE(Libevent CONFIG REQUIRED)
+FIND_PATH(LIBEVENT_INCLUDES evutil.h)
+if (BUILD_SHARED_LIBS)
+ set(LIBEVENT_LIBS ${LIBEVENT_SHARED_LIBRARIES})
+else()
+ set(LIBEVENT_LIBS ${LIBEVENT_STATIC_LIBRARIES})
+endif()
+if (UNIX)
ADD_EXECUTABLE(example-libevent example-libevent)
- TARGET_LINK_LIBRARIES(example-libevent hiredis event)
+ TARGET_LINK_LIBRARIES(example-libevent hiredis ${LIBEVENT_LIBS})
+ TARGET_INCLUDE_DIRECTORIES(example-libevent PRIVATE ${LIBEVENT_INCLUDES})
ENDIF()
FIND_PATH(LIBUV uv.h)
@@ -38,9 +45,17 @@ IF (APPLE)
ENDIF()
IF (ENABLE_SSL)
+ FIND_PACKAGE(OpenSSL REQUIRED)
+ IF (WIN32)
+ FIND_PACKAGE(pthreads REQUIRED)
+ SET(THREADS_LIBS PThreads4W::PThreads4W)
+ ELSE()
+ FIND_PACKAGE(Threads)
+ SET(THREADS_LIBS ${CMAKE_THREAD_LIBS_INIT})
+ ENDIF()
ADD_EXECUTABLE(example-ssl example-ssl.c)
- TARGET_LINK_LIBRARIES(example-ssl hiredis hiredis_ssl)
+ TARGET_LINK_LIBRARIES(example-ssl hiredis hiredis_ssl OpenSSL::SSL OpenSSL::Crypto ${THREADS_LIBS})
ENDIF()
ADD_EXECUTABLE(example example.c)
-TARGET_LINK_LIBRARIES(example hiredis)
+TARGET_LINK_LIBRARIES(example hiredis ${LIBEVENT_LIBS})
\ No newline at end of file
diff --git a/examples/example-ssl.c b/examples/example-ssl.c
index 81f4648..9f42923 100644
--- a/examples/example-ssl.c
+++ b/examples/example-ssl.c
@@ -1,6 +1,10 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#ifdef _WIN32
+#include <Winsock2.h>
+#include <Windows.h>
+#endif
#include <hiredis.h>
#include <hiredis_ssl.h>
diff --git a/examples/example.c b/examples/example.c
index 0e93fc8..339e322 100644
--- a/examples/example.c
+++ b/examples/example.c
@@ -1,6 +1,10 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#ifdef _WIN32
+#include <Winsock2.h>
+#include <Windows.h>
+#endif
#include <hiredis.h>

View File

@ -1,4 +1,6 @@
vcpkg_fail_port_install(ON_TARGET "Windows")
if (VCPKG_TARGET_IS_WINDOWS)
vcpkg_check_linkage(ONLY_STATIC_LIBRARY)
endif()
vcpkg_from_github(
OUT_SOURCE_PATH SOURCE_PATH
@ -6,6 +8,9 @@ vcpkg_from_github(
REF e777b0295eeeda89ee2ecef6ec5cb54889033d94
SHA512 9486ce3e40580ca6a1da8a31c3e139eb8b5e17ac1b94bd0987f2435aeb2465ad271784d5e8e83dc6cbaf362f95c9e175efa5fbe80a63c56070ceb212d3d68470
HEAD_REF master
PATCHES
fix-feature-example.patch
support-static-in-win.patch
)
vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS

View File

@ -0,0 +1,22 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9e78894..87aba5b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -22,7 +22,7 @@ PROJECT(hiredis VERSION "${VERSION}")
SET(ENABLE_EXAMPLES OFF CACHE BOOL "Enable building hiredis examples")
-ADD_LIBRARY(hiredis SHARED
+ADD_LIBRARY(hiredis
async.c
dict.c
hiredis.c
@@ -60,7 +60,7 @@ IF(ENABLE_SSL)
ENDIF()
ENDIF()
FIND_PACKAGE(OpenSSL REQUIRED)
- ADD_LIBRARY(hiredis_ssl SHARED
+ ADD_LIBRARY(hiredis_ssl
ssl.c)
TARGET_INCLUDE_DIRECTORIES(hiredis_ssl PRIVATE "${OPENSSL_INCLUDE_DIR}")
TARGET_LINK_LIBRARIES(hiredis_ssl PRIVATE ${OPENSSL_LIBRARIES})

View File

@ -579,12 +579,8 @@ hidapi:x64-linux=fail
hidapi:x64-osx=fail
hidapi:x64-uwp=fail
highfive:x64-osx=fail
hiredis:arm64-windows=fail
hiredis:arm-uwp=fail
hiredis:x64-uwp=fail
hiredis:x64-windows=fail
hiredis:x64-windows-static=fail
hiredis:x86-windows=fail
hpx:x64-windows-static=fail
hunspell:x64-linux=fail
hunspell:x64-osx=fail
@ -1449,6 +1445,10 @@ realsense2:arm-uwp=fail
realsense2:x64-linux=fail
realsense2:x64-osx=fail
realsense2:x64-uwp=fail
redis-plus-plus:x86-windows=fail
redis-plus-plus:x64-windows=fail
redis-plus-plus:x64-windows-static=fail
redis-plus-plus:arm64-windows=fail
reproc:arm-uwp=fail
reproc:x64-uwp=fail
restbed:arm-uwp=fail