Skip to content

Commit 109918f

Browse files
authored
[+] Add Windows support (beta) (#160)
1 parent d1348ec commit 109918f

40 files changed

+686
-280
lines changed

CMakeLists.txt

+87-20
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,40 @@ if(NOT SSL_TYPE)
1717
set(SSL_TYPE "babassl")
1818
endif()
1919

20-
# PATH of ssl
21-
if(NOT SSL_PATH)
22-
set(SSL_PATH "/usr/local/babassl")
20+
if(${SSL_TYPE} MATCHES "babassl")
21+
# PATH of ssl
22+
if(NOT SSL_PATH)
23+
set(SSL_PATH "/usr/local/babassl")
24+
endif()
25+
26+
# ssl lib denpendency
27+
if(NOT SSL_LIB_PATH)
28+
set(SSL_LIB_PATH
29+
${SSL_PATH}/lib/libssl.a
30+
${SSL_PATH}/lib/libcrypto.a
31+
)
32+
endif()
33+
elseif(${SSL_TYPE} MATCHES "boringssl")
34+
# PATH of ssl
35+
if(NOT SSL_PATH)
36+
set(SSL_PATH ${CMAKE_CURRENT_SOURCE_DIR}/third_party/boringssl)
37+
endif()
38+
39+
# ssl lib denpendency
40+
if(NOT SSL_LIB_PATH)
41+
if(CMAKE_SYSTEM_NAME MATCHES "Windows")
42+
add_definitions(-DNOCRYPT=1)
43+
set(SSL_LIB_PATH
44+
${SSL_PATH}/build/ssl/${CMAKE_BUILD_TYPE}/ssl.lib
45+
${SSL_PATH}/build/crypto/${CMAKE_BUILD_TYPE}/crypto.lib
46+
)
47+
else()
48+
set(SSL_LIB_PATH
49+
${SSL_PATH}/build/ssl/libssl.a
50+
${SSL_PATH}/build/crypto/libcrypto.a
51+
)
52+
endif()
53+
endif()
2354
endif()
2455

2556
# ssl include path
@@ -29,13 +60,10 @@ if(NOT SSL_INC_PATH)
2960
)
3061
endif()
3162

32-
# ssl lib denpendency
33-
if(NOT SSL_LIB_PATH)
34-
set(SSL_LIB_PATH
35-
${SSL_PATH}/lib/libssl.a
36-
${SSL_PATH}/lib/libcrypto.a
37-
)
38-
endif()
63+
MESSAGE("SSL_TYPE= ${SSL_TYPE}")
64+
MESSAGE("SSL_PATH= ${SSL_PATH}")
65+
MESSAGE("SSL_LIB_PATH= ${SSL_LIB_PATH}")
66+
MESSAGE("SSL_INC_PATH= ${SSL_INC_PATH}")
3967

4068
# print tls traffic secret in keylog
4169
if(XQC_PRINT_SECRET)
@@ -65,8 +93,15 @@ endif()
6593

6694

6795
# C_FLAGS
68-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O2 -std=gnu11 -Werror -Wall -Wno-unused -Wno-pointer-sign -Wno-format-security -DNDEBUG_PRINT -DNPRINT_MALLOC ")
69-
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS} -g -O0 -std=gnu11 -Werror -Wall -Wno-unused -Wno-pointer-sign -Wno-format-security -DNDEBUG_PRINT -DNPRINT_MALLOC -DXQC_DEBUG ")
96+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O2 -std=gnu11 -Wall -DNDEBUG_PRINT -DNPRINT_MALLOC ")
97+
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS} -g -O0 -std=gnu11 -Wall -DNDEBUG_PRINT -DNPRINT_MALLOC -DXQC_DEBUG ")
98+
99+
if(NOT CMAKE_SYSTEM_NAME MATCHES "Windows")
100+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror -Wno-unused -Wno-pointer-sign -Wno-format-security ")
101+
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Werror -Wno-unused -Wno-pointer-sign -Wno-format-security ")
102+
else()
103+
add_definitions(-DXQC_SYS_WINDOWS=1)
104+
endif()
70105

71106
# additional C_FLAGS on mac
72107
if(PLATFORM STREQUAL "mac32")
@@ -263,10 +298,9 @@ include_directories(${SSL_INC_PATH})
263298
include_directories(${CMAKE_SOURCE_DIR}/)
264299

265300

266-
267301
##### build unittest, test client/server, demo client/server #####
268302
if (XQC_ENABLE_TESTING)
269-
# CUnit
303+
# CUnit TODO: fix test unit on windows
270304
find_package(CUnit 2.1)
271305
enable_testing()
272306
set(HAVE_CUNIT ${CUNIT_FOUND})
@@ -275,10 +309,24 @@ if (XQC_ENABLE_TESTING)
275309
endif()
276310

