espressif / esp-azure

SDK to connect ESP8266 and ESP32 to Microsoft Azure IoT services
177 stars 93 forks source link

How to use esp-azure from a component (not as a component)? #73

Closed jubueche closed 4 years ago

jubueche commented 4 years ago

Hi,

I am trying to use a component, which requires including some files from esp-azure.

main/main.cpp:

#include "esp_log.h"
#include "iothub_message.h"
#include "upload_to_blob_block.h"

const char * TAG_MAIN = "Chaze-Main";

extern "C" void app_main()
{
    ESP_LOGI(TAG_MAIN, "This is the main function");
}

main/CMakeLists.txt:

idf_component_register(SRCS "main.cpp"
                    INCLUDE_DIRS "."
                    REQUIRES upload_to_blob)

component_compile_definitions(SET_TRUSTED_CERT_IN_SAMPLES)

CMakeLists.txt:

# The following lines of boilerplate have to be in your project's
# CMakeLists in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.5)

include($ENV{IDF_PATH}/tools/cmake/project.cmake)
set (EXTRA_COMPONENT_DIRS "$ENV{ESP_PATH}/esp-azure/port")
project(chaze-esp32)

Q: Can all the components include the files in the extra component, or do I have to register that for every component that tries to use it?

components/upload_to_blob/CMakeLists.txt:

idf_component_register(SRCS "upload_to_blob_block.c"
                       INCLUDE_DIRS "include")

In main.cpp, #include "iothub_message.h" succeeds, but not #include "upload_to_blob_block.h"

The reason seems to be that upload_to_blob_block.c can not find the include files. I know that the required components, included in .c files must be listes in PRIV_REQUIRES, but how do I reference esp-azure, if it is not in my components directory?

This is the output when trying to compile it:

CMake Error at /home/julianbuchel2/esp/esp-idf/tools/cmake/component.cmake:283 (message):
  Include directory '/esp-azure/port' is not a directory.
Call Stack (most recent call first):
  /home/julianbuchel2/esp/esp-idf/tools/cmake/component.cmake:447 (__component_add_include_dirs)
  components/upload_to_blob/CMakeLists.txt:1 (idf_component_register)

-- Configuring incomplete, errors occurred!
See also "/home/julianbuchel2/Documents/chaze-esp32/build/CMakeFiles/CMakeOutput.log".
FAILED: build.ninja 
/usr/bin/cmake -H/home/julianbuchel2/Documents/chaze-esp32 -B/home/julianbuchel2/Documents/chaze-esp32/build
ninja: error: rebuilding 'build.ninja': subcommand failed
ninja failed with exit code 1
jubueche commented 4 years ago

Just saw that it is this issue.