forked from Sendspin/sendspin-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
194 lines (159 loc) · 7.06 KB
/
Copy pathCMakeLists.txt
File metadata and controls
194 lines (159 loc) · 7.06 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
# 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})
set(SENDSPIN_REQUIRES esp_http_server esp_netif esp_timer esp_ringbuf pthread mbedtls bblanchon__arduinojson)
set(SENDSPIN_COMPILE_DEFS "")
if(CONFIG_SENDSPIN_ENABLE_PLAYER)
list(APPEND SENDSPIN_ALL_SOURCES ${SENDSPIN_PLAYER_SOURCES})
list(APPEND SENDSPIN_REQUIRES esphome__micro-flac esphome__micro-opus)
list(APPEND SENDSPIN_COMPILE_DEFS SENDSPIN_ENABLE_PLAYER)
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()
# Register the component — uses assembled source list
idf_component_register(
SRCS ${SENDSPIN_ALL_SOURCES}
INCLUDE_DIRS "include"
PRIV_INCLUDE_DIRS "src" "src/esp"
REQUIRES ${SENDSPIN_REQUIRES}
PRIV_REQUIRES espressif__esp_websocket_client
)
# 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})
# ==============================================================================
# Host Build
# ==============================================================================
else()
project(sendspin VERSION 0.1.0 LANGUAGES CXX)
# 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)
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()
# Create the library — core sources + enabled role sources + host networking (added 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_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()
# Host build options
option(ENABLE_WERROR "Treat warnings as errors" OFF)
option(ENABLE_SANITIZERS "Enable AddressSanitizer and UndefinedBehaviorSanitizer" OFF)
# 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.
set(_sendspin_is_top_level OFF)
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
set(_sendspin_is_top_level ON)
endif()
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)
add_subdirectory(examples/tui_client)
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()