277311
add_subdirectory(tests)
312+
include_directories(${CMAKE_CURRENT_BINARY_DIR}/test)
313+
314+
if(CMAKE_SYSTEM_NAME MATCHES "Windows")
315+
# used wingetopt on windows
316+
if(NOT GETOPT_INC_PATH)
317+
set(GETOPT_INC_PATH
318+
${CMAKE_SOURCE_DIR}/third_party/wingetopt
319+
)
320+
endif()
321+
MESSAGE("GETOPT_INC_PATH= ${GETOPT_INC_PATH}")
322+
323+
include_directories(${GETOPT_INC_PATH}/src)
324+
set(GETOPT_SOURCES "${GETOPT_INC_PATH}/src/getopt.c")
325+
endif()
278326

279327
### test client/server ###
280-
add_executable(test_server tests/test_server.c)
281-
add_executable(test_client tests/test_client.c)
328+
add_executable(test_server tests/test_server.c ${GETOPT_SOURCES})
329+
add_executable(test_client tests/test_client.c ${GETOPT_SOURCES})
282330

283331
### hq demo client/server ###
284332
set(
@@ -300,10 +348,24 @@ if (XQC_ENABLE_TESTING)
300348
"demo/demo_server.c"
301349
)
302350

303-
add_executable(demo_server ${DEMO_SERVER_SOURCES})
304-
add_executable(demo_client ${DEMO_CLIENT_SOURCES})
305-
306-
link_directories(/usr/local/lib)
351+
add_executable(demo_server ${DEMO_SERVER_SOURCES} ${GETOPT_SOURCES})
352+
add_executable(demo_client ${DEMO_CLIENT_SOURCES} ${GETOPT_SOURCES})
353+
if(CMAKE_SYSTEM_NAME MATCHES "Windows")
354+
if (NOT EVENT_LIB_DIR)
355+
message("YOU NEED SET -DEVENT_LIB_DIR=your_event_path, eg:-DEVENT_LIB_DIR=D:/project/vcpkg/packages/libevent_x64-windows-static")
356+
endif()
357+
358+
include_directories( ${EVENT_LIB_DIR}/include )
359+
link_directories( ${EVENT_LIB_DIR}/lib )
360+
361+
SET(EVENT_LIB_PATH
362+
${EVENT_LIB_DIR}/lib/event.lib
363+
${EVENT_LIB_DIR}/lib/event_core.lib
364+
${EVENT_LIB_DIR}/lib/event_extra.lib
365+
)
366+
else()
367+
link_directories( /usr/local/lib )
368+
endif()
307369

308370
if(PLATFORM STREQUAL "mac32")
309371
target_link_libraries(test_server xquic -lm ${CMAKE_CURRENT_SOURCE_DIR}/../libevent32/lib/libevent.dylib)
@@ -315,6 +377,11 @@ if (XQC_ENABLE_TESTING)
315377
target_link_libraries(test_client xquic -lm -L/usr/local/lib -levent)
316378
target_link_libraries(demo_server xquic -lm -L/usr/local/lib -levent)
317379
target_link_libraries(demo_client xquic -lm -L/usr/local/lib -levent)
380+
elseif(CMAKE_SYSTEM_NAME MATCHES "Windows")
381+
target_link_libraries(test_server xquic ${EVENT_LIB_PATH} -lm)
382+
target_link_libraries(test_client xquic ${EVENT_LIB_PATH} -lm)
383+
target_link_libraries(demo_server xquic ${EVENT_LIB_PATH} -lm)
384+
target_link_libraries(demo_client xquic ${EVENT_LIB_PATH} -lm)
318385
else()
319386
target_link_libraries(test_server xquic -levent -lm)
320387
target_link_libraries(test_client xquic -levent -lm)

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ XQUIC Library released by Alibaba is …
1616

1717
**a client and server implementation of QUIC and HTTP/3 as specified by the IETF.** Currently supported QUIC versions are v1 and draft-29.
1818

19-
**OS and platform agnostic.** It currently supports Android, iOS, Linux and macOS. Most of the code is used in our own products, and has been tested at scale on android, iOS apps, as well as servers.
19+
**OS and platform agnostic.** It currently supports Android, iOS, Linux, macOS and Windows. Most of the code is used in our own products, and has been tested at scale on android, iOS apps, as well as servers.
2020

2121
**still in active development.** [Interoperability](https://interop.seemann.io/) is regularly tested with other QUIC implementations.
2222

demo/common.h

-12
Original file line numberDiff line numberDiff line change
@@ -94,16 +94,4 @@ xqc_demo_read_file_data(char * data, size_t data_len, char *filename)
9494
return ret;
9595
}
9696

97-
98-
static inline uint64_t
99-
xqc_demo_now()
100-
{
101-
/* get microsecond unit time */
102-
struct timeval tv;
103-
gettimeofday(&tv, NULL);
104-
uint64_t ul = tv.tv_sec * (uint64_t)1000000 + tv.tv_usec;
105-
return ul;
106-
}
107-
108-
10997
#endif

0 commit comments

Comments
 (0)