-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
202 lines (156 loc) · 5.75 KB
/
Copy pathCMakeLists.txt
File metadata and controls
202 lines (156 loc) · 5.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# -- project setup -------------------------------------------------------------
cmake_minimum_required(VERSION 3.12 FATAL_ERROR)
project(lib_net CXX)
include(FetchContent)
include(GoogleTest)
# Avoid warning about DOWNLOAD_EXTRACT_TIMESTAMP in CMake 3.24:
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
cmake_policy(SET CMP0135 NEW)
endif()
# -- set useful CMake options --------------------------------------------------
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_FLAGS_DEBUG "-g")
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
add_compile_options(-Wall -Wextra -pedantic -Werror)
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
# -- build type configuration --------------------------------------------------
message (STATUS "Build type ${CMAKE_BUILD_TYPE}")
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(LIB_NET_DEBUG TRUE)
add_compile_definitions(LIB_NET_DEBUG)
endif()
# -- find or fetch dependencies ------------------------------------------------
# Threads
find_package(Threads REQUIRED)
if (LIB_NET_ENABLE_TESTS)
# Googletest
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip
)
FetchContent_MakeAvailable(googletest)
endif()
if(LIB_NET_ENABLE_URING)
if(LINUX)
find_package(IoUring REQUIRED)
add_compile_definitions(LIB_NET_URING)
else()
message(FATAL_ERROR "io_uring support is only available on Linux")
endif()
endif()
# OpenSSL
# find_package(OpenSSL REQUIRED)
# -- project files -------------------------------------------------------------
# Find the packet-routing headers
file(GLOB_RECURSE LIB_NET_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/libnet/*.hpp")
# New source files have to be added here
set(LIB_NET_SOURCES
src/net/multiplexer.cpp
src/net/operation.cpp
src/net/uri.cpp
src/net/detail/acceptor.cpp
src/net/detail/epoll_multiplexer.cpp
src/net/detail/kqueue_multiplexer.cpp
src/net/detail/manager_base.cpp
src/net/detail/multiplexer_base.cpp
src/net/detail/pollset_updater.cpp
src/net/detail/uring_manager.cpp
src/net/detail/uring_multiplexer.cpp
src/net/ip/v4_address.cpp
src/net/ip/v4_endpoint.cpp
src/openssl/tls_context.cpp
src/openssl/tls_session.cpp
src/net/socket/datagram_socket.cpp
src/net/socket/pipe_socket.cpp
src/net/socket/socket.cpp
src/net/socket/stream_socket.cpp
src/net/socket/tcp_accept_socket.cpp
src/net/socket/tcp_stream_socket.cpp
src/net/socket/udp_datagram_socket.cpp
src/util/binary_deserializer.cpp
src/util/binary_serializer.cpp
src/util/cli_parser.cpp
src/util/config.cpp
src/util/error.cpp
src/util/format.cpp
)
# -- Object for different targets ----------------------------------------------
add_library(net STATIC ${LIB_NET_HEADERS} ${LIB_NET_SOURCES})
set_property(TARGET net PROPERTY POSITION_INDEPENDENT_CODE ON)
target_include_directories(net PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/libnet")
target_link_libraries(net Threads::Threads)
if(LIB_NET_ENABLE_URING)
target_link_libraries(net IoUring::IoUring)
endif()
# Copy Dummy certs to build folder and set preprocessor definition to the folder
file(COPY "${PROJECT_SOURCE_DIR}/certs" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}")
add_compile_definitions(CERT_DIRECTORY="${CMAKE_CURRENT_BINARY_DIR}/certs")
# -- assertion configuration ---------------------------------------------------
option(LIB_NET_ENABLE_ASSERTIONS "Enable runtime assertions" OFF)
if(LIB_NET_ENABLE_ASSERTIONS)
if(NOT LIB_NET_DEBUG)
message(WARNING "This is a release build and assertions are enabled. Assertions have a significant impact on the runtime performance - Consider disabling them if not really necessary.")
endif()
add_compile_definitions(LIB_NET_ENABLE_ASSERTIONS)
endif()
# -- logging configuration -----------------------------------------------------
if(LIB_NET_LOG_LEVEL)
message(STATUS "Logging enabled: ${LIB_NET_LOG_LEVEL}")
add_compile_definitions(NET_LOG_LEVEL=${LIB_NET_LOG_LEVEL})
else()
message(STATUS "Logging disabled")
endif()
# -- main for playing with things ----------------------------------------------
macro(add_target name)
add_executable(${name} "src/${name}.cpp")
target_include_directories(${name} PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/libnet")
target_link_libraries(${name} PRIVATE net)
endmacro()
add_target(playground)
# -- test setup ----------------------------------------------------------------
if (LIB_NET_ENABLE_TESTS)
enable_testing()
add_executable(
lib_net_test
test/net_test_main.cpp
test/net/datagram_socket.cpp
test/net/multiplexer.cpp
test/net/socket_guard.cpp
test/net/tcp_socket.cpp
test/net/udp_datagram_socket.cpp
test/net/uri.cpp
test/net/detail/acceptor.cpp
test/net/detail/datagram_dispatcher.cpp
test/net/detail/datagram_transport.cpp
test/net/detail/manager_base.cpp
test/net/detail/pollset_updater.cpp
test/net/detail/stream_transport.cpp
test/net/detail/transport_adaptor.cpp
test/net/detail/uring_multiplexer.cpp
test/net/ip/v4_address.cpp
test/net/ip/v4_endpoint.cpp
test/util/binary_deserializer.cpp
test/util/binary_serializer.cpp
test/util/cli_parser.cpp
test/util/config.cpp
test/util/format.cpp
test/util/intrusive_ptr.cpp
test/util/ref_counted.cpp
test/util/scope_guard.cpp
test/util/serialized_size.cpp
test/net/full_integration/stream_transport.cpp
# test/net/tls.cpp
# test/openssl/communication.cpp
)
target_include_directories(lib_net_test PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/libnet")
target_include_directories(lib_net_test PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/test")
target_link_libraries(
lib_net_test
net
gmock
)
gtest_discover_tests(lib_net_test)
endif()