update cmake files

This commit is contained in:
philippe44
2022-09-22 16:42:22 -07:00
parent 34fa7203be
commit f84e856e68
3 changed files with 49 additions and 25 deletions

View File

@@ -12,8 +12,11 @@ add_definitions(-DBELL_USE_MBEDTLS)
add_definitions(-Wno-unused-variable -Wno-unused-const-variable -Wchar-subscripts -Wunused-label -Wmaybe-uninitialized -Wmisleading-indentation)
set(BELL_DISABLE_CODECS ON)
set(BELL_EXTERNAL_TREMOR "idf::codecs")
set(BELL_EXTERNAL_CJSON "idf::json")
set(BELL_DISABLE_SINKS ON)
set(CSPOT_TARGET_ESP32 ON)
# becase CMake is so broken, the cache set below overrides a normal "set" for the first build
set(BELL_EXTERNAL_TREMOR "idf::codecs" CACHE STRING "provide own codecs")
set(BELL_EXTERNAL_CJSON "idf::json" CACHE STRING "provide own CJSON")
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/cspot ${CMAKE_CURRENT_BINARY_DIR}/cspot)
target_link_libraries(${COMPONENT_LIB} PRIVATE cspot ${EXTRA_REQ_LIBS})

View File

@@ -25,26 +25,17 @@ if(UNIX AND NOT APPLE)
# TODO: migrate from this to native linux mDNS
endif()
if (GENERATE_PROTOS)
file(GLOB SOURCES "src/*.cpp" "src/*.c")
set(NANOPB_OPTIONS "-I${CMAKE_CURRENT_SOURCE_DIR}")
set(PROTOS protobuf/authentication.proto protobuf/mercury.proto protobuf/keyexchange.proto protobuf/spirc.proto protobuf/metadata.proto)
message(${PROTOS})
message("building protobuf")
message(${CMAKE_CURRENT_SOURCE_DIR})
nanopb_generate_cpp(PROTO_SRCS PROTO_HDRS RELPATH ${CMAKE_CURRENT_SOURCE_DIR} ${PROTOS})
add_custom_target(generate_proto_sources DEPENDS ${PROTO_SRCS} ${PROTO_HDRS})
set_source_files_properties(${PROTO_SRCS} ${PROTO_HDRS} PROPERTIES GENERATED TRUE)
set(GENERATED_INCLUDES ${CMAKE_CURRENT_BINARY_DIR})
else()
file(GLOB SOURCES "src/*.cpp" "src/*.c" "protobuf/*.c")
message("BEWARE => NOT GENERATING PROTOBUF")
set(GENERATED_INCLUDES ".")
endif()
# Build protobuf code
set(NANOPB_OPTIONS "-I${CMAKE_CURRENT_SOURCE_DIR}")
file(GLOB PROTOS protobuf/*.proto)
nanopb_generate_cpp(PROTO_SRCS PROTO_HDRS RELPATH ${CMAKE_CURRENT_SOURCE_DIR} ${PROTOS})
add_custom_target(generate_proto_sources DEPENDS ${PROTO_SRCS} ${PROTO_HDRS})
set_source_files_properties(${PROTO_SRCS} ${PROTO_HDRS}
PROPERTIES GENERATED TRUE)
add_library(cspot STATIC ${SOURCES} ${PROTO_SRCS})
# PUBLIC to propagate includes from bell to cspot dependents
target_compile_definitions(bell PUBLIC PB_ENABLE_MALLOC)
target_compile_definitions(bell PUBLIC PB_FIELD_32BIT)
target_link_libraries(cspot PUBLIC ${EXTRA_LIBS})
target_include_directories(cspot PUBLIC "include" ${GENERATED_INCLUDES} ${NANOPB_INCLUDE_DIRS})
target_include_directories(cspot PUBLIC "include" ${CMAKE_CURRENT_BINARY_DIR} ${NANOPB_INCLUDE_DIRS})

View File

@@ -1,19 +1,24 @@
cmake_minimum_required(VERSION 2.8.12)
cmake_policy(SET CMP0077 NEW)
project(bell)
# Configurable options
option(BELL_DISABLE_CODECS "Disable libhelix AAC and MP3 codecs" 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")
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)
set(BELL_EXTERNAL_CJSON "" CACHE STRING "External cJSON library target name, optional")
set(BELL_EXTERNAL_TREMOR "" CACHE STRING "External tremor library target name, optional")
# Include nanoPB library
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/nanopb/extra)
find_package(Nanopb REQUIRED)
include_directories(${NANOPB_INCLUDE_DIRS})
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)
# Main library sources
@@ -74,6 +79,33 @@ else()
endif()
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 "src/sinks/${PLATFORM}/*.cpp" "src/sinks/${PLATFORM}/*.c")
# Find ALSA if required, else remove the sink
if(BELL_USE_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)
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})
else()
list(REMOVE_ITEM SINK_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/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})
else()
@@ -91,9 +123,7 @@ else()
endif()
add_library(bell STATIC ${SOURCES})
message(${NANOPB_INCLUDE_DIRS})
# 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_include_directories(bell PUBLIC "include" "include/platform" ${EXTRA_INCLUDES} ${CMAKE_CURRENT_BINARY_DIR})
target_compile_definitions(bell PUBLIC PB_ENABLE_MALLOC)