idf_component register conditionals

william.basser
Posts: 2
Joined: Fri Sep 19, 2025 2:08 pm

idf_component register conditionals

Postby william.basser » Sat Nov 22, 2025 7:33 pm

Is there a way to add a conditional REQUIRES statement in a idf_components_register statement in CMakeLists.txt using a configuration declaration.

in CMakeLists.txt the following statement exists
idf_component_register(SRCS "LedManager.c"
REQUIRES LibGpio LibTypes CommandLineInterface
INCLUDE_DIRS "include")

I would like to make the CommandLineInterface requirement a conditional based on a configuration parameter
CONFIG_LEDMANAGER_ENABLE_DEBUG_COMMANDS

nopnop2002
Posts: 347
Joined: Thu Oct 03, 2019 10:52 pm
Contact:

Re: idf_component register conditionals

Postby nopnop2002 » Mon Nov 24, 2025 1:08 am

Code: Select all

set(reqs "LibGpio LibTypes")

if(CONFIG_LEDMANAGER_ENABLE_DEBUG_COMMANDS)
	list(APPEND reqs "CommandLineInterface")
endif()

idf_component_register(SRCS "LedManager.c"
REQUIRES "${reqs}"
INCLUDE_DIRS "include")

User avatar
ok-home
Posts: 157
Joined: Sun May 02, 2021 7:23 pm
Location: Russia Novosibirsk
Contact:

Re: idf_component register conditionals

Postby ok-home » Mon Nov 24, 2025 1:54 am

Code: Select all

set(reqs "LibGpio LibTypes")

if(CONFIG_LEDMANAGER_ENABLE_DEBUG_COMMANDS)
	list(APPEND reqs "CommandLineInterface")
endif()

idf_component_register(SRCS "LedManager.c"
REQUIRES "${reqs}"
INCLUDE_DIRS "include")
Unfortunately, this is not possible in the current build system.
https://docs.espressif.com/projects/es ... uirements
The values of REQUIRES and PRIV_REQUIRES should not depend on any configuration options (CONFIG_xxx macros). This is because requirements are expanded before the configuration is loaded. Other component variables (like include paths or source files) can depend on configuration options.
Build system v2 is currently being tested, where this limitation has been removed.
https://docs.espressif.com/projects/es ... .html#id9

Who is online

Users browsing this forum: DuckDuckGo [Bot] and 2 guests