-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
332 lines (268 loc) · 9.37 KB
/
Copy pathCMakeLists.txt
File metadata and controls
332 lines (268 loc) · 9.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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
cmake_minimum_required(VERSION 3.22)
project(moqx VERSION 0.1.0 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# Default to RelWithDebInfo for reproducible dev builds.
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "" FORCE)
endif()
# Defines MOQX_VERSION_STRING and the moqx_version interface target.
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/MoqxVersion.cmake)
option(MOQX_BUILD_TESTS "Build tests" ON)
option(MOQX_BUILD_BENCHMARKS "Build benchmarks" OFF)
option(MOQX_ENABLE_SANITIZERS "Enable ASAN/UBSAN (non-Release)" OFF)
option(MOQX_ENABLE_TSAN "Enable TSan (non-Release)" OFF)
if(MOQX_ENABLE_SANITIZERS AND MOQX_ENABLE_TSAN)
message(FATAL_ERROR "MOQX_ENABLE_SANITIZERS and MOQX_ENABLE_TSAN are mutually exclusive")
endif()
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
set(_moqx_bpf_default ON)
else()
set(_moqx_bpf_default OFF)
endif()
option(MOQX_ENABLE_BPF_STEERING
"Attach a classic BPF reuseport filter to steer QUIC packets to the correct worker (Linux only)"
${_moqx_bpf_default})
if(MOQX_ENABLE_SANITIZERS AND NOT CMAKE_BUILD_TYPE STREQUAL "Release")
add_compile_options(-fsanitize=address,undefined -fno-omit-frame-pointer)
add_link_options(-fsanitize=address,undefined)
endif()
if(MOQX_ENABLE_TSAN AND NOT CMAKE_BUILD_TYPE STREQUAL "Release")
add_compile_options(-fsanitize=thread -fno-omit-frame-pointer)
add_link_options(-fsanitize=thread)
endif()
# Prefer static libraries for all transitive deps (from-release mode).
# For from-source builds, build.sh overrides this to ON (system gflags is shared-only).
set(GFLAGS_SHARED OFF CACHE BOOL "")
list(APPEND CMAKE_MODULE_PATH
"${PROJECT_SOURCE_DIR}/deps/moxygen/build/fbcode_builder/CMake"
)
# Folly's config calls FindBoost which was removed in CMake 3.30 (CMP0167).
# Folly itself works fine with Boost's own config-mode package; silence the
# policy warning until upstream fixes their config files.
if(POLICY CMP0167)
cmake_policy(SET CMP0167 OLD)
endif()
find_package(moxygen REQUIRED)
find_package(OpenSSL REQUIRED)
include(cmake/CPM.cmake)
# --- yaml-cpp (CPM) ---
CPMAddPackage(
NAME yaml-cpp
GITHUB_REPOSITORY jbeder/yaml-cpp
GIT_TAG 0.8.0
OPTIONS
"YAML_CPP_BUILD_TESTS OFF"
"YAML_CPP_BUILD_TOOLS OFF"
"YAML_CPP_FORMAT_SOURCE OFF"
"CMAKE_WARN_DEPRECATED OFF"
)
# --- reflect-cpp (FetchContent, needs yaml-cpp available) ---
CPMAddPackage(
NAME reflectcpp
GITHUB_REPOSITORY getml/reflect-cpp
GIT_TAG v0.18.0
OPTIONS "REFLECTCPP_YAML ON" "REFLECTCPP_BUILD_TESTS OFF"
)
# --- XLOG category rooting ---
# Rewrite __FILE__ for moqx sources so folly XLOG categories render as moqx.*
# (e.g. moqx.MoqxRelay) instead of src.* — sources live under src/, but the
# user-facing logging API expects "moqx" as the top-level category. The
# FOLLY_XLOG_STRIP_PREFIXES define handles paths the prefix-map doesn't touch
# (notably generated headers under the build dir). Placed here so subsequent
# moqx_* targets pick it up; yaml-cpp / reflectcpp above were declared before
# this point and are unaffected.
add_compile_options(-fmacro-prefix-map=${CMAKE_CURRENT_SOURCE_DIR}/src=moqx)
add_compile_definitions(
"FOLLY_XLOG_STRIP_PREFIXES=\"${CMAKE_SOURCE_DIR}:${CMAKE_BINARY_DIR}\""
)
# --- catapult (CAT/CWT/MOQT auth implementation) ---
set(ENABLE_LOGGING OFF CACHE BOOL "" FORCE)
set(CATAPULT_ENABLE_JSON OFF CACHE BOOL "" FORCE)
add_subdirectory(deps/catapult EXCLUDE_FROM_ALL)
# --- Cache library (forked from moxygen) ---
add_library(moqx_cache STATIC
src/MoqxCache.cpp
)
target_include_directories(moqx_cache
PUBLIC
${PROJECT_SOURCE_DIR}/src
)
target_link_libraries(moqx_cache PUBLIC
moxygen::moxygen_moq
moxygen::moxygen_moq_consumers
moxygen::moxygen_moq_framer
moxygen::moxygen_util_location_interval_set
Folly::folly_container_f14_hash
Folly::folly_coro_baton
Folly::folly_coro_task
Folly::folly_logging_logging
)
target_compile_options(moqx_cache PRIVATE -Wall -Wextra -Wpedantic)
# --- HMAC key derivation (shared by the relay's verifier and the issuer) ---
add_library(moqx_hmac_key STATIC
src/auth/HmacKey.cpp
)
target_include_directories(moqx_hmac_key
PUBLIC
${PROJECT_SOURCE_DIR}/src
)
target_link_libraries(moqx_hmac_key PUBLIC OpenSSL::Crypto)
target_compile_options(moqx_hmac_key PRIVATE -Wall -Wextra -Wpedantic)
# --- Core library ---
add_library(moqx_core STATIC
src/auth/Auth.cpp
src/LoggingMultiFlag.cpp
src/NamespaceTree.cpp
src/SubscriptionRegistry.cpp
src/MoqxRelay.cpp
src/MoqxRelayContext.cpp
src/MoqxRelayServer.cpp
src/MoqxPicoRelayServer.cpp
src/MoqxQmuxRelayServer.cpp
src/ServiceMatcher.cpp
src/admin/AdminServer.cpp
src/admin/BuiltinRoutes.cpp
src/admin/CachePurgeHandler.cpp
src/admin/ConfigHandler.cpp
src/admin/MetricsHandler.cpp
src/admin/TrackMetricsHandler.cpp
src/admin/StateHandler.cpp
src/stats/StatsRegistry.cpp
src/stats/TrackStatsRegistry.cpp
src/stats/MoQStatsCollector.cpp
src/stats/PicoQuicStatsCollector.cpp
src/stats/QuicStatsCollector.cpp
src/stats/EventBaseStatsCollector.cpp
src/UpstreamProvider.cpp
src/SafeTrackName.cpp
src/relay/AuthFilters.cpp
src/relay/TopNFilter.cpp
src/relay/TrackStatsFilter.cpp
src/relay/PropertyRanking.cpp
src/relay/CrossExecFilter.cpp
src/relay/CrossExecForwarderCallback.cpp
src/relay/WeakRelayForwarderCallback.cpp
src/relay/PublisherCrossExecFilter.cpp
src/relay/SubscriberCrossExecFilter.cpp
src/logging/LogSetup.cpp
)
target_include_directories(moqx_core
PUBLIC
${PROJECT_SOURCE_DIR}/src
)
target_link_libraries(moqx_core PUBLIC
moqx_cache
moqx_hmac_key
moxygen::moxygen_relay_moq_forwarder
moxygen::moxygen_moq_relay_session
moxygen::moxygen_moq_server
moxygen::moxygen_moq_qmux_server
moxygen::moxygen_qmux_utils
moxygen::openmoq_pico_evb_server_transport
proxygen::proxygenhttpserver
# Workaround: wangle::wangle_acceptor_acceptor_core uses AsyncFdSocket from
# FizzAcceptorHandshakeHelper but omits this dep from its cmake config.
Folly::folly_io_async_fdsock_async_fd_socket
moxygen::moxygen_moqclient
OpenSSL::Crypto
catapult
moxygen::moxygen_mlog_file_mlogger
moxygen::moxygen_mlog_mlogger_factory
moxygen::moxygen_mlog_sampling_mlogger_factory
mvfst::mvfst_logging_file_qlogger
)
target_compile_options(moqx_core PRIVATE -Wall -Wextra -Wpedantic)
# PUBLIC so dependents can include moqx/Version.h.
target_link_libraries(moqx_core PUBLIC moqx_version)
# --- Config types (resolved Config structs, header-only, no rfl dependency) ---
# Library consumers that only need the Config API link this.
add_library(moqx_config INTERFACE)
target_include_directories(moqx_config
INTERFACE
${PROJECT_SOURCE_DIR}/src
)
target_link_libraries(moqx_config INTERFACE
Folly::folly_network_address
Folly::folly_container_detail_f14_hash_detail
)
# --- Config loader (YAML parsing + validation + resolution + init) ---
# Application-level: ParsedConfig rfl structs, loadConfig(), resolveConfig(),
# handleConfigSubcommand(). Links rfl/yaml-cpp; consumers that only need
# resolved Config types can depend on moqx_config alone.
add_library(moqx_config_loader STATIC
src/config/Loader.cpp
src/config/ConfigResolver.cpp
src/config/ConfigInit.cpp
src/config/Pkcs12.cpp
)
target_include_directories(moqx_config_loader
PUBLIC
${PROJECT_SOURCE_DIR}/src
)
target_link_libraries(moqx_config_loader PUBLIC
moqx_config
reflectcpp
yaml-cpp
Folly::folly_file_util
)
# PKCS#12 transcode (Pkcs12.cpp) + OPENSSL_cleanse in ConfigResolver.cpp;
# folly cert utils supplies OpenSSLCertUtils::pemEncode.
target_link_libraries(moqx_config_loader PRIVATE
OpenSSL::Crypto
Folly::folly_ssl_openssl_cert_utils
)
target_compile_options(moqx_config_loader PRIVATE -Wall -Wextra -Wpedantic)
# --- Main executable ---
add_executable(moqx
src/main.cpp
)
if(MOQX_ENABLE_BPF_STEERING)
# QuicReuseportSteering.cpp defines mvfst_hook_on_socket_create, overriding
# the weak symbol in mvfst. It must live in the executable (not a static lib)
# so the linker always includes it without a --whole-archive trick.
target_sources(moqx PRIVATE src/bpf/QuicReuseportSteering.cpp)
target_compile_definitions(moqx PRIVATE MOQX_ENABLE_BPF_STEERING)
endif()
target_link_libraries(moqx PRIVATE moqx_core moqx_config_loader)
# --- CAT4MOQ token issuer (signing) library, shared by the CLI and tests ---
add_library(moqx_issuer_lib STATIC
src/auth/AuthTokenIssuer.cpp
)
target_include_directories(moqx_issuer_lib
PUBLIC
${PROJECT_SOURCE_DIR}/src
)
target_link_libraries(moqx_issuer_lib PUBLIC
moqx_hmac_key
moqx_config
catapult
moxygen::moxygen_moq_types
)
target_compile_options(moqx_issuer_lib PRIVATE -Wall -Wextra -Wpedantic)
# --- Standalone moqx-issuer CLI ---
add_executable(moqx-issuer
src/auth/IssuerMain.cpp
)
target_link_libraries(moqx-issuer PRIVATE
moqx_issuer_lib
moqx_config_loader
Folly::folly_init_init
Folly::folly_base64
Folly::folly_string
gflags
)
target_compile_options(moqx-issuer PRIVATE -Wall -Wextra -Wpedantic)
# --- Tests ---
if(MOQX_BUILD_TESTS)
enable_testing()
add_subdirectory(test)
endif()
if(MOQX_BUILD_BENCHMARKS)
add_subdirectory(benchmark)
endif()
include(${PROJECT_SOURCE_DIR}/cmake/Lint.cmake)
install(TARGETS moqx moqx-issuer moqx_core moqx_config_loader)
# Identifies an unpacked tarball without running the binary.
install(FILES ${CMAKE_BINARY_DIR}/VERSION DESTINATION .)