[hiredis] Fix feature ssl build error on windows (#12354)

* [hiredis] Fix feature ssl build error on windows

* Fix feature example build error on windows
This commit is contained in:
NancyLi1013 2020-07-16 06:55:31 +08:00 committed by GitHub
parent 85a5acfd3c
commit fc761ebb72
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 128 additions and 79 deletions

View File

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

View File

@ -1,76 +1,107 @@
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
index dd3a313..0df75d5 100644 index dd3a313..8c69d3a 100644
--- a/examples/CMakeLists.txt --- a/examples/CMakeLists.txt
+++ b/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt
@@ -19,10 +19,17 @@ if (LIBEV) @@ -19,16 +19,30 @@ if (LIBEV)
TARGET_LINK_LIBRARIES(example-libev hiredis ev) TARGET_LINK_LIBRARIES(example-libev hiredis ev)
ENDIF() ENDIF()
-FIND_PATH(LIBEVENT event.h) -FIND_PATH(LIBEVENT event.h)
-if (LIBEVENT) -if (LIBEVENT)
+FIND_PACKAGE(Libevent CONFIG REQUIRED) +FIND_PACKAGE(Libevent CONFIG REQUIRED)
+FIND_PATH(LIBEVENT_INCLUDES evutil.h) +FIND_PATH(LIBEVENT_INCLUDES evutil.h)
+if (BUILD_SHARED_LIBS) +if (BUILD_SHARED_LIBS)
+ set(LIBEVENT_LIBS ${LIBEVENT_SHARED_LIBRARIES}) + set(LIBEVENT_LIBS ${LIBEVENT_SHARED_LIBRARIES})
+else() +else()
+ set(LIBEVENT_LIBS ${LIBEVENT_STATIC_LIBRARIES}) + set(LIBEVENT_LIBS ${LIBEVENT_STATIC_LIBRARIES})
+endif() +endif()
+if (UNIX) +if (UNIX)
ADD_EXECUTABLE(example-libevent example-libevent) ADD_EXECUTABLE(example-libevent example-libevent)
- TARGET_LINK_LIBRARIES(example-libevent hiredis event) - TARGET_LINK_LIBRARIES(example-libevent hiredis event)
+ TARGET_LINK_LIBRARIES(example-libevent hiredis ${LIBEVENT_LIBS}) + TARGET_LINK_LIBRARIES(example-libevent hiredis ${LIBEVENT_LIBS})
+ TARGET_INCLUDE_DIRECTORIES(example-libevent PRIVATE ${LIBEVENT_INCLUDES}) + TARGET_INCLUDE_DIRECTORIES(example-libevent PRIVATE ${LIBEVENT_INCLUDES})
ENDIF() ENDIF()
FIND_PATH(LIBUV uv.h) +FIND_LIBRARY(UV_LIBRARY libuv)
@@ -38,9 +45,17 @@ IF (APPLE) FIND_PATH(LIBUV uv.h)
ENDIF() IF (LIBUV)
ADD_EXECUTABLE(example-libuv example-libuv.c)
IF (ENABLE_SSL) - TARGET_LINK_LIBRARIES(example-libuv hiredis uv)
+ FIND_PACKAGE(OpenSSL REQUIRED) + if(WIN32)
+ IF (WIN32) + set(LIB_LISTS Iphlpapi.lib Psapi.lib Userenv.lib)
+ FIND_PACKAGE(pthreads REQUIRED) + else()
+ SET(THREADS_LIBS PThreads4W::PThreads4W) + set(LIB_LISTS)
+ ELSE() + endif()
+ FIND_PACKAGE(Threads) + TARGET_LINK_LIBRARIES(example-libuv hiredis ${UV_LIBRARY} ${LIB_LISTS})
+ SET(THREADS_LIBS ${CMAKE_THREAD_LIBS_INIT}) + TARGET_INCLUDE_DIRECTORIES(example-libuv PRIVATE ${LIBUV})
+ ENDIF() ENDIF()
ADD_EXECUTABLE(example-ssl example-ssl.c)
- TARGET_LINK_LIBRARIES(example-ssl hiredis hiredis_ssl) IF (APPLE)
+ TARGET_LINK_LIBRARIES(example-ssl hiredis hiredis_ssl OpenSSL::SSL OpenSSL::Crypto ${THREADS_LIBS}) @@ -38,9 +52,21 @@ IF (APPLE)
ENDIF() ENDIF()
ADD_EXECUTABLE(example example.c) IF (ENABLE_SSL)
-TARGET_LINK_LIBRARIES(example hiredis) + FIND_PACKAGE(OpenSSL REQUIRED)
+TARGET_LINK_LIBRARIES(example hiredis ${LIBEVENT_LIBS}) + IF (WIN32)
\ No newline at end of file + FIND_PACKAGE(pthreads REQUIRED)
diff --git a/examples/example-ssl.c b/examples/example-ssl.c + SET(THREADS_LIBS PThreads4W::PThreads4W)
index 81f4648..9f42923 100644 + ELSE()
--- a/examples/example-ssl.c + FIND_PACKAGE(Threads)
+++ b/examples/example-ssl.c + SET(THREADS_LIBS ${CMAKE_THREAD_LIBS_INIT})
@@ -1,6 +1,10 @@ + ENDIF()
#include <stdio.h> ADD_EXECUTABLE(example-ssl example-ssl.c)
#include <stdlib.h> - TARGET_LINK_LIBRARIES(example-ssl hiredis hiredis_ssl)
#include <string.h> + if(WIN32)
+#ifdef _WIN32 + TARGET_LINK_LIBRARIES(example-ssl hiredis hiredis_ssl OpenSSL::SSL OpenSSL::Crypto ${THREADS_LIBS} crypt32.lib)
+#include <Winsock2.h> + else()
+#include <Windows.h> + TARGET_LINK_LIBRARIES(example-ssl hiredis hiredis_ssl OpenSSL::SSL OpenSSL::Crypto ${THREADS_LIBS})
+#endif + endif()
ENDIF()
#include <hiredis.h>
#include <hiredis_ssl.h> ADD_EXECUTABLE(example example.c)
diff --git a/examples/example.c b/examples/example.c -TARGET_LINK_LIBRARIES(example hiredis)
index 0e93fc8..339e322 100644 +TARGET_LINK_LIBRARIES(example hiredis ${LIBEVENT_LIBS})
--- a/examples/example.c diff --git a/examples/example-libuv.c b/examples/example-libuv.c
+++ b/examples/example.c index a5462d4..9b7ca3e 100644
@@ -1,6 +1,10 @@ --- a/examples/example-libuv.c
#include <stdio.h> +++ b/examples/example-libuv.c
#include <stdlib.h> @@ -33,7 +33,9 @@ void disconnectCallback(const redisAsyncContext *c, int status) {
#include <string.h> }
+#ifdef _WIN32
+#include <Winsock2.h> int main (int argc, char **argv) {
+#include <Windows.h> +#ifndef _WIN32
+#endif signal(SIGPIPE, SIG_IGN);
+#endif
#include <hiredis.h> uv_loop_t* loop = uv_default_loop();
redisAsyncContext *c = redisAsyncConnect("127.0.0.1", 6379);
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

@ -0,0 +1,16 @@
diff --git a/ssl.c b/ssl.c
index 78ab9e4..768f304 100644
--- a/ssl.c
+++ b/ssl.c
@@ -34,7 +34,11 @@
#include "async.h"
#include <assert.h>
+#ifdef _WIN32
+#include <windows.h>
+#else
#include <pthread.h>
+#endif
#include <errno.h>
#include <string.h>

View File

@ -12,6 +12,7 @@ vcpkg_from_github(
fix-feature-example.patch fix-feature-example.patch
support-static-in-win.patch support-static-in-win.patch
fix-timeval.patch fix-timeval.patch
fix-pthread.h-not-found-on-windows.patch
) )
vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS
@ -32,4 +33,4 @@ vcpkg_copy_pdbs()
file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/include) file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/include)
# Handle copyright # Handle copyright
file(INSTALL ${SOURCE_PATH}/COPYING DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT} RENAME copyright) file(INSTALL ${SOURCE_PATH}/COPYING DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT} RENAME copyright)