Page 1 of 1

idf_component register conditionals

Posted: Sat Nov 22, 2025 7:33 pm
by william.basser
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

Re: idf_component register conditionals

Posted: Mon Nov 24, 2025 1:08 am
by nopnop2002

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")

Re: idf_component register conditionals

Posted: Mon Nov 24, 2025 1:54 am
by ok-home

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