Repository navigation
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
292 lines (249 loc) · 12.3 KB
/
Copy pathCMakeLists.txt
File metadata and controls
292 lines (249 loc) · 12.3 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
# CMakeLists.txt for sendspin-cpp
# Supports both ESP-IDF component builds and standalone host builds
#
# Structure:
# cmake/sources.cmake - Source file definitions
# cmake/esp-idf.cmake - ESP-IDF specific configuration
# cmake/host.cmake - Host platform configuration
cmake_minimum_required(VERSION 3.16)
# ==============================================================================
# Build type detection
# ==============================================================================
if(DEFINED IDF_TARGET)
set(ESP_IDF_BUILD TRUE)
else()
set(ESP_IDF_BUILD FALSE)
endif()
# Set source directory variable for consistent use
if(ESP_IDF_BUILD)
set(SENDSPIN_COMPONENT_DIR ${COMPONENT_DIR})
else()
set(SENDSPIN_COMPONENT_DIR ${CMAKE_CURRENT_SOURCE_DIR})
endif()
# ==============================================================================
# Include CMake modules
# ==============================================================================
include(${SENDSPIN_COMPONENT_DIR}/cmake/sources.cmake)
# ==============================================================================
# ESP-IDF Build
# ==============================================================================
if(ESP_IDF_BUILD)
include(${SENDSPIN_COMPONENT_DIR}/cmake/esp-idf.cmake)
# Collect sources
sendspin_get_sources(${SENDSPIN_COMPONENT_DIR})
# Assemble source list from core + enabled roles (driven by Kconfig)
set(SENDSPIN_ALL_SOURCES ${SENDSPIN_CORE_SOURCES} ${SENDSPIN_ESP_SOURCES})
# REQUIRES cannot depend on CONFIG_ values: ESP-IDF collects them before sdkconfig is loaded.
# The codec components are required through the Kconfig rules in idf_component.yml instead.
set(SENDSPIN_REQUIRES esp_http_server esp_netif esp_timer esp_ringbuf esp_hw_support pthread mbedtls bblanchon__arduinojson esphome__noise-c)
set(SENDSPIN_COMPILE_DEFS "")
if(CONFIG_SENDSPIN_ENABLE_PLAYER)
list(APPEND SENDSPIN_ALL_SOURCES ${SENDSPIN_PLAYER_SOURCES})
list(APPEND SENDSPIN_COMPILE_DEFS SENDSPIN_ENABLE_PLAYER)
endif()
# CONFIG_SENDSPIN_ENABLE_OPUS exists only while the player or the source role is enabled
if(CONFIG_SENDSPIN_ENABLE_OPUS)
list(APPEND SENDSPIN_COMPILE_DEFS SENDSPIN_ENABLE_OPUS)
endif()
if(CONFIG_SENDSPIN_ENABLE_CONTROLLER)
list(APPEND SENDSPIN_ALL_SOURCES ${SENDSPIN_CONTROLLER_SOURCES})
list(APPEND SENDSPIN_COMPILE_DEFS SENDSPIN_ENABLE_CONTROLLER)
endif()
if(CONFIG_SENDSPIN_ENABLE_METADATA)
list(APPEND SENDSPIN_ALL_SOURCES ${SENDSPIN_METADATA_SOURCES})
list(APPEND SENDSPIN_COMPILE_DEFS SENDSPIN_ENABLE_METADATA)
endif()
if(CONFIG_SENDSPIN_ENABLE_COLOR)
list(APPEND SENDSPIN_ALL_SOURCES ${SENDSPIN_COLOR_SOURCES})
list(APPEND SENDSPIN_COMPILE_DEFS SENDSPIN_ENABLE_COLOR)
endif()
if(CONFIG_SENDSPIN_ENABLE_ARTWORK)
list(APPEND SENDSPIN_ALL_SOURCES ${SENDSPIN_ARTWORK_SOURCES})
list(APPEND SENDSPIN_COMPILE_DEFS SENDSPIN_ENABLE_ARTWORK)
endif()
if(CONFIG_SENDSPIN_ENABLE_VISUALIZER)
list(APPEND SENDSPIN_ALL_SOURCES ${SENDSPIN_VISUALIZER_SOURCES})
list(APPEND SENDSPIN_COMPILE_DEFS SENDSPIN_ENABLE_VISUALIZER)
endif()
if(CONFIG_SENDSPIN_ENABLE_SOURCE)
list(APPEND SENDSPIN_ALL_SOURCES ${SENDSPIN_SOURCE_SOURCES})
list(APPEND SENDSPIN_COMPILE_DEFS SENDSPIN_ENABLE_SOURCE)
if(CONFIG_SENDSPIN_ENABLE_OPUS)
list(APPEND SENDSPIN_ALL_SOURCES ${SENDSPIN_SOURCE_OPUS_SOURCES})
endif()
endif()
# Register the component using the assembled source list
# WHOLE_ARCHIVE: this component defines noise_rand_bytes() (src/esp/noise_rand.cpp), which the
# esphome__noise-c component references but does not define (it is built with
# NOISE_USE_CUSTOM_RAND=1). Because noise-c depends on sendspin-cpp and sendspin-cpp depends on
# noise-c, the link is circular; without --whole-archive the linker never pulls noise_rand.o
# from libsendspin-cpp.a (it is not referenced at the point that archive is scanned) and the
# link fails with "undefined reference to noise_rand_bytes". --gc-sections still strips genuinely
# unused sections, so this does not bloat the image.
idf_component_register(
SRCS ${SENDSPIN_ALL_SOURCES}
INCLUDE_DIRS "include"
PRIV_INCLUDE_DIRS "src" "src/esp" "src/crypto"
REQUIRES ${SENDSPIN_REQUIRES}
PRIV_REQUIRES espressif__esp_websocket_client
WHOLE_ARCHIVE
)
# Apply compile definitions for enabled roles
foreach(DEF ${SENDSPIN_COMPILE_DEFS})
target_compile_definitions(${COMPONENT_LIB} PUBLIC ${DEF})
endforeach()
# Apply ESP-IDF configuration
sendspin_configure_esp_idf(${COMPONENT_LIB} ${COMPONENT_DIR})
# Deferred to the end of configuration: noise-c and this component require each other, so its
# target may not exist yet when this file runs.
cmake_language(DEFER DIRECTORY ${CMAKE_SOURCE_DIR} CALL sendspin_enable_noise_name_tables)
# ==============================================================================
# Host Build
# ==============================================================================
else()
project(sendspin VERSION 0.1.0 LANGUAGES C CXX)
set(_sendspin_is_top_level OFF)
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
set(_sendspin_is_top_level ON)
endif()
# ccache keys compiles on content, so branch switches reuse earlier builds. Set before any
# target so the FetchContent dependencies are cached too.
option(SENDSPIN_USE_CCACHE "Compile through ccache when it is installed" ${_sendspin_is_top_level})
if(SENDSPIN_USE_CCACHE)
find_program(SENDSPIN_CCACHE_PROGRAM ccache)
if(SENDSPIN_CCACHE_PROGRAM)
foreach(_lang C CXX)
if(NOT DEFINED CMAKE_${_lang}_COMPILER_LAUNCHER)
set(CMAKE_${_lang}_COMPILER_LAUNCHER ${SENDSPIN_CCACHE_PROGRAM})
endif()
endforeach()
message(STATUS "Using ccache: ${SENDSPIN_CCACHE_PROGRAM}")
endif()
endif()
# Role selection options
option(SENDSPIN_ENABLE_PLAYER "Enable player role (audio decoding)" ON)
option(SENDSPIN_ENABLE_CONTROLLER "Enable controller role" ON)
option(SENDSPIN_ENABLE_METADATA "Enable metadata role" ON)
option(SENDSPIN_ENABLE_COLOR "Enable color role" ON)
option(SENDSPIN_ENABLE_ARTWORK "Enable artwork role" ON)
option(SENDSPIN_ENABLE_VISUALIZER "Enable visualizer role" ON)
option(SENDSPIN_ENABLE_SOURCE "Enable source role (audio capture)" ON)
# Codec selection for the player's decoder and the source's encoder. Opus is
# patent-encumbered; see the player and source role specs.
option(SENDSPIN_ENABLE_OPUS "Enable Opus in the player and source roles" ON)
# Plaintext trace of every protocol message (SendspinClientConfig::message_trace), for
# conformance tooling. Host only: the ESP-IDF build has no switch for it.
option(SENDSPIN_ENABLE_MESSAGE_TRACE "Enable the plaintext protocol message trace" OFF)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/host.cmake)
# Get sources
sendspin_get_sources(${CMAKE_CURRENT_SOURCE_DIR})
# Assemble source list from core + enabled roles
set(SENDSPIN_ALL_SOURCES ${SENDSPIN_CORE_SOURCES})
if(SENDSPIN_ENABLE_PLAYER)
list(APPEND SENDSPIN_ALL_SOURCES ${SENDSPIN_PLAYER_SOURCES})
endif()
if(SENDSPIN_ENABLE_CONTROLLER)
list(APPEND SENDSPIN_ALL_SOURCES ${SENDSPIN_CONTROLLER_SOURCES})
endif()
if(SENDSPIN_ENABLE_METADATA)
list(APPEND SENDSPIN_ALL_SOURCES ${SENDSPIN_METADATA_SOURCES})
endif()
if(SENDSPIN_ENABLE_COLOR)
list(APPEND SENDSPIN_ALL_SOURCES ${SENDSPIN_COLOR_SOURCES})
endif()
if(SENDSPIN_ENABLE_ARTWORK)
list(APPEND SENDSPIN_ALL_SOURCES ${SENDSPIN_ARTWORK_SOURCES})
endif()
if(SENDSPIN_ENABLE_VISUALIZER)
list(APPEND SENDSPIN_ALL_SOURCES ${SENDSPIN_VISUALIZER_SOURCES})
endif()
if(SENDSPIN_ENABLE_SOURCE)
list(APPEND SENDSPIN_ALL_SOURCES ${SENDSPIN_SOURCE_SOURCES})
if(SENDSPIN_ENABLE_OPUS)
list(APPEND SENDSPIN_ALL_SOURCES ${SENDSPIN_SOURCE_OPUS_SOURCES})
endif()
endif()
if(SENDSPIN_ENABLE_MESSAGE_TRACE)
list(APPEND SENDSPIN_ALL_SOURCES ${SENDSPIN_MESSAGE_TRACE_SOURCES})
endif()
# Create the library: core sources, enabled role sources, host networking (via host.cmake)
add_library(sendspin STATIC ${SENDSPIN_ALL_SOURCES})
# Add compile definitions for enabled roles
if(SENDSPIN_ENABLE_PLAYER)
target_compile_definitions(sendspin PUBLIC SENDSPIN_ENABLE_PLAYER)
endif()
if(SENDSPIN_ENABLE_OPUS AND (SENDSPIN_ENABLE_PLAYER OR SENDSPIN_ENABLE_SOURCE))
target_compile_definitions(sendspin PUBLIC SENDSPIN_ENABLE_OPUS)
endif()
if(SENDSPIN_ENABLE_CONTROLLER)
target_compile_definitions(sendspin PUBLIC SENDSPIN_ENABLE_CONTROLLER)
endif()
if(SENDSPIN_ENABLE_METADATA)
target_compile_definitions(sendspin PUBLIC SENDSPIN_ENABLE_METADATA)
endif()
if(SENDSPIN_ENABLE_COLOR)
target_compile_definitions(sendspin PUBLIC SENDSPIN_ENABLE_COLOR)
endif()
if(SENDSPIN_ENABLE_ARTWORK)
target_compile_definitions(sendspin PUBLIC SENDSPIN_ENABLE_ARTWORK)
endif()
if(SENDSPIN_ENABLE_VISUALIZER)
target_compile_definitions(sendspin PUBLIC SENDSPIN_ENABLE_VISUALIZER)
endif()
if(SENDSPIN_ENABLE_SOURCE)
target_compile_definitions(sendspin PUBLIC SENDSPIN_ENABLE_SOURCE)
endif()
if(SENDSPIN_ENABLE_MESSAGE_TRACE)
target_compile_definitions(sendspin PUBLIC SENDSPIN_ENABLE_MESSAGE_TRACE)
endif()
# Host build options
option(ENABLE_WERROR "Treat warnings as errors" OFF)
option(ENABLE_SANITIZERS "Enable AddressSanitizer and UndefinedBehaviorSanitizer" OFF)
# ThreadSanitizer is a separate option because it cannot be combined with ASan/UBSan. The
# concurrency tests (e.g. RecordStoreConcurrency) only detect a data race when built this way.
option(ENABLE_TSAN "Enable ThreadSanitizer (mutually exclusive with ENABLE_SANITIZERS)" OFF)
if(ENABLE_TSAN AND ENABLE_SANITIZERS)
message(FATAL_ERROR "ENABLE_TSAN and ENABLE_SANITIZERS are mutually exclusive")
endif()
# ThreadSanitizer is applied globally rather than per target, and before the FetchContent
# dependencies are declared, so IXWebSocket, GoogleTest and the codecs are instrumented too.
# TSan intercepts pthread calls in uninstrumented code but cannot see its std::atomic
# accesses, which reports the lock-free stop flags in IXWebSocket as false races.
if(ENABLE_TSAN)
string(APPEND CMAKE_C_FLAGS " -fsanitize=thread -fno-omit-frame-pointer -g")
string(APPEND CMAKE_CXX_FLAGS " -fsanitize=thread -fno-omit-frame-pointer -g")
string(APPEND CMAKE_EXE_LINKER_FLAGS " -fsanitize=thread")
string(APPEND CMAKE_SHARED_LINKER_FLAGS " -fsanitize=thread")
string(APPEND CMAKE_MODULE_LINKER_FLAGS " -fsanitize=thread")
endif()
# Examples build by default for standalone development, but not when sendspin is pulled into
# a larger project via add_subdirectory (where the consumer doesn't want the example deps,
# e.g. FTXUI). Override either way with -DBUILD_EXAMPLES=ON/OFF.
option(BUILD_EXAMPLES "Build host examples" ${_sendspin_is_top_level})
# Apply host configuration
sendspin_configure_host(sendspin ${CMAKE_CURRENT_SOURCE_DIR})
# Examples
if(BUILD_EXAMPLES)
add_subdirectory(examples/basic_client)
# tui_client parses its options with POSIX getopt(), which Windows lacks
if(NOT WIN32)
add_subdirectory(examples/tui_client)
else()
message(STATUS "Skipping tui_client example (POSIX-only)")
endif()
# source_client demonstrates only the source role, so the whole target is gated on it
if(SENDSPIN_ENABLE_SOURCE)
add_subdirectory(examples/source_client)
else()
message(STATUS "Skipping source_client example (SENDSPIN_ENABLE_SOURCE=OFF)")
endif()
else()
message(STATUS "Skipping sendspin-cpp examples (BUILD_EXAMPLES=OFF)")
endif()
# Unit tests (host only, opt-in via -DSENDSPIN_BUILD_TESTS=ON)
option(SENDSPIN_BUILD_TESTS "Build host unit tests" OFF)
if(SENDSPIN_BUILD_TESTS)
enable_testing()
add_subdirectory(tests)
endif()
endif()