VScode CMake REQUIRES problem
Posted: Fri Apr 17, 2026 8:47 am
I would like to write a CMake file to compile some of my libraries, including only the necessary libraries as specified by the project configuration.
Some of these libraries require additional managed components that are only used if the library is included in the project.
My CMake file generates a list of sources and a list of requirements to be included, which are then used in `idf_component_register`.
For example
and for requires
and at the end
But if I add a managed component to requires list in conditional block like this
If I include the " list (APPEND requires....)" statement inside the conditional compilation `if` statement, the additional component is not found and the compilation ends in an error.
I must move the list (APPEND requires espressif__esp_dns) outside of the "if" statement in order to successfully compile the project
I don’t understand why this happens. In both cases, the list of requirements printed with
is identical and contains the name of the additional component.
thanks
Some of these libraries require additional managed components that are only used if the library is included in the project.
My CMake file generates a list of sources and a list of requirements to be included, which are then used in `idf_component_register`.
For example
Code: Select all
set(src "lib_config/lib_config.c")
list(APPEND src "lib_sockets/lib_sockets.c"
"lib_sockets/lib_phy_socket.c" )
if (CONFIG_ENABLE_LITTLEFS_LIB)
list(APPEND src "lib_littlefs/lib_littlefs.c" )
endif()
....
.....
Code: Select all
set(requires json vfs sdmmc fatfs spiffs nvs_flash)
list (APPEND requires esp_wifi wpa_supplicant lwip wifi_provisioning)
list (APPEND requires esp_event esp_psram)
.....
.....
Code: Select all
idf_component_register(SRCS ${src}
INCLUDE_DIRS ${includes}
REQUIRES ${requires}
....
....
Code: Select all
if(CONFIG_ENABLE_IPFILTER_LIB)
list(APPEND src "lib_ipfilter/lib_ipfilter.c" )
list (APPEND requires espressif__esp_dns)
endif()
I must move the list (APPEND requires espressif__esp_dns) outside of the "if" statement in order to successfully compile the project
I don’t understand why this happens. In both cases, the list of requirements printed with
Code: Select all
message ("${requires}") thanks