cmake_minimum_required(VERSION 3.5)
# Set the path to the additional component directory
set(EXTRA_COMPONENT_DIRS $ENV{IDF_PATH}/components/esp_netif)
# Include the project configuration file
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
# Set the project name
project(13_3_internet_connection)
# Add include directories for the required components
include_directories(
C:/Espressif/frameworks/esp-idf-v5.0.1/components/esp_netif/include
)
I was trying to add esp_netif library in esp-idf project's cmake file.
CMake Error at CMakeLists.txt:13 (target_include_directories):
Cannot specify include directories for target "esp_netif" which is not
built by this project.
-- Configuring incomplete, errors occurred!
See also "C:/Users/Umair/Documents/GitHub/esp32-course/_13_Internet_Connection/v4.3/13_3_internet_connection/build/CMakeFiles/CMakeOutput.log".
FAILED: build.ninja
C:\Espressif\tools\cmake\3.24.0\bin\cmake.exe --regenerate-during-build -SC:\Users\Umair\Documents\GitHub\esp32-course\_13_Internet_Connection\v4.3\13_3_internet_connection -BC:\Users\Umair\Documents\GitHub\esp32-course\_13_Internet_Connection\v4.3\13_3_internet_connection\build
ninja: error: rebuilding 'build.ninja': subcommand failed
ninja failed with exit code 1, output of the command is in the c:\users\umair\documents\github\esp32-course\_13_internet_connection\v4.3\13_3_internet_connection\build\log\idf_py_stderr_output_3136 and c:\users\umair\documents\github\esp32-course\_13_internet_connection\v4.3\13_3_internet_connection\build\log\idf_py_stdout_output_3136
I am not able to add esp_netif libray in my project.
Leave the top level CMakeLists.txt
be, it only declares some global project stuff. The developer usually adds their code to a component named main
and consequently that's where you need to add dependencies: statement idf_component_register()
in the main/CMakeLists.txt
file.
Modifying the minimal example from ESP IDF documentation to include the component named "esp_netif" as an explicit requirement to "main":
# File main/CMakeLists.txt
idf_component_register(SRCS "foo.c" "bar.c"
INCLUDE_DIRS "include"
REQUIRES esp_netif)
Do not add any CMake statements to update paths or pull in sub-projects. The ESP IDF build system does all that automatically. You only need to know the name of the component, which is esp_netif
.