浏览代码

Add option to compile against winsock

And replace the old PLATFORM flag to match
Bart van Strien 6 年之前
父节点
当前提交
ae41c468ba
共有 3 个文件被更改,包括 14 次插入6 次删除
  1. 6 0
      src/CMakeLists.txt
  2. 7 6
      src/common/PlaintextConnection.cpp
  3. 1 0
      src/common/config.h.in

+ 6 - 0
src/CMakeLists.txt

@@ -46,16 +46,22 @@ if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
 	option (USE_OPENSSL_BACKEND "Use the openssl backend" ON)
 	option (USE_SCHANNEL_BACKEND "Use the schannel backend (windows-only)" OFF)
 	option (USE_NSURL_BACKEND "Use the NSUrl backend (macos-only)" OFF)
+
+	option (USE_WINSOCK "Use winsock instead of BSD sockets (windows-only)" OFF)
 elseif (${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
 	option (USE_CURL_BACKEND "Use the libcurl backend" OFF)
 	option (USE_OPENSSL_BACKEND "Use the openssl backend" OFF)
 	option (USE_SCHANNEL_BACKEND "Use the schannel backend (windows-only)" ON)
 	option (USE_NSURL_BACKEND "Use the NSUrl backend (macos-only)" OFF)
+
+	option (USE_WINSOCK "Use winsock instead of BSD sockets (windows-only)" ON)
 elseif (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
 	option (USE_CURL_BACKEND "Use the libcurl backend" OFF)
 	option (USE_OPENSSL_BACKEND "Use the openssl backend" OFF)
 	option (USE_SCHANNEL_BACKEND "Use the schannel backend (windows-only)" OFF)
 	option (USE_NSURL_BACKEND "Use the NSUrl backend (macos-only)" ON)
+
+	option (USE_WINSOCK "Use winsock instead of BSD sockets (windows-only)" OFF)
 endif ()
 
 ### Dependencies

+ 7 - 6
src/common/PlaintextConnection.cpp

@@ -1,5 +1,6 @@
+#include "common/config.h"
 #include <cstring>
-#ifndef PLATFORM_WINDOWS
+#ifndef USE_WINSOCK
 #	include <netdb.h>
 #	include <unistd.h>
 #	include <sys/types.h>
@@ -9,28 +10,28 @@
 #	include <ws2tcpip.h>
 #	undef min
 #	undef max
-#endif // PLATFORM_WINDOWS
+#endif // USE_WINSOCK
 
 #include "PlaintextConnection.h"
 
-#ifdef PLATFORM_WINDOWS
+#ifdef USE_WINSOCK
 	static void close(int fd)
 	{
 		closesocket(fd);
 	}
-#endif // PLATFORM_WINDOWS
+#endif // USE_WINSOCK
 
 PlaintextConnection::PlaintextConnection()
 	: fd(-1)
 {
-#ifdef PLATFORM_WINDOWS
+#ifdef USE_WINSOCK
 	static bool wsaInit = false;
 	if (!wsaInit)
 	{
 		WSADATA data;
 		WSAStartup(MAKEWORD(2, 2), &data);
 	}
-#endif
+#endif // USE_WINSOCK
 }
 
 PlaintextConnection::~PlaintextConnection()

+ 1 - 0
src/common/config.h.in

@@ -2,3 +2,4 @@
 #cmakedefine USE_OPENSSL_BACKEND
 #cmakedefine USE_SCHANNEL_BACKEND
 #cmakedefine USE_NSURL_BACKEND
+#cmakedefine USE_WINSOCK