VScode CMake REQUIRES problem

accacca
Posts: 40
Joined: Mon Aug 06, 2018 4:59 pm

VScode CMake REQUIRES problem

Postby accacca » 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

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()     
....
.....           
and for requires

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)
.....
.....
and at the end

Code: Select all

idf_component_register(SRCS ${src}
                    INCLUDE_DIRS ${includes}
                    REQUIRES ${requires}  
....
....                                    
But if I add a managed component to requires list in conditional block like this

Code: Select all

if(CONFIG_ENABLE_IPFILTER_LIB)
  list(APPEND src "lib_ipfilter/lib_ipfilter.c" )
  list (APPEND requires espressif__esp_dns)  
endif()
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

Code: Select all

message ("${requires}")   
is identical and contains the name of the additional component.

thanks

MicroController
Posts: 2661
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: VScode CMake REQUIRES problem

Postby MicroController » Fri Apr 17, 2026 2:56 pm

Yeah, doesn't work this way (at least with the v1 build system). Basically, dependencies are collected first, then the CONFIG_...s from sdkconfig are processed; so the CONFIG_... settings cannot influence which dependencies are seen by cmake.

accacca
Posts: 40
Joined: Mon Aug 06, 2018 4:59 pm

Re: VScode CMake REQUIRES problem

Postby accacca » Wed Apr 22, 2026 8:16 am

Sorry for the late reply
I understand now, thanks for the explanation
So my idea of using a single Cmakefile to configure the libraries to include in the project, and just one REQUIRES myLIB statement in each project, won’t work
I’ll have to use a separate Cmakefile for each library and specify REQUIRES for each library I want to use within my project.

Who is online

Users browsing this forum: Baidu [Spider], PetalBot and 8 guests