Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
766 views
in Technique[技术] by (71.8m points)

makefile - How do you pass Menuconfig variables to your cmake file ( in ESP-IDF )

I am trying to configure to my build process for ESP-IDF to slim down the build. What I have tried : I've added custom entries to the menuconfig:

    menu "Install Sensor Device Drivers"
        config LISD3H_CHECK
            bool "Include LISD3H Accel Sensor"
            default "n"      
            help
                Install required drivers for LISD3H and check if device present 
        config SHT30_CHECK
            bool "Include SHT30 Temp & Hum Sensor"
            default "n"      
            help
                Install required drivers for SHT30 and check if device present
    endmenu   

and tried using these to reduce unnecessary components getting compiled into the project. The config variables are correctly created and accessible within the source code. Now, I tried to control the build within the top level cmake file:

set(component_dirs "${CMAKE_CURRENT_LIST_DIR}/../components/comp1")
message(STATUS ${component_dirs})

message(STATUS ${CONFIG_LISD3H_CHECK})
message(STATUS ${CONFIG_SHT30_CHECK})

if(CONFIG_LISD3H_CHECK)  
    list(APPEND component_dirs "${CMAKE_CURRENT_LIST_DIR}/../components/comp2" )
    message(STATUS ${component_dirs})
else()
    message(STATUS "config not equal to whategver...")
endif()

However, the if statement is always false because cmake cannot see the CONFIG_XXXX variables from Kconfig (the messages are blank) Is there a way to access Kconfig varaibles inside cmake? Or a means of using menuconfig to control the build?

Basically, How do you exclude a component from the build? Should I just use C precompile directives inside the source code and ignore what gets compiled, since it will get optimised out of the final binary?

question from:https://stackoverflow.com/questions/65894376/how-do-you-pass-menuconfig-variables-to-your-cmake-file-in-esp-idf

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You should be on the correct path according to the ESP IDF build system documentation. Did you add your options to Kconfig in the main component? Note that you need to actually run idf.py menuconfig and choose your configuration before it becomes visible to cmake, after which the root sdkconfig file should have them set.

For example, in the ESP IDF project's main/Kconfig.projbuild file I added

menu "Test Configuration"

    config TESTOPTION_YAY
        bool "Enable test option"

endmenu

Then in the project root CMakeLists.txt I added:

message(STATUS CONFIG_TESTOPTION_YAY: ${CONFIG_TESTOPTION_YAY})

Now I run idf.py menuconfig and set the test option on or off. Subsequently I build with idf.py build - the build log shows -- CONFIG_TESTOPTION_YAY:y or -- CONFIG_TESTOPTION_YAY: depending on the choice I made.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...