Page 1 of 1
problem with CmakeLists.txt conditional configuration
Posted: Fri Dec 11, 2020 5:26 am
by champonthis
I am just trying to following this guide
https://docs.espressif.com/projects/esp ... figuration
But my settings are always ignored and building always results in else() case with "componentE"
my CmakeLists.txt of my compoonent to configure
Code: Select all
set(priv_requires "componentA" "componentB" )
if(CONFIG_OPTION_1)
list(APPEND priv_requires "componentC")
elseif(CONFIG_OPTION_2)
list(APPEND priv_requires "componentD")
else()
list(APPEND priv_requires "componentE")
endif()
idf_component_register(
SRCS ...
INCLUDE_DIRS ...
PRIV_REQUIRES ${priv_requires}
)
And I have a Kconfig.projbuild with
Code: Select all
menu "Component Choose"
choice OPTION_CHOOSE
prompt "Choose device"
default OPTION_1
config OPTION_1
bool "option1"
config OPTION_2
bool "option2"
endchoice
endmenu
this is currently in my main folder, but I also put this in components "Kconfig.projbuild" and also just in "Kconfig" file all with same result
So what I am missing here. CONFIG_OPTION_1 and CONFIG_OPTION_2 always are ignored in my CmakeLists.txt
Re: problem with CmakeLists.txt conditional configuration
Posted: Fri Dec 11, 2020 11:10 am
by boarchuz
elseif(CONFIG_OPTION_1)
CONFIG_OPTION_2?
Full clean and rebuild?
What relevant definitions do you see in sdkconfig.h?
Re: problem with CmakeLists.txt conditional configuration
Posted: Fri Dec 11, 2020 4:47 pm
by champonthis
This was just typo, because I adopted my code. Did try everything like fullclean etc. In sdkconfig.h options are set correct. They are also correct in code like if I do like #ifdef CONFIG_OPTION_1 etc. But like said, in the CmakeLists.txt it get not applied. Do I have to set somewhere to include the sdkconfig?
Re: problem with CmakeLists.txt conditional configuration
Posted: Wed Dec 16, 2020 9:23 am
by champonthis
I added now some output in CmakeLists.txt
Code: Select all
set(priv_requires "componentA" "componentB")
if(CONFIG_DEMO_OPTION1)
list(APPEND priv_requires "componentC")
elseif(CONFIG_DEMO_OPTION2)
list(APPEND priv_requires "componentD")
endif()
message(STATUS "Option 1 : ${CONFIG_DEMO_OPTION1}")
message(STATUS "Option 2 : ${CONFIG_DEMO_OPTION2}")
message(STATUS "PRIV_REQUIRES : ${priv_requires}")
idf_component_register(
SRCS
INCLUDE_DIRS "."
PRIV_REQUIRES ${priv_requires}
)
on building I get the following
-- Building ESP-IDF components for target esp32
-- Option 1 :
-- Option 2 :
-- PRIV_REQUIRES : componentA;componentB
-- Project sdkconfig file ../sdkconfig
-- App "esp-ena-device" version: 45444bb-dirty
-- Adding linker script ../esp-idf/components/esp_rom/esp32/ld/esp32.rom.newlib-time.ld
-- Adding linker script ../esp-idf/components/esp_rom/esp32/ld/esp32.rom.api.ld
-- Adding linker script ../esp-idf/components/esp_rom/esp32/ld/esp32.rom.ld
-- Adding linker script ../esp-idf/components/esp_rom/esp32/ld/esp32.rom.libgcc.ld
-- Adding linker script ../esp-idf/components/esp_rom/esp32/ld/esp32.rom.newlib-data.ld
-- Adding linker script ../esp-idf/components/esp_rom/esp32/ld/esp32.rom.syscalls.ld
-- Adding linker script ../esp-idf/components/esp_rom/esp32/ld/esp32.rom.newlib-funcs.ld
-- Adding linker script ../build/esp-idf/esp32/esp32_out.ld
-- Adding linker script ../esp-idf/components/esp32/ld/esp32.project.ld.in
-- Adding linker script ../esp-idf/components/esp32/ld/esp32.peripherals.ld
-- Option 1 : y
-- Option 2 :
-- PRIV_REQUIRES : componentA;componentB;componentC
So the cmake is called without and with Sdkconfig. On building, only first, without is applied, so "componentC/D" is always missing.
How can I solve this?
Re: problem with CmakeLists.txt conditional configuration
Posted: Wed Dec 16, 2020 9:51 am
by champonthis
Okay, I found now the hint in documentation:
The values of REQUIRES and PRIV_REQUIRES should not depend on any configuration choices (CONFIG_xxx macros). This is because requirements are expanded before configuration is loaded. Other component variables (like include paths or source files) can depend on configuration choices.
Re: problem with CmakeLists.txt conditional configuration
Posted: Wed Dec 15, 2021 8:58 pm
by ricardoquesada
ahhh.... thanks. I was triggering this bug and was not sure why it was not working for me.
So, what's the best way to solve this?
e.g: I want to depend on a certain component (e.g: "arduino") only if certain features gets enabled in Kconfig?
Re: problem with CmakeLists.txt conditional configuration
Posted: Mon Jul 25, 2022 9:23 am
by FlorianR
Hi,
I would like to know that too
Re: problem with CmakeLists.txt conditional configuration
Posted: Sun Dec 31, 2023 12:01 am
by dernasherbrezon
You can conditionally enable no-op sources. For example:
Code: Select all
set(wifi_srcs "")
if(CONFIG_AT_WIFI_ENABLED)
list(APPEND wifi_srcs "at_wifi.c")
else()
list(APPEND wifi_srcs "at_no_wifi.c")
endif()
esp-idf won't link not used components.
idf.py size-components can help with troubleshooting.