CMake 和 ESP-IDF:创建自定义组件

CMake and ESP-IDF: Creating custom components

框架:

ESP-IDF v4.3.1 - Eclipse 插件

具有 1 个活动组件的项目(我的计划是添加 ble 扫描、mqtt 消息传递和 wifi 访问)

IDF_PATH:        C:\Users\username\source\esp-idf-v4.3.1\
IDF_TOOLS_PATH:  C:\Users\username\.espressif

目标: 为 ESP-IDF 中的自定义组件添加 MQTT 功能

问题:

../components/mqtt/include/mqtt.h:24:10: fatal error: mqtt_client.h: No such file or directory
 #include "mqtt_client.h"

项目目录内容:

/components/mqtt/CMakeLists.txt 的内容:

idf_component_register(SRCS "mqtt.c"
                        INCLUDE_DIRS "include"
                        REQUIRES mqtt esp-tls)

我按照此处 ESP-IDF 文档的指示将 mqtt 和 esp-tls 所需组件添加到 CMakeLists.txt 文件:https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/build-system.html#idf-component-commands

尝试修复 1 我修复此代码的第一次尝试是将 /components/mqtt/CMakeLists.txt 的内容更新为 直接引用 所需的包含文件:

idf_component_register(SRCS 
                        "mqtt.c"
                        "C:/Users/user/source/esp-idf-v4.3.1/components/mqtt/esp-mqtt/mqtt_client.c"
                        "C:/Users/user/source/esp-idf-v4.3.1/components/esp-mqtt/lib/mqtt_msg.c"
                        "C:/Users/user/source/esp-idf-v4.3.1/components/esp-mqtt/lib/mqtt_outbox.c"
                        "C:/Users/user/source/esp-idf-v4.3.1/components/esp-mqtt/lib/platform_esp32_idf.c"
                    INCLUDE_DIRS 
                        "include"
                        "C:/Users/user/source/esp-idf-v4.3.1/components/mqtt/esp-mqtt/include" 
                        "C:/Users/user/source/esp-idf-v4.3.1/components/esp-tls"
                        "C:/Users/user/source/esp-idf-v4.3.1/components/mbedtls/mbedtls/include"
                        "C:/Users/user/source/esp-idf-v4.3.1/components/mbedtls/port/include"
                        "C:/Users/user/source/esp-idf-v4.3.1/components/tcp_transport/include"
                        "C:/Users/user/source/esp-idf-v4.3.1/components/nghttp/port/include"
                    PRIV_INCLUDE_DIRS "C:/Users/user/source/esp-idf-v4.3.1/components/mqtt/esp-mqtt/lib/include" 
                    REQUIRES lwip nghttp mbedtls)

这可以构建,但是必须有更好的方法来构建 mqtt 组件。谁能帮我修改 CMakeLists.txt 文件以正确拉入 esp-idf mqtt 组件?

您有命名冲突。您正在尝试创建一个名为 mqtt 的自定义组件,它需要名为 mqtt 的系统组件,并且您希望构建系统能够解决这个问题。那是自找麻烦:)

将您的组件命名为 myproject-mqtt 或其他名称。注意您的组件 wifible.

是否存在类似问题