Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:78 Xiaozhi esp32 CMakeLists Board Selection

From Leeroopedia
Knowledge Sources
Domains Build_Systems, Configuration_Management
Last Updated 2026-10-17 00:00 GMT

Overview

Concrete tool for CMake-based board source selection provided by the XiaoZhi firmware, implementing an if/elseif chain in main/CMakeLists.txt that maps each CONFIG_BOARD_TYPE_<NAME> Kconfig symbol to board source files, locale, font, and asset configuration.

Description

main/CMakeLists.txt contains a Pattern Doc — the board source selection chain. It is the final link in the build configuration chain. The if/elseif chain checks the Kconfig symbol CONFIG_BOARD_TYPE_<NAME> and sets:

  • SRCS: List of board source files (typically one board.cc)
  • target_add_binary_assets: Optional binary assets for the board
  • Locale and font configuration: Language-specific font and string assets
  • Wake word model selection: Speech recognition model for the board's chip

Each board has exactly one elseif block. The chain is mutually exclusive because Kconfig choice ensures only one CONFIG_BOARD_TYPE_<NAME> is set.

Usage

Reference this implementation when:

  • Adding a new board to the CMake build
  • Understanding which source files compile for each board
  • Debugging "source not found" build errors
  • Configuring locale-specific fonts or assets for a board

Code Reference

Source Location

Signature

# Board source selection chain
if(CONFIG_BOARD_TYPE_BREAD_COMPACT_WIFI)
    set(SRCS
        boards/bread-compact-wifi/board.cc
    )
elseif(CONFIG_BOARD_TYPE_M5STACK_CORES3)
    set(SRCS
        boards/m5stack/cores3/board.cc
    )
    target_add_binary_assets(boards/m5stack/cores3/assets)
elseif(CONFIG_BOARD_TYPE_SEEED_XIAO_ESP32S3)
    set(SRCS
        boards/seeed/xiao_esp32s3/board.cc
    )
# ... one elseif per board
endif()

# SRCS is then compiled into the firmware
target_sources(${COMPONENT_LIB} PRIVATE ${SRCS})

Import

# CMakeLists.txt is processed by the ESP-IDF CMake build system automatically.

I/O Contract

Inputs

Name Type Required Description
CONFIG_BOARD_TYPE_<NAME> CMake variable Set to "y" by Kconfig for the selected board

Outputs

Name Type Description
SRCS Board source files compiled into the firmware
target_add_binary_assets Binary assets linked for boards that need them

Usage Examples

Adding a New Board to CMakeLists.txt

# In main/CMakeLists.txt, inside the if/elseif chain:
elseif(CONFIG_BOARD_TYPE_MY_CUSTOM_BOARD)
    set(SRCS
        boards/my-board/board.cc
    )
    # Optionally add binary assets:
    # target_add_binary_assets(boards/my-board/assets)

Verifying Board Selection

# Check which board is selected in the current build
grep CONFIG_BOARD_TYPE build/config/sdkconfig

# Output:
# CONFIG_BOARD_TYPE_BREAD_COMPACT_WIFI=y

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment