From cf3227503b24201dadb99306357aa8c0b0349db3 Mon Sep 17 00:00:00 2001 From: Aron Rubin Date: Thu, 4 Mar 2021 23:00:21 -0500 Subject: [PATCH] Use more stable arduino detection methods (#38) * Use a more stable arduino detection macro. * Detection method for both IDF config phases. Newer IDF API and targets. --- CMakeLists.txt | 56 +++++++++++++++++++++++--------------------- src/NimBLEDevice.cpp | 4 ++-- 2 files changed, 31 insertions(+), 29 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 650f323..d84e132 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,9 +2,32 @@ # CMakeLists in this exact order for cmake to work correctly cmake_minimum_required(VERSION 3.5) -set(SUPPORTED_TARGETS esp32) +idf_build_get_property(__hack_component_targets __COMPONENT_TARGETS) -set(COMPONENT_SRCS +if("esp-nimble-component" IN_LIST BUILD_COMPONENTS OR "__esp-nimble-component" IN_LIST __hack_component_targets) + list(APPEND ESP_NIMBLE_PRIV_REQUIRES + esp-nimble-component + ) +elseif("nimble" IN_LIST BUILD_COMPONENTS OR "__nimble" IN_LIST __hack_component_targets) + list(APPEND ESP_NIMBLE_PRIV_REQUIRES + nimble + ) +endif() + +if("arduino" IN_LIST BUILD_COMPONENTS OR __hack_component_targets MATCHES "__idf_arduino") + list(APPEND ESP_NIMBLE_PRIV_REQUIRES + arduino + ) +endif() + +idf_component_register( + REQUIRED_IDF_TARGETS + "esp32" + "esp32s3" + "esp32c3" + INCLUDE_DIRS + "src" + SRCS "src/FreeRTOS.cpp" "src/NimBLE2904.cpp" "src/NimBLEAddress.cpp" @@ -27,31 +50,10 @@ set(COMPONENT_SRCS "src/NimBLEService.cpp" "src/NimBLEUtils.cpp" "src/NimBLEUUID.cpp" -) - -set(COMPONENT_ADD_INCLUDEDIRS - src -) - -set(COMPONENT_PRIV_REQUIRES - nvs_flash + REQUIRES bt + nvs_flash + PRIV_REQUIRES + ${ESP_NIMBLE_PRIV_REQUIRES} ) -if(COMPONENTS MATCHES "esp-nimble-component") - list(APPEND COMPONENT_PRIV_REQUIRES - esp-nimble-component - ) -elseif(COMPONENTS MATCHES "nimble") - list(APPEND COMPONENT_PRIV_REQUIRES - nimble - ) -endif() - -if(COMPONENTS MATCHES "arduino") - list(APPEND COMPONENT_PRIV_REQUIRES - arduino - ) -endif() - -register_component() diff --git a/src/NimBLEDevice.cpp b/src/NimBLEDevice.cpp index dc9caf3..66d952a 100644 --- a/src/NimBLEDevice.cpp +++ b/src/NimBLEDevice.cpp @@ -30,7 +30,7 @@ #include "services/gap/ble_svc_gap.h" #include "services/gatt/ble_svc_gatt.h" -#ifdef ARDUINO_ARCH_ESP32 +#ifdef CONFIG_ENABLE_ARDUINO_DEPENDS #include "esp32-hal-bt.h" #endif @@ -534,7 +534,7 @@ void NimBLEDevice::setScanFilterMode(uint8_t mode) { int rc=0; esp_err_t errRc = ESP_OK; -#ifdef ARDUINO_ARCH_ESP32 +#ifdef CONFIG_ENABLE_ARDUINO_DEPENDS // make sure the linker includes esp32-hal-bt.c so ardruino init doesn't release BLE memory. btStarted(); #endif