Project combining ESP-IDF and ESP-MDF examples not compiling

karunt
Posts: 76
Joined: Sat Apr 03, 2021 7:58 am

Project combining ESP-IDF and ESP-MDF examples not compiling

Postby karunt » Mon Jul 04, 2022 12:14 pm

Trying to use a esp-mdf example with esp-idf example. So my overall code relies on both esp-mdf and esp-idf components. However, when compiling my code, CMake throws the following error repeatedly and doesn't do anything else:
Component directory C:/Users/[Username]/ESP/esp-mdf/components/third_party does not contain a CMakeLists.txt file. No component will be added
ccache will be used for faster recompilation
Here are what my top level and project level CMakeLists.txt files look like:

Top level CMakeLists.txt:

Code: Select all

cmake_minimum_required(VERSION 3.5)
list(APPEND EXTRA_COMPONENT_DIRS "$ENV{IDF_PATH}/components" "$ENV{MDF_PATH}/components")
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
include($ENV{MDF_PATH}/project.cmake)
project(ble_and_wifimesh)
Project level CMakeLists.txt:

Code: Select all

idf_component_register(SRCS "main.c" "http.c" "spiffs.c" "wifi_mesh.c" "wifi_provision.c"
                    INCLUDE_DIRS "include"
                    PRIV_REQUIRES esp_http_client mwifi nvs_flash spiffs spi_flash tcp_transport wifi_provisioning)
My project directory (main) includes the following source files:
include/main.h
CMakeLists.txt
component.mk
http.c
kconfig.projbuild
main.c
spiffs.c
wifi_mesh.c
wifi_provision.c
wifi.c

I wouldn't have expected this to be an issue since not every directory in esp-mdf/components needs to have a cmakelists.txt file, right? So what is it that I'm doing incorrectly with my CMakeLists.txt files? I'm at a loss.

karunt
Posts: 76
Joined: Sat Apr 03, 2021 7:58 am

Re: Project combining ESP-IDF and ESP-MDF examples not compiling

Postby karunt » Thu Jul 07, 2022 9:23 pm

Figured a solution out to the issue described in the post. To integrate an ESP-MDF project into an ESP-MDF project, the top level CMakeLists.txt file needs to be modified as follows:

1. For some reason, ESP-IDF requires all folders inside the components folder (esp/esp-idf/components) to have a CMakeLists.txt file. This might have something to do with the project.cmake file in esp/esp-idf/tools/cmake, which is included in the top level CMakeLists.txt file.

Code: Select all

include($ENV{IDF_PATH}/tools/cmake/project.cmake)
)

This means that the third_party folder in the esp/esp-mdf/components folder will throw the error described above because it doesn't have its own CMakeLists.txt file. To remedy this situation, I moved the folders aliyun_sdk and miniz from third_party directly into to the components folder (ie, in esp/esp-mdf/components) and deleted folder third_party.

2. The top level CMakeLists.txt file in the esp-mdf example also calls for file project.cmake in folder esp/esp-mdf.

Code: Select all

include($ENV{MDF_PATH}/project.cmake)


This esp-mdf project.cmake file in turn calls for inclusion of file esp/esp-mdf/mdf_functions.cmake, which defines function mdf_get_git_revision().

Code: Select all

include($ENV{MDF_PATH}/mdf_functions.cmake)
mdf_get_git_revision()
So in my top level CMakeLists.txt file, I copied the above 2 lines of code (include($ENV{MDF_PATH}/mdf_functions.cmake) and
mdf_get_git_revision()).

3. In the top level CMakeLists.txt file, I also added the esp-mdf components folder to variable EXTRA_COMPONENT_DIRS:

Code: Select all

list(APPEND EXTRA_COMPONENT_DIRS "$ENV{IDF_PATH}/components" "$ENV{MDF_PATH}/components")
This is what my final top level CMakeLists.txt looks like and it seems to work well in integrating an esp-mdf example into an esp-idf project:

Code: Select all

cmake_minimum_required(VERSION 3.5)

list(APPEND EXTRA_COMPONENT_DIRS "$ENV{IDF_PATH}/components" "$ENV{MDF_PATH}/components")

include($ENV{IDF_PATH}/tools/cmake/project.cmake)
include($ENV{MDF_PATH}/mdf_functions.cmake)

mdf_get_git_revision()
project(epuzz)

Who is online

Users browsing this forum: No registered users and 118 guests