How to properly configure the KCONFIG system to set up your own local libraries?

kotyara12
Posts: 7
Joined: Tue Mar 22, 2022 11:09 am

How to properly configure the KCONFIG system to set up your own local libraries?

Postby kotyara12 » Sun Mar 23, 2025 8:58 am

Hello!

I am creating my own set of libraries in addition to ESP-IDF. All of them are collected OUTSIDE OF THE PROJECT FOLDER. This allows them to be used in many projects at once.

For example:

1. ESP-IDF is installed as:

Code: Select all

 c:\Projects\Espressif\.esp-idf\...
2. Libraries are collected in a folder:

Code: Select all

 c:\Projects\Espressif\espidf-k12\components\...
Of course, many of them need options. Previously, I got by with "configuration files" like project_config.h, where I manually created the macros I needed.

But the project, as they say, "went to the people", a lot of people started using it and it became very inconvenient.

Now I want to stuff many parameters into the standard idf.py menuconfig system. This is not a problem.

The problem is that I have a lot of components, and a lot of unorganized items are created in the COMPONENT CONFIG submenu. I absolutely do not like this. I want to build a KCONFIG system so that all "my" settings are in a tree and start with one item in COMPONENT CONFIG:

2025-03-23_11-45-52.png
2025-03-23_11-45-52.png (25.04 KiB) Viewed 1023 times
2025-03-23_11-48-03.png
2025-03-23_11-48-03.png (16.2 KiB) Viewed 1023 times
2025-03-23_11-48-40.png
2025-03-23_11-48-40.png (18.7 KiB) Viewed 1023 times
I achieved this by creating an "empty" component, with a KConfig file containing the following:

Code: Select all

menu "k12 Options"

    menu "System"

        orsource "../re_strings/KConfig.k12"
        orsource "../re_core/KConfig.k12"

    endmenu

    menu "Formats"

        orsource "./KConfig_Formats_DateTime.k12"

    endmenu

    menu "Peripherals"

        orsource "../re_led/KConfig.k12"
        orsource "../re_sysled/KConfig.k12"

    endmenu

    orsource "../re_debug/KConfig.k12"
endmenu
That is, all other KConfigs have the .k12 extension - this allows you to exclude them from the main menu.

I was completely satisfied with this, until.... Until I needed a conditional CMakeLists.txt:

Code: Select all

idf_build_get_property(target IDF_TARGET)

set(srcs)
set(includes)
set(requires)
set(priv_requires log re_strings)

if(CONFIG_RE_DEBUG_BACKTRACE_INTERCEPTION)
    list(APPEND srcs "backtrace/re_backtrace.c")
    list(APPEND includes "backtrace")
endif()

if(CONFIG_RE_DEBUG_MQTT_PUBLISH_SYSTEM_INFO)
    list(APPEND srcs "sysinfo/re_sysinfo_json.c")
    list(APPEND includes "sysinfo")
    list(APPEND priv_requires heap)
endif()

if(CONFIG_RE_DEBUG_MQTT_PUBLISH_CORE_SYSTEM_FLAGS)
    list(APPEND srcs "sysflags/re_sysflags_json.c")
    list(APPEND includes "sysflags")
    list(APPEND priv_requires re_core)
endif()

if(CONFIG_RE_DEBUG_MQTT_PUBLISH_TASK_LIST)
    list(APPEND srcs "tasklist/re_tasklist.c")
    list(APPEND includes "tasklist")
    list(APPEND priv_requires re_heap)
endif()

idf_component_register(
    SRCS SRCS "${srcs}"
    INCLUDE_DIRS ${includes}
    REQUIRES ${requires}
    PRIV_REQUIRES ${priv_requires}
) 
THIS DOESN'T WORK! As I understand it, this is precisely because the component folder contains the KConfig.k12 file instead of just KConfig

And now the main question:

HOW DO I COLLECT MY PARAMETERS INTO A TREE WITH ONE ROOT (OR VERtex - CALL IT WHATEVER YOU WANT), AND NOT LOSE THE FUNCTIONALITY OF CMakeList.txt

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

Re: How to properly configure the KCONFIG system to set up your own local libraries?

Postby ok-home » Mon Mar 24, 2025 12:59 am

hi
Check REQUIRES and PRIV_REQUIRES
The values of REQUIRES and PRIV_REQUIRES should not depend on any configuration choices (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 choices.
https://docs.espressif.com/projects/esp ... -component

Who is online

Users browsing this forum: Bing [Bot], ChatGPT-User, PetalBot and 2 guests