123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258 |
- cmake_minimum_required(VERSION 2.8.12)
- cmake_policy(SET CMP0077 NEW)
- 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_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")
- 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_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")
- find_package(Nanopb REQUIRED)
- list(APPEND EXTRA_INCLUDES ${NANOPB_INCLUDE_DIRS})
- # CMake options
- 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/unix/*.c")
- list(APPEND SOURCES ${UNIX_PLATFORM_SOURCES})
- endif()
- if(APPLE)
- 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)
- list(APPEND EXTRA_LIBS idf::mbedtls idf::pthread idf::mdns)
- add_definitions(-Wunused-const-variable -Wchar-subscripts -Wunused-label -Wmaybe-uninitialized -Wmisleading-indentation)
- else()
- 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(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("${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)
- 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)
- 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 "${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)
- if(WIN32)
- target_compile_definitions(bell PUBLIC PB_NO_STATIC_ASSERT)
- endif()
|