Skip to content

Commit a3d7a41

Browse files
Make compilation work with MS Visual Studio on Windows (#32)
1 parent 8e99a9c commit a3d7a41

File tree

5 files changed

+34
-2
lines changed

5 files changed

+34
-2
lines changed

cmake/CompilerWarnings.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ function(set_project_c_warnings library_name)
2121
set(C_PROJECT_WARNINGS ${CLANG_C_WARNINGS})
2222
elseif(CMAKE_C_COMPILER_ID STREQUAL "AppleClang")
2323
set(C_PROJECT_WARNINGS ${CLANG_C_WARNINGS})
24-
else()
24+
elseif(CMAKE_C_COMPILER_ID STREQUAL "GNU")
2525
set(C_PROJECT_WARNINGS ${GCC_C_WARNINGS})
2626
endif()
2727

@@ -53,7 +53,7 @@ function(set_project_cpp_warnings library_name)
5353
set(CPP_PROJECT_WARNINGS ${CLANG_CPP_WARNINGS})
5454
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
5555
set(CPP_PROJECT_WARNINGS ${CLANG_CPP_WARNINGS})
56-
else()
56+
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
5757
set(CPP_PROJECT_WARNINGS ${GCC_CPP_WARNINGS})
5858
endif()
5959

src/mgallocator.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
#include <stdlib.h>
2121
#include <string.h>
2222

23+
#ifdef _MSC_VER
24+
typedef double max_align_t;
25+
#endif
26+
2327
void *mg_system_realloc(struct mg_allocator *self, void *buf, size_t size) {
2428
(void)self;
2529
return realloc(buf, size);

src/mgsession.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
#include <stdio.h>
2121
#include <stdlib.h>
2222
#include <string.h>
23+
#ifndef _MSC_VER
2324
#include <unistd.h>
25+
#endif
2426

2527
#include "mgcommon.h"
2628
#include "mgconstants.h"

src/mgsocket.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ extern "C" {
4343
#include <Ws2tcpip.h>
4444
#include <windows.h>
4545
#include <winsock2.h>
46+
#ifdef _MSC_VER
47+
typedef long ssize_t;
48+
#endif
4649
#endif // MGCLIENT_ON_WINDOWS
4750

4851
#include "mgclient.h"

src/windows/mgcommon.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,27 @@
1717

1818
// Based on https://gist.github.com/PkmX/63dd23f28ba885be53a5
1919

20+
#if defined(_MSC_VER)
21+
22+
#include <stdlib.h>
23+
24+
#define htobe16(x) _byteswap_ushort(x)
25+
#define htole16(x) (x)
26+
#define be16toh(x) _byteswap_ushort(x)
27+
#define le16toh(x) (x)
28+
29+
#define htobe32(x) _byteswap_ulong(x)
30+
#define htole32(x) (x)
31+
#define be32toh(x) _byteswap_ulong(x)
32+
#define le32toh(x) (x)
33+
34+
#define htobe64(x) _byteswap_uint64(x)
35+
#define htole64(x) (x)
36+
#define be64toh(x) _byteswap_uint64(x)
37+
#define le64toh(x) (x)
38+
39+
#else
40+
2041
#define htobe16(x) __builtin_bswap16(x)
2142
#define htole16(x) (x)
2243
#define be16toh(x) __builtin_bswap16(x)
@@ -33,3 +54,5 @@
3354
#define le64toh(x) (x)
3455

3556
#endif
57+
58+
#endif

0 commit comments

Comments
 (0)