From 8a1d5f98f993e5451f8acee04912e086a229fe8d Mon Sep 17 00:00:00 2001 From: Sudeep Mohanty Date: Mon, 26 Jan 2026 09:02:32 +0100 Subject: [PATCH] feat(cmakev2): Added component_manager example for cmakev2 This commit updates the examples/build_system/cmake/component_manager example for the new build system and adds the newly created example at examples/build_system/cmakev2/features/component_manager. --- examples/build_system/cmakev2/README.md | 9 ++- .../features/component_manager/CMakeLists.txt | 7 ++ .../features/component_manager/README.md | 68 +++++++++++++++++++ .../component_manager/main/CMakeLists.txt | 2 + .../main/component_manager.c | 12 ++++ .../component_manager/main/idf_component.yml | 36 ++++++++++ 6 files changed, 133 insertions(+), 1 deletion(-) create mode 100644 examples/build_system/cmakev2/features/component_manager/CMakeLists.txt create mode 100644 examples/build_system/cmakev2/features/component_manager/README.md create mode 100644 examples/build_system/cmakev2/features/component_manager/main/CMakeLists.txt create mode 100644 examples/build_system/cmakev2/features/component_manager/main/component_manager.c create mode 100644 examples/build_system/cmakev2/features/component_manager/main/idf_component.yml diff --git a/examples/build_system/cmakev2/README.md b/examples/build_system/cmakev2/README.md index 4d74aefea50..c2a44374b0f 100644 --- a/examples/build_system/cmakev2/README.md +++ b/examples/build_system/cmakev2/README.md @@ -77,6 +77,8 @@ LED blinking example with Kconfig configuration and Component Manager integratio ## Build System Features Examples +These examples demonstrate the build system capabilities and `cmakev2` features. + ### idf_as_lib **Location:** [idf_as_lib/](./features/idf_as_lib/) @@ -97,7 +99,12 @@ cmake -G Ninja -B build -DCMAKE_TOOLCHAIN_FILE=... ninja -C build ``` -These examples demonstrate the build system capabilities and some `cmakev2` specific features. +### component_manager +**Location:** [component_manager](./features/component_manager) + +Demonstrates using ESP-IDF component manager with `cmakev2` + +**Key Concepts:** Defining component dependencies for the application using `idf_component.yml` ## Build System v2 API Quick Reference diff --git a/examples/build_system/cmakev2/features/component_manager/CMakeLists.txt b/examples/build_system/cmakev2/features/component_manager/CMakeLists.txt new file mode 100644 index 00000000000..5fd23c2a7fb --- /dev/null +++ b/examples/build_system/cmakev2/features/component_manager/CMakeLists.txt @@ -0,0 +1,7 @@ +# The following five lines of boilerplate have to be in your project's +# CMakeLists in this exact order for cmake to work correctly +cmake_minimum_required(VERSION 3.22) + +include($ENV{IDF_PATH}/tools/cmakev2/idf.cmake) +project(component_manager C CXX ASM) +idf_project_default() diff --git a/examples/build_system/cmakev2/features/component_manager/README.md b/examples/build_system/cmakev2/features/component_manager/README.md new file mode 100644 index 00000000000..60adced3819 --- /dev/null +++ b/examples/build_system/cmakev2/features/component_manager/README.md @@ -0,0 +1,68 @@ +| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C5 | ESP32-C6 | ESP32-C61 | ESP32-H2 | ESP32-H21 | ESP32-H4 | ESP32-P4 | ESP32-S2 | ESP32-S3 | ESP32-S31 | +| ----------------- | ----- | -------- | -------- | -------- | -------- | --------- | -------- | --------- | -------- | -------- | -------- | -------- | --------- | + +# Using the component manager for downloading dependencies + +This example demonstrates how to use [IDF Component Manager](https://pypi.org/project/idf-component-manager/) for downloading dependencies from [ESP Component Registry](https://components.espressif.com). More details and use cases of IDF Component Manager can be found in the programming guide under `API Guides` -> `Tools` -> `IDF Component Manager`. + +## How to use the example +### Hardware Required + +This example is designed to work with any commonly available development kit. + +### Build and Flash + +Run `idf.py reconfigure` to configure this project. During CMake execution the component manager will process data from the manifest file `./main/idf_component.yml` where 2 dependencies are defined: + +- `idf: ">=6.0"` - Specifies required version of ESP-IDF. +- `example/cmp: ">=3.3.3"` - Defines dependency on [example/cmp](https://components.espressif.com/component/example/cmp) component that is used by the main component. + +CMake Output: +``` +... +-- IDF: Component manager round 1... +NOTICE: Dependencies lock doesn't exist, solving dependencies. +...NOTICE: Updating lock file at /Users/sudeepmohanty/esp/esp-idf/examples/build_system/cmakev2/features/component_manager/dependencies.lock +NOTICE: Processing 2 dependencies: +NOTICE: [1/2] example/cmp (3.3.9~1) +NOTICE: [2/2] idf (6.1.0) +... +``` + +Content of the `./managed_components` directory after successful build: +``` +▶ find ./managed_components +./managed_components +./managed_components/example__cmp +./managed_components/example__cmp/CMakeLists.txt +./managed_components/example__cmp/LICENSE +./managed_components/example__cmp/changelog.md +./managed_components/example__cmp/idf_component.yml +./managed_components/example__cmp/include +./managed_components/example__cmp/include/cmp.h +./managed_components/example__cmp/README.md +./managed_components/example__cmp/examples +./managed_components/example__cmp/examples/cmp_ex +./managed_components/example__cmp/examples/cmp_ex/CMakeLists.txt +./managed_components/example__cmp/examples/cmp_ex/README.md +./managed_components/example__cmp/examples/cmp_ex/main +./managed_components/example__cmp/examples/cmp_ex/main/CMakeLists.txt +./managed_components/example__cmp/examples/cmp_ex/main/idf_component.yml +./managed_components/example__cmp/examples/cmp_ex/main/cmp_ex.c +./managed_components/example__cmp/cmp.c +./managed_components/example__cmp/.component_hash +``` + +Flash the project and run the serial monitor to view the output: + +``` +idf.py -p PORT flash monitor +``` + +### Example Output + +The example outputs a line from the `cmp_hello` function from the component downloaded by the component manager. + +``` +Hello from example component! +``` diff --git a/examples/build_system/cmakev2/features/component_manager/main/CMakeLists.txt b/examples/build_system/cmakev2/features/component_manager/main/CMakeLists.txt new file mode 100644 index 00000000000..9bc2623419c --- /dev/null +++ b/examples/build_system/cmakev2/features/component_manager/main/CMakeLists.txt @@ -0,0 +1,2 @@ +idf_component_register(SRCS "component_manager.c" + INCLUDE_DIRS ".") diff --git a/examples/build_system/cmakev2/features/component_manager/main/component_manager.c b/examples/build_system/cmakev2/features/component_manager/main/component_manager.c new file mode 100644 index 00000000000..6cfbeeb121d --- /dev/null +++ b/examples/build_system/cmakev2/features/component_manager/main/component_manager.c @@ -0,0 +1,12 @@ +/* + * SPDX-FileCopyrightText: 2026 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Unlicense OR CC0-1.0 + */ +#include +#include "cmp.h" + +void app_main(void) +{ + cmp_hello(); +} diff --git a/examples/build_system/cmakev2/features/component_manager/main/idf_component.yml b/examples/build_system/cmakev2/features/component_manager/main/idf_component.yml new file mode 100644 index 00000000000..8b221801e52 --- /dev/null +++ b/examples/build_system/cmakev2/features/component_manager/main/idf_component.yml @@ -0,0 +1,36 @@ +dependencies: + # Required IDF version + idf: ">=6.0" + + # Defining a dependency from the ESP Component Registry: + # https://components.espressif.com/component/example/cmp + example/cmp: "^3.3.3" + + # # Other ways to define dependencies + # + # # For components maintained by Espressif only name can be used. + # # Same as `espressif/cmp` + # component: "~1.0.0" + # + # # Or in a longer form with extra parameters + # component2: + # version: ">=2.0.0" + # + # # For transient dependencies `public` flag can be set. + # # `public` flag doesn't have an effect for the `main` component. + # # All dependencies of `main` are public by default. + # public: true + # + # # For components hosted on non-default registry: + # service_url: "https://componentregistry.company.com" + # + # # For components in git repository: + # test_component: + # path: test_component + # git: ssh://git@gitlab.com/user/components.git + # + # # For test projects during component development + # # components can be used from a local directory + # # with relative or absolute path + # some_local_component: + # path: ../../projects/component