From a4e085f71a77f1a212db5acfd768dcb127362bf7 Mon Sep 17 00:00:00 2001 From: h2zero Date: Fri, 15 Jan 2021 19:56:06 -0700 Subject: [PATCH] Fix compilation when using CMake. * Update readme to include note about compiling with Arduino component. --- CMakeLists.txt | 73 ++++++++++++++++++++++++++++++++++---------------- README.md | 5 ++++ 2 files changed, 55 insertions(+), 23 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 80dd3f1..df4576c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,26 +4,53 @@ cmake_minimum_required(VERSION 3.5) set(SUPPORTED_TARGETS esp32) -idf_component_register(SRCS "src/FreeRTOS.cpp" - "src/NimBLE2904.cpp" - "src/NimBLEAddress.cpp" - "src/NimBLEAdvertisedDevice.cpp" - "src/NimBLEAdvertising.cpp" - "src/NimBLEBeacon.cpp" - "src/NimBLECharacteristic.cpp" - "src/NimBLEClient.cpp" - "src/NimBLEDescriptor.cpp" - "src/NimBLEDevice.cpp" - "src/NimBLEEddystoneTLM.cpp" - "src/NimBLEEddystoneURL.cpp" - "src/NimBLERemoteCharacteristic.cpp" - "src/NimBLERemoteDescriptor.cpp" - "src/NimBLERemoteService.cpp" - "src/NimBLEScan.cpp" - "src/NimBLESecurity.cpp" - "src/NimBLEServer.cpp" - "src/NimBLEService.cpp" - "src/NimBLEUtils.cpp" - "src/NimBLEUUID.cpp" - INCLUDE_DIRS "src" - REQUIRES bt) +set(COMPONENT_SRCS + "src/FreeRTOS.cpp" + "src/NimBLE2904.cpp" + "src/NimBLEAddress.cpp" + "src/NimBLEAdvertisedDevice.cpp" + "src/NimBLEAdvertising.cpp" + "src/NimBLEBeacon.cpp" + "src/NimBLECharacteristic.cpp" + "src/NimBLEClient.cpp" + "src/NimBLEDescriptor.cpp" + "src/NimBLEDevice.cpp" + "src/NimBLEEddystoneTLM.cpp" + "src/NimBLEEddystoneURL.cpp" + "src/NimBLERemoteCharacteristic.cpp" + "src/NimBLERemoteDescriptor.cpp" + "src/NimBLERemoteService.cpp" + "src/NimBLEScan.cpp" + "src/NimBLESecurity.cpp" + "src/NimBLEServer.cpp" + "src/NimBLEService.cpp" + "src/NimBLEUtils.cpp" + "src/NimBLEUUID.cpp" +) + +set(COMPONENT_ADD_INCLUDEDIRS + src +) + +set(COMPONENT_PRIV_REQUIRES + nvs_flash + bt +) + +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/README.md b/README.md index 10189d8..d88c933 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,11 @@ Also see [Improvements_and_updates](docs/Improvements_and_updates.md) for inform [Full API documentation and class list can be found here.](https://h2zero.github.io/esp-nimble-cpp/)
+## Using with Arduino as an IDF component and CMake +When using this library along with Arduino and compiling with *CMake* you must add `add_compile_definitions(ARDUINO_ARCH_ESP32=1)` +in your project/CMakeLists.txt after the line `include($ENV{IDF_PATH}/tools/cmake/project.cmake)` to prevent Arduino from releasing BLE memory. +
+ # Acknowledgments * [nkolban](https://github.com/nkolban) and [chegewara](https://github.com/chegewara) for the [original esp32 BLE library](https://github.com/nkolban/esp32-snippets/tree/master/cpp_utils) this project was derived from. * [beegee-tokyo](https://github.com/beegee-tokyo) for contributing your time to test/debug and contributing the beacon examples.