Jelajahi Sumber

fix mingw compile error

ithewei 1 tahun lalu
induk
melakukan
e2ee1069a8
2 mengubah file dengan 7 tambahan dan 7 penghapusan
  1. 5 5
      CMakeLists.txt
  2. 2 2
      http/server/FileCache.cpp

+ 5 - 5
CMakeLists.txt

@@ -29,7 +29,7 @@ option(WITH_MBEDTLS "with mbedtls library" OFF)
 
 option(WITH_KCP "compile event/kcp" OFF)
 
-if(WIN32)
+if(WIN32 OR MINGW)
     option(WITH_WEPOLL "compile event/wepoll -> use iocp" ON)
     option(ENABLE_WINDUMP "Windows MiniDumpWriteDump" OFF)
     option(BUILD_FOR_MT "build for /MT" OFF)
@@ -126,7 +126,7 @@ endif()
 if(WITH_CURL)
     add_definitions(-DWITH_CURL)
     set(LIBS ${LIBS} curl)
-    if(WIN32)
+    if(WIN32 OR MINGW)
         set(LIBS ${LIBS} wldap32 advapi32 crypt32)
     endif()
 endif()
@@ -156,7 +156,7 @@ if(WITH_MBEDTLS)
     set(LIBS ${LIBS} mbedtls mbedx509 mbedcrypto)
 endif()
 
-if(WIN32)
+if(WIN32 OR MINGW)
     add_definitions(-DWIN32_LEAN_AND_MEAN -D_CRT_SECURE_NO_WARNINGS -D_WIN32_WINNT=0x0600)
     set(LIBS ${LIBS} secur32 crypt32 winmm iphlpapi ws2_32)
     if(ENABLE_WINDUMP)
@@ -167,7 +167,7 @@ endif()
 
 if(ANDROID)
     set(LIBS ${LIBS} log)
-elseif(UNIX)
+elseif(UNIX AND NOT MINGW)
     set(LIBS ${LIBS} pthread m dl)
     if(CMAKE_COMPILER_IS_GNUCC)
         set(LIBS ${LIBS} rt)
@@ -181,7 +181,7 @@ endif()
 # see Makefile
 set(ALL_SRCDIRS . base ssl event event/kcp util cpputil evpp protocol http http/client http/server mqtt)
 set(CORE_SRCDIRS . base ssl event)
-if(WIN32)
+if(WIN32 OR MINGW)
     if(WITH_WEPOLL)
         set(CORE_SRCDIRS ${CORE_SRCDIRS} event/wepoll)
     endif()

+ 2 - 2
http/server/FileCache.cpp

@@ -8,7 +8,7 @@
 #include "httpdef.h"    // import http_content_type_str_by_suffix
 #include "http_page.h"  // import make_index_of_page
 
-#ifdef OS_WIN
+#ifdef _MSC_VER
 #include <codecvt>
 #endif
 
@@ -20,7 +20,7 @@ FileCache::FileCache() {
 }
 
 static int hv_open(char const* filepath, int flags) {
-#ifdef OS_WIN
+#ifdef _MSC_VER
     std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> conv;
     auto wfilepath = conv.from_bytes(filepath);
     int fd = _wopen(wfilepath.c_str(), flags);