Damien George | 9b90882 | 2020-09-23 15:55:55 +1000 | [diff] [blame] | 1 | # Set location of base MicroPython directory. |
Damien George | 0009a7d | 2021-06-24 16:03:25 +1000 | [diff] [blame] | 2 | if(NOT MICROPY_DIR) |
Damien George | e465012 | 2023-05-09 09:52:54 +1000 | [diff] [blame] | 3 | get_filename_component(MICROPY_DIR ${CMAKE_CURRENT_LIST_DIR}/../.. ABSOLUTE) |
Brian 'redbeard' Harrington | 5fe2a3f | 2023-06-12 13:02:10 -0700 | [diff] [blame] | 4 | endif() |
| 5 | |
Damien George | e465012 | 2023-05-09 09:52:54 +1000 | [diff] [blame] | 6 | # Set location of the ESP32 port directory. |
Brian 'redbeard' Harrington | 5fe2a3f | 2023-06-12 13:02:10 -0700 | [diff] [blame] | 7 | if(NOT MICROPY_PORT_DIR) |
| 8 | get_filename_component(MICROPY_PORT_DIR ${MICROPY_DIR}/ports/esp32 ABSOLUTE) |
Damien George | 0009a7d | 2021-06-24 16:03:25 +1000 | [diff] [blame] | 9 | endif() |
Damien George | 9b90882 | 2020-09-23 15:55:55 +1000 | [diff] [blame] | 10 | |
| 11 | # Include core source components. |
| 12 | include(${MICROPY_DIR}/py/py.cmake) |
Damien George | 9b90882 | 2020-09-23 15:55:55 +1000 | [diff] [blame] | 13 | |
Jim Mussared | ad123ed | 2023-07-31 17:24:38 +1000 | [diff] [blame] | 14 | # CMAKE_BUILD_EARLY_EXPANSION is set during the component-discovery phase of |
| 15 | # `idf.py build`, so none of the extmod/usermod (and in reality, most of the |
| 16 | # micropython) rules need to happen. Specifically, you cannot invoke add_library. |
Michael O'Cleirigh | 0ccd9e0 | 2021-03-27 17:10:39 -0400 | [diff] [blame] | 17 | if(NOT CMAKE_BUILD_EARLY_EXPANSION) |
Damien George | bd375df | 2022-06-08 12:21:51 +1000 | [diff] [blame] | 18 | # Enable extmod components that will be configured by extmod.cmake. |
| 19 | # A board may also have enabled additional components. |
| 20 | set(MICROPY_PY_BTREE ON) |
| 21 | |
Michael O'Cleirigh | 0ccd9e0 | 2021-03-27 17:10:39 -0400 | [diff] [blame] | 22 | include(${MICROPY_DIR}/py/usermod.cmake) |
Damien George | 212fe7f | 2021-04-08 23:45:28 +1000 | [diff] [blame] | 23 | include(${MICROPY_DIR}/extmod/extmod.cmake) |
Michael O'Cleirigh | 0ccd9e0 | 2021-03-27 17:10:39 -0400 | [diff] [blame] | 24 | endif() |
| 25 | |
Damien George | e465012 | 2023-05-09 09:52:54 +1000 | [diff] [blame] | 26 | list(APPEND MICROPY_QSTRDEFS_PORT |
Brian 'redbeard' Harrington | 5fe2a3f | 2023-06-12 13:02:10 -0700 | [diff] [blame] | 27 | ${MICROPY_PORT_DIR}/qstrdefsport.h |
Damien George | 75db0b9 | 2021-02-21 11:33:15 +1100 | [diff] [blame] | 28 | ) |
| 29 | |
Damien George | e465012 | 2023-05-09 09:52:54 +1000 | [diff] [blame] | 30 | list(APPEND MICROPY_SOURCE_SHARED |
Damien George | 136369d | 2021-07-09 14:19:15 +1000 | [diff] [blame] | 31 | ${MICROPY_DIR}/shared/readline/readline.c |
| 32 | ${MICROPY_DIR}/shared/netutils/netutils.c |
| 33 | ${MICROPY_DIR}/shared/timeutils/timeutils.c |
| 34 | ${MICROPY_DIR}/shared/runtime/interrupt_char.c |
| 35 | ${MICROPY_DIR}/shared/runtime/stdout_helpers.c |
| 36 | ${MICROPY_DIR}/shared/runtime/sys_stdio_mphal.c |
| 37 | ${MICROPY_DIR}/shared/runtime/pyexec.c |
| 38 | ) |
| 39 | |
Damien George | e465012 | 2023-05-09 09:52:54 +1000 | [diff] [blame] | 40 | list(APPEND MICROPY_SOURCE_LIB |
Damien George | 9b90882 | 2020-09-23 15:55:55 +1000 | [diff] [blame] | 41 | ${MICROPY_DIR}/lib/littlefs/lfs1.c |
| 42 | ${MICROPY_DIR}/lib/littlefs/lfs1_util.c |
| 43 | ${MICROPY_DIR}/lib/littlefs/lfs2.c |
| 44 | ${MICROPY_DIR}/lib/littlefs/lfs2_util.c |
Damien George | e465012 | 2023-05-09 09:52:54 +1000 | [diff] [blame] | 45 | #${MICROPY_DIR}/lib/mbedtls_errors/esp32_mbedtls_errors.c |
Damien George | 9b90882 | 2020-09-23 15:55:55 +1000 | [diff] [blame] | 46 | ${MICROPY_DIR}/lib/oofatfs/ff.c |
| 47 | ${MICROPY_DIR}/lib/oofatfs/ffunicode.c |
Damien George | 9b90882 | 2020-09-23 15:55:55 +1000 | [diff] [blame] | 48 | ) |
| 49 | |
Damien George | e465012 | 2023-05-09 09:52:54 +1000 | [diff] [blame] | 50 | list(APPEND MICROPY_SOURCE_DRIVERS |
Damien George | 9b90882 | 2020-09-23 15:55:55 +1000 | [diff] [blame] | 51 | ${MICROPY_DIR}/drivers/bus/softspi.c |
| 52 | ${MICROPY_DIR}/drivers/dht/dht.c |
| 53 | ) |
| 54 | |
Damien George | e465012 | 2023-05-09 09:52:54 +1000 | [diff] [blame] | 55 | list(APPEND MICROPY_SOURCE_PORT |
Brian 'redbeard' Harrington | 5fe2a3f | 2023-06-12 13:02:10 -0700 | [diff] [blame] | 56 | main.c |
Damien George | 1db40ed | 2023-06-21 15:09:26 +1000 | [diff] [blame] | 57 | ppp_set_auth.c |
Brian 'redbeard' Harrington | 5fe2a3f | 2023-06-12 13:02:10 -0700 | [diff] [blame] | 58 | uart.c |
| 59 | usb.c |
| 60 | usb_serial_jtag.c |
| 61 | gccollect.c |
| 62 | mphalport.c |
| 63 | fatfs_port.c |
| 64 | help.c |
| 65 | machine_bitstream.c |
| 66 | machine_timer.c |
| 67 | machine_pin.c |
| 68 | machine_touchpad.c |
Brian 'redbeard' Harrington | 5fe2a3f | 2023-06-12 13:02:10 -0700 | [diff] [blame] | 69 | machine_adcblock.c |
| 70 | machine_dac.c |
| 71 | machine_i2c.c |
Brian 'redbeard' Harrington | 5fe2a3f | 2023-06-12 13:02:10 -0700 | [diff] [blame] | 72 | modmachine.c |
| 73 | network_common.c |
| 74 | network_lan.c |
| 75 | network_ppp.c |
| 76 | network_wlan.c |
| 77 | mpnimbleport.c |
| 78 | modsocket.c |
| 79 | modesp.c |
| 80 | esp32_nvs.c |
| 81 | esp32_partition.c |
| 82 | esp32_rmt.c |
| 83 | esp32_ulp.c |
| 84 | modesp32.c |
| 85 | machine_hw_spi.c |
Brian 'redbeard' Harrington | 5fe2a3f | 2023-06-12 13:02:10 -0700 | [diff] [blame] | 86 | mpthreadport.c |
| 87 | machine_rtc.c |
| 88 | machine_sdcard.c |
| 89 | modespnow.c |
Damien George | 9b90882 | 2020-09-23 15:55:55 +1000 | [diff] [blame] | 90 | ) |
Brian 'redbeard' Harrington | 5fe2a3f | 2023-06-12 13:02:10 -0700 | [diff] [blame] | 91 | list(TRANSFORM MICROPY_SOURCE_PORT PREPEND ${MICROPY_PORT_DIR}/) |
Damien George | cb31c0a | 2023-07-15 00:03:59 +1000 | [diff] [blame] | 92 | list(APPEND MICROPY_SOURCE_PORT ${CMAKE_BINARY_DIR}/pins.c) |
Damien George | 9b90882 | 2020-09-23 15:55:55 +1000 | [diff] [blame] | 93 | |
Damien George | e465012 | 2023-05-09 09:52:54 +1000 | [diff] [blame] | 94 | list(APPEND MICROPY_SOURCE_QSTR |
Damien George | 9b90882 | 2020-09-23 15:55:55 +1000 | [diff] [blame] | 95 | ${MICROPY_SOURCE_PY} |
| 96 | ${MICROPY_SOURCE_EXTMOD} |
Michael O'Cleirigh | 0ccd9e0 | 2021-03-27 17:10:39 -0400 | [diff] [blame] | 97 | ${MICROPY_SOURCE_USERMOD} |
Damien George | 136369d | 2021-07-09 14:19:15 +1000 | [diff] [blame] | 98 | ${MICROPY_SOURCE_SHARED} |
Damien George | 9b90882 | 2020-09-23 15:55:55 +1000 | [diff] [blame] | 99 | ${MICROPY_SOURCE_LIB} |
| 100 | ${MICROPY_SOURCE_PORT} |
Damien George | f046b50 | 2021-09-22 00:00:26 +1000 | [diff] [blame] | 101 | ${MICROPY_SOURCE_BOARD} |
Damien George | 9b90882 | 2020-09-23 15:55:55 +1000 | [diff] [blame] | 102 | ) |
| 103 | |
Damien George | e465012 | 2023-05-09 09:52:54 +1000 | [diff] [blame] | 104 | list(APPEND IDF_COMPONENTS |
Damien George | 9b90882 | 2020-09-23 15:55:55 +1000 | [diff] [blame] | 105 | app_update |
| 106 | bootloader_support |
Damien George | da2b5fa | 2021-02-14 01:36:30 +1100 | [diff] [blame] | 107 | bt |
Damien George | 9b90882 | 2020-09-23 15:55:55 +1000 | [diff] [blame] | 108 | driver |
Damien George | e465012 | 2023-05-09 09:52:54 +1000 | [diff] [blame] | 109 | esp_adc |
| 110 | esp_app_format |
Damien George | 9b90882 | 2020-09-23 15:55:55 +1000 | [diff] [blame] | 111 | esp_common |
| 112 | esp_eth |
| 113 | esp_event |
Damien George | e465012 | 2023-05-09 09:52:54 +1000 | [diff] [blame] | 114 | esp_hw_support |
| 115 | esp_netif |
| 116 | esp_partition |
| 117 | esp_pm |
| 118 | esp_psram |
Damien George | 9b90882 | 2020-09-23 15:55:55 +1000 | [diff] [blame] | 119 | esp_ringbuf |
| 120 | esp_rom |
Damien George | e465012 | 2023-05-09 09:52:54 +1000 | [diff] [blame] | 121 | esp_system |
| 122 | esp_timer |
Damien George | 9b90882 | 2020-09-23 15:55:55 +1000 | [diff] [blame] | 123 | esp_wifi |
| 124 | freertos |
Damien George | e465012 | 2023-05-09 09:52:54 +1000 | [diff] [blame] | 125 | hal |
Damien George | 9b90882 | 2020-09-23 15:55:55 +1000 | [diff] [blame] | 126 | heap |
| 127 | log |
| 128 | lwip |
| 129 | mbedtls |
Damien George | 9b90882 | 2020-09-23 15:55:55 +1000 | [diff] [blame] | 130 | newlib |
| 131 | nvs_flash |
| 132 | sdmmc |
| 133 | soc |
| 134 | spi_flash |
Damien George | 9b90882 | 2020-09-23 15:55:55 +1000 | [diff] [blame] | 135 | ulp |
| 136 | vfs |
Damien George | 9b90882 | 2020-09-23 15:55:55 +1000 | [diff] [blame] | 137 | ) |
| 138 | |
Damien George | 9b90882 | 2020-09-23 15:55:55 +1000 | [diff] [blame] | 139 | # Register the main IDF component. |
| 140 | idf_component_register( |
| 141 | SRCS |
| 142 | ${MICROPY_SOURCE_PY} |
| 143 | ${MICROPY_SOURCE_EXTMOD} |
Damien George | 136369d | 2021-07-09 14:19:15 +1000 | [diff] [blame] | 144 | ${MICROPY_SOURCE_SHARED} |
Damien George | 9b90882 | 2020-09-23 15:55:55 +1000 | [diff] [blame] | 145 | ${MICROPY_SOURCE_LIB} |
| 146 | ${MICROPY_SOURCE_DRIVERS} |
| 147 | ${MICROPY_SOURCE_PORT} |
Damien George | f046b50 | 2021-09-22 00:00:26 +1000 | [diff] [blame] | 148 | ${MICROPY_SOURCE_BOARD} |
Damien George | 9b90882 | 2020-09-23 15:55:55 +1000 | [diff] [blame] | 149 | INCLUDE_DIRS |
Damien George | 5dcc9b3 | 2021-04-09 00:59:16 +1000 | [diff] [blame] | 150 | ${MICROPY_INC_CORE} |
Michael O'Cleirigh | 0ccd9e0 | 2021-03-27 17:10:39 -0400 | [diff] [blame] | 151 | ${MICROPY_INC_USERMOD} |
Damien George | 9b90882 | 2020-09-23 15:55:55 +1000 | [diff] [blame] | 152 | ${MICROPY_PORT_DIR} |
| 153 | ${MICROPY_BOARD_DIR} |
| 154 | ${CMAKE_BINARY_DIR} |
| 155 | REQUIRES |
| 156 | ${IDF_COMPONENTS} |
| 157 | ) |
| 158 | |
| 159 | # Set the MicroPython target as the current (main) IDF component target. |
| 160 | set(MICROPY_TARGET ${COMPONENT_TARGET}) |
| 161 | |
| 162 | # Define mpy-cross flags, for use with frozen code. |
Alessandro Gatti | 95ce61d | 2023-10-31 13:28:25 +0100 | [diff] [blame^] | 163 | if(NOT IDF_TARGET STREQUAL "esp32c3") |
Damien George | 9b90882 | 2020-09-23 15:55:55 +1000 | [diff] [blame] | 164 | set(MICROPY_CROSS_FLAGS -march=xtensawin) |
Alessandro Gatti | 95ce61d | 2023-10-31 13:28:25 +0100 | [diff] [blame^] | 165 | endif() |
Damien George | 9b90882 | 2020-09-23 15:55:55 +1000 | [diff] [blame] | 166 | |
| 167 | # Set compile options for this port. |
| 168 | target_compile_definitions(${MICROPY_TARGET} PUBLIC |
Damien George | ab9d47e | 2021-04-08 23:56:28 +1000 | [diff] [blame] | 169 | ${MICROPY_DEF_CORE} |
Jim Mussared | 2fbf42d | 2023-07-25 15:03:30 +1000 | [diff] [blame] | 170 | ${MICROPY_DEF_BOARD} |
Damien George | 9b90882 | 2020-09-23 15:55:55 +1000 | [diff] [blame] | 171 | MICROPY_ESP_IDF_4=1 |
| 172 | MICROPY_VFS_FAT=1 |
| 173 | MICROPY_VFS_LFS2=1 |
| 174 | FFCONF_H=\"${MICROPY_OOFATFS_DIR}/ffconf.h\" |
| 175 | LFS1_NO_MALLOC LFS1_NO_DEBUG LFS1_NO_WARN LFS1_NO_ERROR LFS1_NO_ASSERT |
| 176 | LFS2_NO_MALLOC LFS2_NO_DEBUG LFS2_NO_WARN LFS2_NO_ERROR LFS2_NO_ASSERT |
| 177 | ) |
| 178 | |
| 179 | # Disable some warnings to keep the build output clean. |
| 180 | target_compile_options(${MICROPY_TARGET} PUBLIC |
| 181 | -Wno-clobbered |
| 182 | -Wno-deprecated-declarations |
| 183 | -Wno-missing-field-initializers |
| 184 | ) |
| 185 | |
Damien George | 5dbb822 | 2021-03-17 12:35:59 +1100 | [diff] [blame] | 186 | # Additional include directories needed for private NimBLE headers. |
| 187 | target_include_directories(${MICROPY_TARGET} PUBLIC |
| 188 | ${IDF_PATH}/components/bt/host/nimble/nimble |
| 189 | ) |
| 190 | |
Damien George | ab9d47e | 2021-04-08 23:56:28 +1000 | [diff] [blame] | 191 | # Add additional extmod and usermod components. |
| 192 | target_link_libraries(${MICROPY_TARGET} micropy_extmod_btree) |
Michael O'Cleirigh | 0ccd9e0 | 2021-03-27 17:10:39 -0400 | [diff] [blame] | 193 | target_link_libraries(${MICROPY_TARGET} usermod) |
| 194 | |
Luca Burelli | 31ef7c1 | 2023-07-05 18:03:11 +0200 | [diff] [blame] | 195 | # Collect all of the include directories and compile definitions for the IDF components, |
| 196 | # including those added by the IDF Component Manager via idf_components.yaml. |
| 197 | foreach(comp ${__COMPONENT_NAMES_RESOLVED}) |
Damien George | 0fabda3 | 2021-04-08 23:42:22 +1000 | [diff] [blame] | 198 | micropy_gather_target_properties(__idf_${comp}) |
Damien George | e465012 | 2023-05-09 09:52:54 +1000 | [diff] [blame] | 199 | micropy_gather_target_properties(${comp}) |
Damien George | 9b90882 | 2020-09-23 15:55:55 +1000 | [diff] [blame] | 200 | endforeach() |
| 201 | |
Damien George | 9b90882 | 2020-09-23 15:55:55 +1000 | [diff] [blame] | 202 | # Include the main MicroPython cmake rules. |
| 203 | include(${MICROPY_DIR}/py/mkrules.cmake) |
Damien George | cb31c0a | 2023-07-15 00:03:59 +1000 | [diff] [blame] | 204 | |
| 205 | # Generate source files for named pins (requires mkrules.cmake for MICROPY_GENHDR_DIR). |
| 206 | |
| 207 | set(GEN_PINS_PREFIX "${MICROPY_PORT_DIR}/boards/pins_prefix.c") |
| 208 | set(GEN_PINS_MKPINS "${MICROPY_PORT_DIR}/boards/make-pins.py") |
| 209 | set(GEN_PINS_SRC "${CMAKE_BINARY_DIR}/pins.c") |
| 210 | set(GEN_PINS_HDR "${MICROPY_GENHDR_DIR}/pins.h") |
| 211 | |
| 212 | if(EXISTS "${MICROPY_BOARD_DIR}/pins.csv") |
| 213 | set(GEN_PINS_BOARD_CSV "${MICROPY_BOARD_DIR}/pins.csv") |
| 214 | set(GEN_PINS_BOARD_CSV_ARG --board-csv "${GEN_PINS_BOARD_CSV}") |
| 215 | endif() |
| 216 | |
| 217 | target_sources(${MICROPY_TARGET} PRIVATE ${GEN_PINS_HDR}) |
| 218 | |
| 219 | add_custom_command( |
| 220 | OUTPUT ${GEN_PINS_SRC} ${GEN_PINS_HDR} |
| 221 | COMMAND ${Python3_EXECUTABLE} ${GEN_PINS_MKPINS} ${GEN_PINS_BOARD_CSV_ARG} |
| 222 | --prefix ${GEN_PINS_PREFIX} --output-source ${GEN_PINS_SRC} --output-header ${GEN_PINS_HDR} |
| 223 | DEPENDS |
| 224 | ${MICROPY_MPVERSION} |
| 225 | ${GEN_PINS_MKPINS} |
| 226 | ${GEN_PINS_BOARD_CSV} |
| 227 | ${GEN_PINS_PREFIX} |
| 228 | VERBATIM |
| 229 | COMMAND_EXPAND_LISTS |
| 230 | ) |