CMakeLists.txt 3.7 KB

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