-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
156 lines (125 loc) · 4.46 KB
/
CMakeLists.txt
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
# -- 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 -fexperimental-library)
message (STATUS "Build type ${CMAKE_BUILD_TYPE}")
# -- 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/609281088cfefc76f9d0ce82e1ff6c30cc3591e5.zip
)
FetchContent_MakeAvailable(googletest)
endif()
# Threads
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/acceptor.cpp
src/net/event_result.cpp
src/net/ip/v4_address.cpp
src/net/ip/v4_endpoint.cpp
src/net/multiplexer_impl.cpp
src/net/kqueue_multiplexer.cpp
src/net/operation.cpp
src/net/pollset_updater.cpp
src/net/socket_manager.cpp
src/net/uri.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_code.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 OpenSSL::Crypto OpenSSL::SSL)
# 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")
# -- 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/acceptor.cpp
test/net/datagram_socket.cpp
test/net/ip/v4_address.cpp
test/net/ip/v4_endpoint.cpp
test/net/kqueue_multiplexer.cpp
test/net/pollset_updater.cpp
test/net/socket_guard.cpp
test/net/socket_manager.cpp
test/net/stream_transport.cpp
test/net/tcp_socket.cpp
test/net/tls.cpp
test/net/transport_adaptor.cpp
test/net/udp_datagram_socket.cpp
test/net/uri.cpp
test/openssl/communication.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
)
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
gtest
)
gtest_discover_tests(lib_net_test)
endif()