|
| 1 | +# ============================================================================== |
| 2 | +# ESP-IDF Component Configuration for Swift-Based Applications |
| 3 | +# ============================================================================== |
| 4 | +# This CMakeLists.txt configures the "main" component of an ESP-IDF project |
| 5 | +# that uses Embedded Swift instead of traditional C/C++. |
| 6 | +# ============================================================================== |
| 7 | +# ------------------------------------------------------------------------------ |
| 8 | +# Step 1: Register the component with ESP-IDF |
| 9 | +# ------------------------------------------------------------------------------ |
| 10 | +# idf_component_register() tells the build system about this component's files |
| 11 | +# and dependencies. Even though we're using Swift, we still need to register |
| 12 | +# as an IDF component. |
| 13 | +# |
| 14 | +# Parameters: |
| 15 | +# SRCS: Source files to compile. We use /dev/null because all actual source |
| 16 | +# code is in Swift files (configured separately below) |
| 17 | +# PRIV_INCLUDE_DIRS: Private header directories for this component only. |
| 18 | +# Set to "." so the BridgingHeader.h can be found. |
| 19 | +# PRIV_REQUIRES: Components this component depends on (linked privately): |
| 20 | +# - swift: Provides Embedded Swift runtime and compilation support |
| 21 | +# - esp_driver_gpio: ESP-IDF GPIO driver for controlling hardware pins |
| 22 | +# |
| 23 | +# IMPORTANT: All dependencies must be explicitly listed. |
| 24 | +idf_component_register( |
| 25 | + SRCS /dev/null |
| 26 | + PRIV_INCLUDE_DIRS "." |
| 27 | + PRIV_REQUIRES swift esp_driver_gpio |
| 28 | +) |
| 29 | + |
| 30 | +# ------------------------------------------------------------------------------ |
| 31 | +# Step 2: Configure Embedded Swift compilation |
| 32 | +# ------------------------------------------------------------------------------ |
| 33 | +# idf_component_register_swift() is a custom function (provided by the 'swift' |
| 34 | +# component) that configures the Swift compiler for embedded systems. |
| 35 | +# |
| 36 | +# Parameters: |
| 37 | +# ${COMPONENT_LIB}: The CMake library target created by idf_component_register() |
| 38 | +# (automatically available after registration) |
| 39 | +# BRIDGING_HEADER: C header file that exposes C APIs to Swift code. |
| 40 | +# This allows Swift to call ESP-IDF C functions. |
| 41 | +# SRCS: Swift source files to compile. List all .swift files in your project. |
| 42 | +idf_component_register_swift( |
| 43 | + ${COMPONENT_LIB} |
| 44 | + BRIDGING_HEADER ${CMAKE_CURRENT_LIST_DIR}/BridgingHeader.h |
| 45 | + SRCS Main.swift Led.swift |
| 46 | +) |
0 commit comments