mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2025-12-11 22:17:17 +03:00
update cspot
This commit is contained in:
@@ -4,79 +4,205 @@ cmake_policy(SET CMP0077 NEW)
|
||||
project(bell)
|
||||
|
||||
# Configurable options
|
||||
option(BELL_DISABLE_CODECS "Disable libhelix AAC and MP3 codecs" OFF)
|
||||
option(BELL_DISABLE_SINKS "Disable built-in audio sink implementations" OFF)
|
||||
option(BELL_USE_ALSA "Enable ALSA sink" OFF)
|
||||
option(BELL_USE_PORTAUDIO "Enable PortAudio sink" OFF)
|
||||
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_ALAC "Support Apple ALAC 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")
|
||||
set(BELL_EXTERNAL_TREMOR "" CACHE STRING "External tremor library target name, optional")
|
||||
|
||||
if(BELL_EXTERNAL_MBEDTLS)
|
||||
set(MbedTLS_DIR ${BELL_EXTERNAL_MBEDTLS})
|
||||
message(STATUS "Setting local mbedtls ${MbedTLS_DIR}")
|
||||
endif()
|
||||
|
||||
# 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}")
|
||||
message(STATUS " - ALAC audio codec: ${BELL_CODEC_ALAC}")
|
||||
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)
|
||||
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)
|
||||
add_definitions(-DUSE_DEFAULT_STDLIB=1)
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
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")
|
||||
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")
|
||||
file(GLOB UNIX_PLATFORM_SOURCES "src/platform/unix/*.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")
|
||||
file(GLOB APPLE_PLATFORM_SOURCES "src/platform/apple/*.cpp" "src/platform/apple/*.c")
|
||||
list(APPEND SOURCES ${APPLE_PLATFORM_SOURCES})
|
||||
list(APPEND EXTRA_INCLUDES "/usr/local/opt/mbedtls@3/include")
|
||||
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()
|
||||
if(WIN32)
|
||||
file(GLOB WIN32_PLATFORM_SOURCES "src/platform/win32/*.cpp" "src/platform/win32/*.c")
|
||||
list(APPEND SOURCES ${WIN32_PLATFORM_SOURCES})
|
||||
list(APPEND EXTRA_INCLUDES "include/platform/win32")
|
||||
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)
|
||||
find_package(Threads REQUIRED)
|
||||
set(THREADS_PREFER_PTHREAD_FLAG ON)
|
||||
list(APPEND EXTRA_LIBS Threads::Threads)
|
||||
|
||||
find_package(MbedTLS REQUIRED)
|
||||
get_target_property(MBEDTLS_INFO MbedTLS::mbedtls INTERFACE_INCLUDE_DIRECTORIES)
|
||||
list(APPEND EXTRA_INCLUDES ${MBEDTLS_INFO})
|
||||
|
||||
# try to handle mbedtls when not system-wide installed
|
||||
if(BELL_EXTERNAL_MBEDTLS)
|
||||
if(MSVC)
|
||||
set(MBEDTLS_RELEASE "RELEASE" CACHE STRING "local mbedtls version")
|
||||
else()
|
||||
set(MBEDTLS_RELEASE "NOCONFIG" CACHE STRING "local mbedtls version")
|
||||
endif()
|
||||
message(STATUS "using local mbedtls version ${MBEDTLS_RELEASE}")
|
||||
get_target_property(MBEDTLS_INFO MbedTLS::mbedtls IMPORTED_LOCATION_${MBEDTLS_RELEASE})
|
||||
list(APPEND EXTRA_LIBS ${MBEDTLS_INFO})
|
||||
get_target_property(MBEDTLS_INFO MbedTLS::mbedx509 IMPORTED_LOCATION_${MBEDTLS_RELEASE})
|
||||
list(APPEND EXTRA_LIBS ${MBEDTLS_INFO})
|
||||
get_target_property(MBEDTLS_INFO MbedTLS::mbedcrypto IMPORTED_LOCATION_${MBEDTLS_RELEASE})
|
||||
list(APPEND EXTRA_LIBS ${MBEDTLS_INFO})
|
||||
else()
|
||||
list(APPEND EXTRA_LIBS mbedtls mbedcrypto mbedx509)
|
||||
endif()
|
||||
|
||||
if(MSVC)
|
||||
add_compile_definitions(NOMINMAX _CRT_SECURE_NO_WARNINGS)
|
||||
add_definitions(/wd4068 /wd4244 /wd4018 /wd4101 /wd4102 /wd4142)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(BELL_DISABLE_CODECS)
|
||||
list(REMOVE_ITEM SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/DecoderGlobals.cpp)
|
||||
else()
|
||||
file(GLOB LIBHELIX_AAC_SOURCES "libhelix-aac/*.c")
|
||||
file(GLOB LIBHELIX_MP3_SOURCES "libhelix-mp3/*.c")
|
||||
list(APPEND EXTRA_INCLUDES "libhelix-aac" "libhelix-mp3")
|
||||
list(APPEND SOURCES ${LIBHELIX_MP3_SOURCES} ${LIBHELIX_AAC_SOURCES})
|
||||
if(NOT BELL_DISABLE_CODECS)
|
||||
file(GLOB EXTRA_SOURCES "src/audio/container/*.cpp")
|
||||
list(APPEND SOURCES "${EXTRA_SOURCES}")
|
||||
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()
|
||||
|
||||
# MP3 codec
|
||||
if(BELL_CODEC_ALAC)
|
||||
file(GLOB ALAC_SOURCES "alac/*.c" "alac/*.cpp")
|
||||
list(APPEND ALAC_SOURCES ${ALAC_SOURCES})
|
||||
list(APPEND EXTRA_INCLUDES "alac")
|
||||
# list(APPEND SOURCES "${AUDIO_DIR}/codec/ALACDecoder.cpp")
|
||||
list(APPEND CODEC_FLAGS "-DBELL_CODEC_ALAC")
|
||||
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(src/DecoderGlobals.cpp PROPERTIES COMPILE_FLAGS -DESP_PLATFORM)
|
||||
set_source_files_properties(${LIBHELIX_AAC_SOURCES} PROPERTIES COMPILE_FLAGS -DESP_PLATFORM)
|
||||
set_source_files_properties(${LIBHELIX_MP3_SOURCES} PROPERTIES COMPILE_FLAGS -DESP_PLATFORM)
|
||||
set_source_files_properties("${AUDIO_DIR}/codec/DecoderGlobals.cpp" ${LIBHELIX_SOURCES} PROPERTIES COMPILE_FLAGS "-DESP_PLATFORM")
|
||||
endif()
|
||||
list(APPEND SOURCES ${LIBHELIX_SOURCES})
|
||||
list(APPEND SOURCES ${ALAC_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}")
|
||||
elseif(BELL_EXTERNAL_TREMOR)
|
||||
list(APPEND EXTRA_LIBS ${BELL_EXTERNAL_TREMOR})
|
||||
endif()
|
||||
|
||||
if(NOT BELL_DISABLE_SINKS)
|
||||
@@ -85,45 +211,52 @@ if(NOT BELL_DISABLE_SINKS)
|
||||
set(PLATFORM "esp")
|
||||
endif()
|
||||
# Add all built-in audio sinks
|
||||
file(GLOB SINK_SOURCES "src/sinks/${PLATFORM}/*.cpp" "src/sinks/${PLATFORM}/*.c")
|
||||
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_USE_ALSA)
|
||||
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 ${CMAKE_CURRENT_SOURCE_DIR}/src/sinks/unix/ALSAAudioSink.cpp)
|
||||
list(REMOVE_ITEM SINK_SOURCES "${AUDIO_DIR}/sinks/unix/ALSAAudioSink.cpp")
|
||||
endif()
|
||||
# Find PortAudio if required, else remove the sink
|
||||
if(BELL_USE_PORTAUDIO)
|
||||
find_package(portaudio REQUIRED)
|
||||
list(APPEND EXTRA_INCLUDES ${PORTAUDIO_INCLUDE_DIRS})
|
||||
list(APPEND EXTRA_LIBS ${PORTAUDIO_LIBRARIES})
|
||||
if(BELL_SINK_PORTAUDIO)
|
||||
if(WIN32)
|
||||
list(APPEND EXTRA_INCLUDES "portaudio/include")
|
||||
if(NOT "${CMAKE_GENERATOR}" MATCHES "(Win64|IA64)")
|
||||
list(APPEND EXTRA_LIBS "${CMAKE_CURRENT_SOURCE_DIR}/portaudio/portaudio_win32.lib")
|
||||
else()
|
||||
list(APPEND EXTRA_LIBS "${CMAKE_CURRENT_SOURCE_DIR}/portaudio/portaudio_x64.lib")
|
||||
endif()
|
||||
else()
|
||||
find_package(portaudio REQUIRED)
|
||||
list(APPEND EXTRA_INCLUDES ${PORTAUDIO_INCLUDE_DIRS})
|
||||
list(APPEND EXTRA_LIBS ${PORTAUDIO_LIBRARIES})
|
||||
endif()
|
||||
else()
|
||||
list(REMOVE_ITEM SINK_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/sinks/unix/PortAudioSink.cpp)
|
||||
list(REMOVE_ITEM SINK_SOURCES "${AUDIO_DIR}/sinks/unix/PortAudioSink.cpp")
|
||||
endif()
|
||||
list(APPEND SOURCES ${SINK_SOURCES})
|
||||
list(APPEND EXTRA_INCLUDES "include/sinks/${PLATFORM}")
|
||||
endif()
|
||||
|
||||
if(BELL_EXTERNAL_CJSON)
|
||||
list(APPEND EXTRA_LIBS ${BELL_EXTERNAL_CJSON})
|
||||
if(BELL_DISABLE_CJSON)
|
||||
list(REMOVE_ITEM SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/JSONObject.cpp")
|
||||
else()
|
||||
list(APPEND EXTRA_INCLUDES "cJSON")
|
||||
list(APPEND SOURCES "cJSON/cJSON.c")
|
||||
endif()
|
||||
|
||||
if(BELL_EXTERNAL_TREMOR)
|
||||
list(APPEND EXTRA_LIBS ${BELL_EXTERNAL_TREMOR})
|
||||
else()
|
||||
file(GLOB TREMOR_SOURCES "tremor/*.c")
|
||||
list(REMOVE_ITEM TREMOR_SOURCES "tremor/ivorbisfile_example.c")
|
||||
list(APPEND EXTRA_INCLUDES "tremor")
|
||||
list(APPEND SOURCES ${TREMOR_SOURCES})
|
||||
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" "include/platform" ${EXTRA_INCLUDES} ${CMAKE_CURRENT_BINARY_DIR})
|
||||
target_include_directories(bell PUBLIC "include" ${EXTRA_INCLUDES} ${CMAKE_CURRENT_BINARY_DIR})
|
||||
target_compile_definitions(bell PUBLIC PB_ENABLE_MALLOC)
|
||||
if(WIN32)
|
||||
target_compile_definitions(bell PUBLIC PB_NO_STATIC_ASSERT)
|
||||
endif()
|
||||
|
||||
Reference in New Issue
Block a user