From 33214079d7f223807297f0643bc9cfd5733667e0 Mon Sep 17 00:00:00 2001 From: pschatzmann Date: Thu, 20 Jun 2024 14:03:55 +0200 Subject: [PATCH] IDF as component --- CMakeLists.txt | 85 +++++++++++++++++++++++++++++--------------------- 1 file changed, 50 insertions(+), 35 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fc503d05d..ce7fcb143 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,50 +1,65 @@ cmake_minimum_required(VERSION 3.16) -# set the project name -project(arduino-audio-tools) +if (DEFINED ESP_PLATFORM) -set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0") -set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0") -set(FETCHCONTENT_UPDATES_DISCONNECTED ON) -add_compile_options(-Wno-deprecated-declarations) + # idf component + idf_component_register( + SRC_DIRS src + INCLUDE_DIRS src + REQUIRES bt esp_common freertos hal log nvs_flash driver + ) -include(FetchContent) + target_compile_options(${COMPONENT_LIB} PUBLIC -DESP32_CMAKE=1 -Wno-error -Wno-format -fpermissive) -add_library(arduino-audio-tools INTERFACE) +else() -option(BUILD_SHARED_LIBS "Build using shared libraries" OFF) -option(ADD_PORTAUDIO "Add Portaudio Library" ON) -option(ADD_ARDUINO_EMULATOR "Add Arduino Emulator Library" ON) + # set the project name + project(arduino-audio-tools) + + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0") + set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0") + set(FETCHCONTENT_UPDATES_DISCONNECTED ON) + add_compile_options(-Wno-deprecated-declarations) + + include(FetchContent) + + add_library(arduino-audio-tools INTERFACE) + + option(BUILD_SHARED_LIBS "Build using shared libraries" OFF) + option(ADD_PORTAUDIO "Add Portaudio Library" ON) + option(ADD_ARDUINO_EMULATOR "Add Arduino Emulator Library" ON) -# make include directory available to calling projects -target_include_directories (arduino-audio-tools INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/src) + # make include directory available to calling projects + target_include_directories (arduino-audio-tools INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/src) -# installation of all header files -install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/src/" # source directory - DESTINATION "include/arduino-audio-tools" # target directory - FILES_MATCHING # install only matched files - PATTERN "*.h" # select header files -) + # installation of all header files + install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/src/" # source directory + DESTINATION "include/arduino-audio-tools" # target directory + FILES_MATCHING # install only matched files + PATTERN "*.h" # select header files + ) -if (ADD_PORTAUDIO) - add_compile_options(-DIS_DESKTOP) - # Add Portaduio for desktop build - FetchContent_Declare(portaudio GIT_REPOSITORY "https://github.com/PortAudio/portaudio.git" GIT_TAG v19.7.0 ) - FetchContent_GetProperties(portaudio) - if(NOT portaudio_POPULATED) - FetchContent_Populate(portaudio) - add_subdirectory(${portaudio_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}/portaudio) + if (ADD_PORTAUDIO) + add_compile_options(-DIS_DESKTOP) + # Add Portaduio for desktop build + FetchContent_Declare(portaudio GIT_REPOSITORY "https://github.com/PortAudio/portaudio.git" GIT_TAG v19.7.0 ) + FetchContent_GetProperties(portaudio) + if(NOT portaudio_POPULATED) + FetchContent_Populate(portaudio) + add_subdirectory(${portaudio_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}/portaudio) + endif() endif() -endif() -if (ADD_ARDUINO_EMULATOR) - # Build with Linux Arduino Emulator - FetchContent_Declare(arduino_emulator GIT_REPOSITORY "https://github.com/pschatzmann/Arduino-Emulator.git" GIT_TAG main ) - FetchContent_GetProperties(arduino_emulator) - if(NOT arduino_emulator_POPULATED) - FetchContent_Populate(arduino_emulator) - add_subdirectory(${arduino_emulator_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}/emulator) + if (ADD_ARDUINO_EMULATOR) + # Build with Linux Arduino Emulator + FetchContent_Declare(arduino_emulator GIT_REPOSITORY "https://github.com/pschatzmann/Arduino-Emulator.git" GIT_TAG main ) + FetchContent_GetProperties(arduino_emulator) + if(NOT arduino_emulator_POPULATED) + FetchContent_Populate(arduino_emulator) + add_subdirectory(${arduino_emulator_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}/emulator) + endif() endif() + endif()