CMakeLists.txt 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. cmake_minimum_required(VERSION 2.8.12)
  2. project(bell)
  3. # Configurable options
  4. option(BELL_DISABLE_CODECS "Disable libhelix AAC and MP3 codecs" OFF)
  5. #set(BELL_EXTERNAL_CJSON "" CACHE STRING "External cJSON library target name, optional")
  6. #set(BELL_EXTERNAL_TREMOR "" CACHE STRING "External tremor library target name, optional")
  7. # Include nanoPB library
  8. set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/nanopb/extra)
  9. find_package(Nanopb REQUIRED)
  10. include_directories(${NANOPB_INCLUDE_DIRS})
  11. # CMake options
  12. set(CMAKE_CXX_STANDARD 17)
  13. add_definitions(-DUSE_DEFAULT_STDLIB=1)
  14. # Main library sources
  15. file(GLOB SOURCES "src/*.cpp" "src/*.c" "nanopb/*.c")
  16. # Add platform specific sources
  17. if(ESP_PLATFORM)
  18. file(GLOB ESP_PLATFORM_SOURCES "src/platform/esp/*.cpp" "src/platform/esp/*.c" "src/asm/biquad_f32_ae32.S")
  19. list(APPEND SOURCES ${ESP_PLATFORM_SOURCES})
  20. endif()
  21. if(UNIX)
  22. file(GLOB UNIX_PLATFORM_SOURCES "src/platform/unix/*.cpp" "src/platform/linux/TLSSocket.cpp" "src/platform/unix/*.c")
  23. list(APPEND SOURCES ${UNIX_PLATFORM_SOURCES})
  24. endif()
  25. if(APPLE)
  26. file(GLOB APPLE_PLATFORM_SOURCES "src/platform/apple/*.cpp" "src/platform/linux/TLSSocket.cpp" "src/platform/apple/*.c")
  27. list(APPEND SOURCES ${APPLE_PLATFORM_SOURCES})
  28. endif()
  29. if(UNIX AND NOT APPLE)
  30. file(GLOB LINUX_PLATFORM_SOURCES "src/platform/linux/*.cpp" "src/platform/linux/*.c")
  31. list(APPEND SOURCES ${LINUX_PLATFORM_SOURCES})
  32. endif()
  33. if(ESP_PLATFORM)
  34. # Use MBedTLS on ESP32
  35. list(REMOVE_ITEM SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/CryptoOpenSSL.cpp)
  36. idf_build_set_property(COMPILE_DEFINITIONS "-DBELL_USE_MBEDTLS" APPEND)
  37. list(APPEND EXTRA_LIBS idf::mbedtls idf::pthread idf::mdns)
  38. add_definitions(-Wunused-const-variable -Wchar-subscripts -Wunused-label -Wmaybe-uninitialized -Wmisleading-indentation)
  39. else()
  40. # Use OpenSSL elsewhere
  41. list(REMOVE_ITEM SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/CryptoMbedTLS.cpp)
  42. find_package(OpenSSL REQUIRED)
  43. find_package(Threads REQUIRED)
  44. set(THREADS_PREFER_PTHREAD_FLAG ON)
  45. if(OPENSSL_FOUND)
  46. set(OPENSSL_USE_STATIC_LIBS TRUE)
  47. endif()
  48. list(APPEND EXTRA_LIBS OpenSSL::Crypto OpenSSL::SSL Threads::Threads)
  49. endif()
  50. if(BELL_DISABLE_CODECS)
  51. list(REMOVE_ITEM SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/DecoderGlobals.cpp)
  52. else()
  53. file(GLOB LIBHELIX_AAC_SOURCES "libhelix-aac/*.c")
  54. file(GLOB LIBHELIX_MP3_SOURCES "libhelix-mp3/*.c")
  55. list(APPEND EXTRA_INCLUDES "libhelix-aac" "libhelix-mp3")
  56. list(APPEND SOURCES ${LIBHELIX_MP3_SOURCES} ${LIBHELIX_AAC_SOURCES})
  57. if(CYGWIN)
  58. # Both Cygwin and ESP are Unix-like so this seems to work (or, at least, compile)
  59. set_source_files_properties(src/DecoderGlobals.cpp PROPERTIES COMPILE_FLAGS -DESP_PLATFORM)
  60. set_source_files_properties(${LIBHELIX_AAC_SOURCES} PROPERTIES COMPILE_FLAGS -DESP_PLATFORM)
  61. set_source_files_properties(${LIBHELIX_MP3_SOURCES} PROPERTIES COMPILE_FLAGS -DESP_PLATFORM)
  62. endif()
  63. endif()
  64. if(BELL_EXTERNAL_CJSON)
  65. list(APPEND EXTRA_LIBS ${BELL_EXTERNAL_CJSON})
  66. else()
  67. list(APPEND EXTRA_INCLUDES "cJSON")
  68. list(APPEND SOURCES "cJSON/cJSON.c")
  69. endif()
  70. if(BELL_EXTERNAL_TREMOR)
  71. list(APPEND EXTRA_LIBS ${BELL_EXTERNAL_TREMOR})
  72. else()
  73. file(GLOB TREMOR_SOURCES "tremor/*.c")
  74. list(REMOVE_ITEM TREMOR_SOURCES "tremor/ivorbisfile_example.c")
  75. list(APPEND EXTRA_INCLUDES "tremor")
  76. list(APPEND SOURCES ${TREMOR_SOURCES})
  77. endif()
  78. add_library(bell STATIC ${SOURCES})
  79. message(${NANOPB_INCLUDE_DIRS})
  80. # PUBLIC to propagate esp-idf includes to bell dependents
  81. target_link_libraries(bell PUBLIC ${EXTRA_LIBS})
  82. target_include_directories(bell PUBLIC "include" ${EXTRA_INCLUDES} ${CMAKE_CURRENT_BINARY_DIR})
  83. target_compile_definitions(bell PUBLIC PB_ENABLE_MALLOC)