Skip to content

Commit faea59c

Browse files
an-taomcirstatao-an
authored
Port Trantor to Windows (#64)
Co-authored-by: mcirsta <mforce2@gmail.com> Co-authored-by: tao-an <50053014+tao-an@users.noreply.github.com>
1 parent 08eb898 commit faea59c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+3307
-156
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@
22
build
33
cmake-build-debug
44
.vscode
5+
.vs
6+
CMakeSettings.json

CMakeLists.txt

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
cmake_minimum_required(VERSION 3.5)
22
project(trantor)
33
add_library(${PROJECT_NAME} STATIC)
4-
# if(MSVC)
5-
# target_compile_options(${PROJECT_NAME} PRIVATE /W4 /WX)
6-
# else()
7-
# target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra -pedantic)
4+
# if(MSVC) target_compile_options(${PROJECT_NAME} PRIVATE /W4 /WX) else()
5+
# target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra -pedantic)
86
# endif()
97

108
set(TRANTOR_MAJOR_VERSION 1)
@@ -13,6 +11,7 @@ set(TRANTOR_PATCH_VERSION 0)
1311
set(TRANTOR_VERSION
1412
${TRANTOR_MAJOR_VERSION}.${TRANTOR_MINOR_VERSION}.${TRANTOR_PATCH_VERSION})
1513

14+
1615
# Offer the user the choice of overriding the installation directories
1716
set(INSTALL_LIB_DIR lib CACHE PATH "Installation directory for libraries")
1817
set(INSTALL_INCLUDE_DIR
@@ -38,14 +37,20 @@ foreach(p
3837
endif()
3938
endforeach()
4039

40+
if(WIN32)
41+
add_subdirectory(third_party/wepoll)
42+
endif(WIN32)
43+
4144
# include directories
42-
target_include_directories(${PROJECT_NAME}
43-
PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
44-
$<INSTALL_INTERFACE:${INSTALL_INCLUDE_DIR}>
45-
PRIVATE ${PROJECT_SOURCE_DIR}
46-
${PROJECT_SOURCE_DIR}/trantor/utils
47-
${PROJECT_SOURCE_DIR}/trantor/net
48-
${PROJECT_SOURCE_DIR}/trantor/net/inner)
45+
target_include_directories(
46+
${PROJECT_NAME}
47+
PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
48+
$<INSTALL_INTERFACE:${INSTALL_INCLUDE_DIR}>
49+
PRIVATE ${PROJECT_SOURCE_DIR}
50+
${PROJECT_SOURCE_DIR}/trantor/utils
51+
${PROJECT_SOURCE_DIR}/trantor/net
52+
${PROJECT_SOURCE_DIR}/trantor/net/inner
53+
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/third_party/wepoll>)
4954

5055
set(TRANTOR_SOURCES
5156
trantor/utils/AsyncFileLogger.cc
@@ -73,6 +78,10 @@ set(TRANTOR_SOURCES
7378
trantor/net/inner/poller/EpollPoller.cc
7479
trantor/net/inner/poller/KQueue.cc)
7580

81+
if(WIN32)
82+
set(TRANTOR_SOURCES ${TRANTOR_SOURCES} trantor/utils/WindowsSupport.cc)
83+
endif(WIN32)
84+
7685
find_package(OpenSSL)
7786
if(OpenSSL_FOUND)
7887
target_include_directories(${PROJECT_NAME} PRIVATE ${OPENSSL_INCLUDE_DIR})
@@ -93,17 +102,23 @@ else()
93102
set(TRANTOR_SOURCES ${TRANTOR_SOURCES} trantor/net/inner/NormalResolver.cc)
94103
endif()
95104
target_sources(${PROJECT_NAME} PRIVATE ${TRANTOR_SOURCES})
96-
target_link_libraries(${PROJECT_NAME} PRIVATE pthread)
105+
106+
if(WIN32)
107+
target_link_libraries(${PROJECT_NAME} PRIVATE ws2_32 Rpcrt4 wepoll)
108+
else()
109+
target_link_libraries(${PROJECT_NAME} PRIVATE pthread)
110+
endif(WIN32)
97111

98112
set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 14)
99113
set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD_REQUIRED ON)
100114
set_target_properties(${PROJECT_NAME} PROPERTIES CXX_EXTENSIONS OFF)
101115
set_target_properties(${PROJECT_NAME} PROPERTIES EXPORT_NAME Trantor)
102116

103-
if(MAKETEST STREQUAL YES)
117+
if(BUILD_TESTING)
104118
add_subdirectory(trantor/tests)
105119
find_package(GTest)
106120
if(GTest_FOUND)
121+
enable_testing()
107122
add_subdirectory(trantor/unittests)
108123
endif()
109124
endif()

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33
[![Build Status](https://travis-ci.org/an-tao/trantor.svg?branch=master)](https://travis-ci.org/an-tao/trantor)
44
[![Language grade: C/C++](https://img.shields.io/lgtm/grade/cpp/g/an-tao/trantor.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/an-tao/trantor/context:cpp)
55

6-
A non-blocking I/O TCP network library, using C++14/17,
6+
A non-blocking I/O cross-platform TCP network library, using C++14.
77
Drawing on the design of Muduo Library
88

99
## Dependence
1010

11-
gcc 5.4.0 or newer;
1211
cmake 3.5 or newer;
1312
linux kernel 2.6.9 x86-64 or newer;

format.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#!/bin/sh
22

33
clang-format --version
4+
5+
find trantor -name *.h -o -name *.cc -exec dos2unix {} \;
46
find trantor -name *.h -o -name *.cc|xargs clang-format -i -style=file

third_party/wepoll/CMakeLists.txt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
project (wepoll C)
2+
3+
cmake_minimum_required (VERSION 3.5)
4+
5+
option (BUILD_TESTS "tests?" OFF)
6+
7+
set (headers Wepoll.h)
8+
set (sources Wepoll.c)
9+
10+
add_library (wepoll STATIC ${sources})
11+
12+
set_target_properties(wepoll PROPERTIES EXPORT_NAME MMAN)
13+
14+
target_link_libraries(wepoll PRIVATE ws2_32)
15+
16+
install (TARGETS wepoll
17+
EXPORT wepollTargets
18+
RUNTIME DESTINATION bin
19+
LIBRARY DESTINATION lib${LIB_SUFFIX}
20+
ARCHIVE DESTINATION lib${LIB_SUFFIX})
21+
22+
install(EXPORT wepollTargets
23+
DESTINATION "${INSTALL_TRANTOR_CMAKE_DIR}"
24+
COMPONENT dev)
25+
26+
install (FILES ${headers} DESTINATION include/sys)
27+
28+
29+

third_party/wepoll/LICENSE

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
wepoll - epoll for Windows
2+
https://github.com/piscisaureus/wepoll
3+
4+
Copyright 2012-2020, Bert Belder <bertbelder@gmail.com>
5+
All rights reserved.
6+
7+
Redistribution and use in source and binary forms, with or without
8+
modification, are permitted provided that the following conditions are
9+
met:
10+
11+
* Redistributions of source code must retain the above copyright
12+
notice, this list of conditions and the following disclaimer.
13+
14+
* Redistributions in binary form must reproduce the above copyright
15+
notice, this list of conditions and the following disclaimer in the
16+
documentation and/or other materials provided with the distribution.
17+
18+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

0 commit comments

Comments
 (0)