forked from feelfreelinux/bell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
204 lines (190 loc) · 8.33 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
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
cmake_minimum_required(VERSION 2.8.12)
project(bell)
# Configurable options
option(BELL_DISABLE_CODECS "Disable the entire audio codec wrapper" OFF)
option(BELL_CODEC_AAC "Support libhelix-aac codec" ON)
option(BELL_CODEC_MP3 "Support libhelix-mp3 codec" ON)
option(BELL_CODEC_VORBIS "Support tremor Vorbis codec" ON)
option(BELL_CODEC_OPUS "Support Opus codec" ON)
option(BELL_DISABLE_SINKS "Disable all built-in audio sink implementations" OFF)
# These are default OFF, as they're OS-dependent (ESP32 sinks are always enabled - no external deps)
option(BELL_SINK_ALSA "Enable ALSA audio sink" OFF)
option(BELL_SINK_PORTAUDIO "Enable PortAudio sink" OFF)
# cJSON wrapper
option(BELL_DISABLE_CJSON "Disable cJSON and JSONObject completely" OFF)
set(BELL_EXTERNAL_CJSON "" CACHE STRING "External cJSON library target name, optional")
# Backwards compatibility with deprecated options
if(BELL_EXTERNAL_TREMOR)
message(WARNING "Deprecated Bell options used, replace BELL_EXTERNAL_TREMOR with BELL_CODEC_VORBIS=OFF")
set(BELL_CODEC_VORBIS OFF)
endif()
if(BELL_USE_ALSA)
message(WARNING "Deprecated Bell options used, replace BELL_USE_ALSA with BELL_SINK_ALSA")
set(BELL_SINK_ALSA ${BELL_USE_ALSA})
endif()
if(BELL_USE_PORTAUDIO)
message(WARNING "Deprecated Bell options used, replace BELL_USE_PORTAUDIO with BELL_SINK_PORTAUDIO")
set(BELL_SINK_PORTAUDIO ${BELL_USE_PORTAUDIO})
endif()
message(STATUS "Bell options:")
message(STATUS " Disable all codecs: ${BELL_DISABLE_CODECS}")
if(NOT BELL_DISABLE_CODECS)
message(STATUS " - AAC audio codec: ${BELL_CODEC_AAC}")
message(STATUS " - MP3 audio codec: ${BELL_CODEC_MP3}")
message(STATUS " - Vorbis audio codec: ${BELL_CODEC_VORBIS}")
message(STATUS " - Opus audio codec: ${BELL_CODEC_OPUS}")
endif()
message(STATUS " Disable built-in audio sinks: ${BELL_DISABLE_SINKS}")
if(NOT BELL_DISABLE_SINKS)
message(STATUS " - ALSA sink: ${BELL_SINK_ALSA}")
message(STATUS " - PortAudio sink: ${BELL_SINK_PORTAUDIO}")
endif()
message(STATUS " Disable cJSON and JSONObject: ${BELL_DISABLE_CJSON}")
# Include nanoPB library
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/nanopb/extra")
find_package(Nanopb REQUIRED)
list(APPEND EXTRA_INCLUDES ${NANOPB_INCLUDE_DIRS})
# CMake options
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
set(AUDIO_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src/audio")
add_definitions("-DUSE_DEFAULT_STDLIB=1")
# Main library sources
file(GLOB SOURCES "src/*.cpp" "src/*.c" "nanopb/*.c" "src/audio/container/*.cpp")
list(APPEND EXTRA_INCLUDES "include/platform")
list(APPEND EXTRA_INCLUDES "include/audio/container")
# Add platform specific sources
if(ESP_PLATFORM)
file(GLOB ESP_PLATFORM_SOURCES "src/platform/esp/*.cpp" "src/platform/esp/*.c" "src/asm/biquad_f32_ae32.S")
list(APPEND SOURCES ${ESP_PLATFORM_SOURCES})
endif()
if(UNIX)
file(GLOB UNIX_PLATFORM_SOURCES "src/platform/unix/*.cpp" "src/platform/linux/TLSSocket.cpp" "src/platform/unix/*.c")
list(APPEND SOURCES ${UNIX_PLATFORM_SOURCES})
endif()
if(APPLE)
file(GLOB APPLE_PLATFORM_SOURCES "src/platform/apple/*.cpp" "src/platform/linux/TLSSocket.cpp" "src/platform/apple/*.c")
list(APPEND SOURCES ${APPLE_PLATFORM_SOURCES})
endif()
if(UNIX AND NOT APPLE)
file(GLOB LINUX_PLATFORM_SOURCES "src/platform/linux/*.cpp" "src/platform/linux/*.c")
list(APPEND SOURCES ${LINUX_PLATFORM_SOURCES})
endif()
# A hack to make Opus keep quiet
function(message)
if(NOT MESSAGE_QUIET)
_message(${ARGN})
endif()
endfunction()
if(ESP_PLATFORM)
# Use MBedTLS on ESP32
list(REMOVE_ITEM SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/CryptoOpenSSL.cpp")
idf_build_set_property(COMPILE_DEFINITIONS "-DBELL_USE_MBEDTLS" APPEND)
list(APPEND EXTRA_LIBS idf::mbedtls idf::pthread idf::mdns)
add_definitions(-Wunused-const-variable -Wchar-subscripts -Wunused-label -Wmaybe-uninitialized -Wmisleading-indentation)
else()
# Use OpenSSL elsewhere
list(REMOVE_ITEM SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/CryptoMbedTLS.cpp")
find_package(OpenSSL REQUIRED)
find_package(Threads REQUIRED)
set(THREADS_PREFER_PTHREAD_FLAG ON)
if(OPENSSL_FOUND)
set(OPENSSL_USE_STATIC_LIBS TRUE)
endif()
list(APPEND EXTRA_LIBS OpenSSL::Crypto OpenSSL::SSL Threads::Threads)
endif()
if(NOT BELL_DISABLE_CODECS)
list(APPEND SOURCES "${AUDIO_DIR}/codec/DecoderGlobals.cpp")
list(APPEND SOURCES "${AUDIO_DIR}/codec/BaseCodec.cpp")
list(APPEND SOURCES "${AUDIO_DIR}/codec/AudioCodecs.cpp")
list(APPEND EXTRA_INCLUDES "include/audio/codec")
# AAC-LC codec
if(BELL_CODEC_AAC)
file(GLOB LIBHELIX_AAC_SOURCES "libhelix-aac/*.c")
list(APPEND LIBHELIX_SOURCES ${LIBHELIX_AAC_SOURCES})
list(APPEND EXTRA_INCLUDES "libhelix-aac")
list(APPEND SOURCES "${AUDIO_DIR}/codec/AACDecoder.cpp")
list(APPEND CODEC_FLAGS "-DBELL_CODEC_AAC")
endif()
# MP3 codec
if(BELL_CODEC_MP3)
file(GLOB LIBHELIX_MP3_SOURCES "libhelix-mp3/*.c")
list(APPEND LIBHELIX_SOURCES ${LIBHELIX_MP3_SOURCES})
list(APPEND EXTRA_INCLUDES "libhelix-mp3")
list(APPEND SOURCES "${AUDIO_DIR}/codec/MP3Decoder.cpp")
list(APPEND CODEC_FLAGS "-DBELL_CODEC_MP3")
endif()
# libhelix Cygwin workaround
if(CYGWIN)
# Both Cygwin and ESP are Unix-like so this seems to work (or, at least, compile)
set_source_files_properties("${AUDIO_DIR}/codec/DecoderGlobals.cpp" ${LIBHELIX_SOURCES} PROPERTIES COMPILE_FLAGS "-DESP_PLATFORM")
endif()
list(APPEND SOURCES ${LIBHELIX_SOURCES})
# Vorbis codec
if(BELL_CODEC_VORBIS)
file(GLOB TREMOR_SOURCES "tremor/*.c")
list(REMOVE_ITEM TREMOR_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/tremor/ivorbisfile_example.c")
list(APPEND SOURCES ${TREMOR_SOURCES})
list(APPEND EXTRA_INCLUDES "tremor")
list(APPEND SOURCES "${AUDIO_DIR}/codec/VorbisDecoder.cpp")
list(APPEND CODEC_FLAGS "-DBELL_CODEC_VORBIS")
endif()
# Opus codec
if(BELL_CODEC_OPUS)
set(OPUS_INSTALL_CMAKE_CONFIG_MODULE OFF CACHE BOOL "")
set(OPUS_INSTALL_CMAKE_CONFIG_MODULE OFF)
set(OPUS_INSTALL_PKG_CONFIG_MODULE OFF CACHE BOOL "")
set(OPUS_INSTALL_PKG_CONFIG_MODULE OFF)
set(MESSAGE_QUIET ON)
add_subdirectory("opus")
unset(MESSAGE_QUIET)
target_compile_options(opus PRIVATE "-O3")
list(APPEND EXTRA_LIBS Opus::opus)
list(APPEND SOURCES "${AUDIO_DIR}/codec/OPUSDecoder.cpp")
list(APPEND CODEC_FLAGS -DBELL_CODEC_OPUS)
endif()
# Enable global codecs
string(REPLACE ";" " " CODEC_FLAGS "${CODEC_FLAGS}")
set_source_files_properties("${AUDIO_DIR}/codec/AudioCodecs.cpp" PROPERTIES COMPILE_FLAGS "${CODEC_FLAGS}")
endif()
if(NOT BELL_DISABLE_SINKS)
set(PLATFORM "unix")
if(ESP_PLATFORM)
set(PLATFORM "esp")
endif()
# Add all built-in audio sinks
file(GLOB SINK_SOURCES "${AUDIO_DIR}/sinks/${PLATFORM}/*.cpp" "${AUDIO_DIR}/sinks/${PLATFORM}/*.c")
list(APPEND EXTRA_INCLUDES "include/audio/sinks/${PLATFORM}")
# Find ALSA if required, else remove the sink
if(BELL_SINK_ALSA)
find_package(ALSA REQUIRED)
list(APPEND EXTRA_INCLUDES ${ALSA_INCLUDE_DIRS})
list(APPEND EXTRA_LIBS ${ALSA_LIBRARIES})
else()
list(REMOVE_ITEM SINK_SOURCES "${AUDIO_DIR}/sinks/unix/ALSAAudioSink.cpp")
endif()
# Find PortAudio if required, else remove the sink
if(BELL_SINK_PORTAUDIO)
find_package(portaudio REQUIRED)
list(APPEND EXTRA_INCLUDES ${PORTAUDIO_INCLUDE_DIRS})
list(APPEND EXTRA_LIBS ${PORTAUDIO_LIBRARIES})
else()
list(REMOVE_ITEM SINK_SOURCES "${AUDIO_DIR}/sinks/unix/PortAudioSink.cpp")
endif()
list(APPEND SOURCES ${SINK_SOURCES})
endif()
if(BELL_DISABLE_CJSON)
list(REMOVE_ITEM SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/JSONObject.cpp")
else()
if(BELL_EXTERNAL_CJSON)
list(APPEND EXTRA_LIBS ${BELL_EXTERNAL_CJSON})
else()
list(APPEND SOURCES "cJSON/cJSON.c")
list(APPEND EXTRA_INCLUDES "cJSON")
endif()
endif()
add_library(bell STATIC ${SOURCES})
# PUBLIC to propagate esp-idf includes to bell dependents
target_link_libraries(bell PUBLIC ${EXTRA_LIBS})
target_include_directories(bell PUBLIC "include" ${EXTRA_INCLUDES} ${CMAKE_CURRENT_BINARY_DIR})
target_compile_definitions(bell PUBLIC PB_ENABLE_MALLOC)