problem with CmakeLists.txt conditional configuration

champonthis
Posts: 4
Joined: Fri Dec 11, 2020 5:20 am

problem with CmakeLists.txt conditional configuration

Postby champonthis » Fri Dec 11, 2020 5:26 am

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
Last edited by champonthis on Fri Dec 11, 2020 4:45 pm, edited 1 time in total.

boarchuz
Posts: 606
Joined: Tue Aug 21, 2018 5:28 am

Re: problem with CmakeLists.txt conditional configuration

Postby boarchuz » Fri Dec 11, 2020 11:10 am

elseif(CONFIG_OPTION_1)
CONFIG_OPTION_2?

Full clean and rebuild?

What relevant definitions do you see in sdkconfig.h?

champonthis
Posts: 4
Joined: Fri Dec 11, 2020 5:20 am

Re: problem with CmakeLists.txt conditional configuration

Postby champonthis » Fri Dec 11, 2020 4:47 pm

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?

champonthis
Posts: 4
Joined: Fri Dec 11, 2020 5:20 am

Re: problem with CmakeLists.txt conditional configuration

Postby champonthis » Wed Dec 16, 2020 9:23 am

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?

champonthis
Posts: 4
Joined: Fri Dec 11, 2020 5:20 am

Re: problem with CmakeLists.txt conditional configuration

Postby champonthis » Wed Dec 16, 2020 9:51 am

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.

ricardoquesada
Posts: 4
Joined: Tue Sep 27, 2016 4:25 am

Re: problem with CmakeLists.txt conditional configuration

Postby ricardoquesada » Wed Dec 15, 2021 8:58 pm

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?

FlorianR
Posts: 28
Joined: Fri Mar 12, 2021 2:00 pm

Re: problem with CmakeLists.txt conditional configuration

Postby FlorianR » Mon Jul 25, 2022 9:23 am

Hi,
I would like to know that too :)

dernasherbrezon
Posts: 3
Joined: Wed Nov 22, 2023 11:12 pm

Re: problem with CmakeLists.txt conditional configuration

Postby dernasherbrezon » Sun Dec 31, 2023 12:01 am

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.

Who is online

Users browsing this forum: No registered users and 142 guests