-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
199 lines (169 loc) · 6.37 KB
/
CMakeLists.txt
File metadata and controls
199 lines (169 loc) · 6.37 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
cmake_minimum_required(VERSION 3.21)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
project(qunet VERSION 1.0.0)
option(QUNET_TLS_SUPPORT "Enable TLS support (for DNS over TLS and other), implied ON if QUIC is enabled" OFF)
option(QUNET_QUIC_SUPPORT "Enable QUIC support" OFF)
option(QUNET_WS_SUPPORT "Enable WebSocket support" OFF)
option(QUNET_ADVANCED_DNS "Enable advanced DNS resolver" ON)
option(QUNET_DEBUG "Enable debug mode" OFF)
option(QUNET_BUILD_TESTER OFF)
option(QUNET_ENABLE_OPENSSL OFF)
option(QUNET_ENABLE_WOLFSSL OFF)
if (QUNET_QUIC_SUPPORT)
set(QUNET_TLS_SUPPORT ON)
endif()
file(GLOB SOURCES CONFIGURE_DEPENDS src/*.cpp)
foreach (SUBDIR buffers compression database dns protocol socket util)
file(GLOB_RECURSE tmp CONFIGURE_DEPENDS src/${SUBDIR}/*.cpp)
list(APPEND SOURCES ${tmp})
endforeach()
if (QUNET_TLS_SUPPORT)
file(GLOB TLS_SOURCES CONFIGURE_DEPENDS src/tls/*.cpp)
list(APPEND SOURCES ${TLS_SOURCES})
endif()
add_library(qunet STATIC ${SOURCES})
#
target_include_directories(qunet PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_include_directories(qunet PRIVATE src)
if (QUNET_DEBUG)
target_compile_definitions(qunet PUBLIC QUNET_DEBUG=1)
message(STATUS "Qunet: debug mode enabled!")
endif()
# i absolutely hate microsoft
if (WIN32)
target_compile_definitions(qunet PRIVATE _HAS_ITERATOR_DEBUGGING=0)
target_compile_definitions(qunet PUBLIC NOMINMAX _WINSOCKAPI_)
endif()
# cpm
if (NOT COMMAND CPMAddPackage)
include(cmake/CPM.cmake)
endif()
# add deps
set(ARC_FEATURE_DEBUG ${QUNET_DEBUG})
if (NOT TARGET asp2)
CPMAddPackage("gh:dankmeme01/asp2#a3a1414")
endif()
if (NOT TARGET arc)
CPMAddPackage("gh:dankmeme01/arc@1.5.3")
endif()
if (NOT TARGET dbuf)
CPMAddPackage("gh:dankmeme01/dbuf@1.0.2")
endif()
# pain and suffering
if (NOT TARGET libzstd_static)
CPMAddPackage("gh:facebook/zstd#v1.5.7")
set(ZSTD_BUILD_SHARED OFF)
set(ZSTD_BUILD_STATIC ON)
set(ZSTD_BUILD_PROGRAMS OFF)
set(ZSTD_BUILD_TESTS OFF)
set(ZSTD_BUILD_CONTRIB OFF)
set(ZSTD_MULTITHREAD_SUPPORT OFF)
set(ZSTD_LEGACY_SUPPORT OFF)
add_subdirectory(${zstd_SOURCE_DIR}/build/cmake zstd)
endif()
if (NOT TARGET lz4_static)
CPMAddPackage("gh:lz4/lz4#v1.10.0")
set(LZ4_BUILD_CLI OFF)
add_subdirectory(${lz4_SOURCE_DIR}/build/cmake lz4)
endif()
if (NOT TARGET blake3)
CPMAddPackage("gh:BLAKE3-team/BLAKE3#1.8.2")
if (WIN32 OR APPLE)
set(BLAKE3_SIMD_TYPE "none")
endif()
add_subdirectory(${BLAKE3_SOURCE_DIR}/c blake3)
endif()
target_link_libraries(qunet PRIVATE libzstd_static lz4_static blake3)
target_link_libraries(qunet PUBLIC qsox asp arc fmt dbuf std23::nontype_functional)
if (QUNET_ADVANCED_DNS)
if (NOT TARGET c-ares)
CPMAddPackage(
NAME c-ares
GIT_REPOSITORY "https://github.com/c-ares/c-ares.git"
GIT_TAG "89f91c0" # TODO: use stable version when a 1.34.7 or 1.35 is out
# the commit right after 89f91c0 also broke the local dns server getter
OPTIONS "CARES_STATIC ON"
"CARES_SHARED OFF"
"CARES_INSTALL OFF"
"CARES_BUILD_TOOLS OFF"
)
target_compile_options(c-ares PRIVATE "-Wno-sign-conversion")
endif()
target_compile_definitions(qunet PUBLIC QUNET_ADVANCED_DNS=1 CARES_STATICLIB)
target_link_libraries(qunet PRIVATE c-ares)
endif()
if (QUNET_TLS_SUPPORT)
if (NOT TARGET xtls)
if (PROJECT_IS_TOP_LEVEL)
CPMAddPackage(
URI "gh:dankmeme01/xtls#12695fe"
OPTIONS "XTLS_ENABLE_OPENSSL ${QUNET_ENABLE_OPENSSL}"
"XTLS_ENABLE_WOLFSSL ${QUNET_ENABLE_WOLFSSL}"
"XTLS_ENABLE_SOCKET ${QUNET_WS_SUPPORT}"
"XTLS_ENABLE_ARC_SOCKET ${QUNET_WS_SUPPORT}"
)
else()
message(FATAL_ERROR "xtls must be included with your preferred TLS backend for TLS support")
endif()
endif()
target_compile_definitions(qunet PUBLIC QUNET_TLS_SUPPORT=1)
target_link_libraries(qunet PUBLIC xtls)
endif()
if (QUNET_QUIC_SUPPORT)
if (NOT TARGET ngtcp2_static)
CPMAddPackage(
NAME ngtcp2
GIT_REPOSITORY "https://github.com/ngtcp2/ngtcp2.git"
GIT_TAG "v1.18.0"
OPTIONS "ENABLE_LIB_ONLY ON"
"ENABLE_STATIC_LIB ON"
"ENABLE_SHARED_LIB OFF"
"ENABLE_OPENSSL ${QUNET_ENABLE_OPENSSL}"
"ENABLE_WOLFSSL ${QUNET_ENABLE_WOLFSSL}"
"BUILD_TESTING OFF"
)
if (MSVC)
target_compile_options(ngtcp2_static PRIVATE /w)
else()
target_compile_options(ngtcp2_static PRIVATE -w)
endif()
endif()
if (QUNET_ENABLE_OPENSSL)
message("Qunet: using OpenSSL for crypto")
target_link_libraries(qunet PRIVATE ngtcp2_crypto_ossl_static)
target_compile_definitions(qunet PUBLIC QUNET_ENABLE_OPENSSL)
elseif(QUNET_ENABLE_WOLFSSL)
message("Qunet: using WolfSSL for crypto")
target_link_libraries(qunet PRIVATE ngtcp2_crypto_wolfssl_static)
target_compile_definitions(qunet PUBLIC QUNET_ENABLE_WOLFSSL)
else()
message(FATAL_ERROR "At least one crypto backend must be enabled")
endif()
target_link_libraries(qunet PRIVATE ngtcp2_static)
target_compile_definitions(qunet PUBLIC QUNET_QUIC_SUPPORT=1)
endif()
if (QUNET_WS_SUPPORT)
if (NOT TARGET wsx)
CPMAddPackage(
URI "gh:dankmeme01/wsx#e936ecc"
OPTIONS "WSX_ENABLE_TLS ${QUNET_TLS_SUPPORT}"
"WSX_ENABLE_ASYNC ON"
)
endif()
target_link_libraries(qunet PUBLIC wsx xtls)
target_compile_definitions(qunet PUBLIC QUNET_WS_SUPPORT=1)
endif()
if (QUNET_BUILD_TESTER)
# Qunet tester
file(GLOB_RECURSE TESTER_SOURCES CONFIGURE_DEPENDS tester/*.cpp)
add_executable(qunet_tester ${TESTER_SOURCES})
target_link_libraries(qunet_tester PRIVATE qunet qsox)
# add asan
# if (NOT WIN32)
# target_compile_options(qunet_tester PRIVATE -fsanitize=address -fno-omit-frame-pointer -g)
# target_compile_options(qunet PRIVATE -fsanitize=address -fno-omit-frame-pointer -g)
# target_link_options(qunet_tester PRIVATE -fsanitize=address)
# target_link_options(qunet PRIVATE -fsanitize=address)
# endif()
endif()