blob: d55dd38134fb892ed42c26dd0a30e8b2b2648a77 [file] [log] [blame]
Damien George9b908822020-09-23 15:55:55 +10001# Set location of base MicroPython directory.
Damien George0009a7d2021-06-24 16:03:25 +10002if(NOT MICROPY_DIR)
Damien Georgee4650122023-05-09 09:52:54 +10003 get_filename_component(MICROPY_DIR ${CMAKE_CURRENT_LIST_DIR}/../.. ABSOLUTE)
Brian 'redbeard' Harrington5fe2a3f2023-06-12 13:02:10 -07004endif()
5
Damien Georgee4650122023-05-09 09:52:54 +10006# Set location of the ESP32 port directory.
Brian 'redbeard' Harrington5fe2a3f2023-06-12 13:02:10 -07007if(NOT MICROPY_PORT_DIR)
8 get_filename_component(MICROPY_PORT_DIR ${MICROPY_DIR}/ports/esp32 ABSOLUTE)
Damien George0009a7d2021-06-24 16:03:25 +10009endif()
Damien George9b908822020-09-23 15:55:55 +100010
11# Include core source components.
12include(${MICROPY_DIR}/py/py.cmake)
Damien George9b908822020-09-23 15:55:55 +100013
Michael O'Cleirigh0ccd9e02021-03-27 17:10:39 -040014if(NOT CMAKE_BUILD_EARLY_EXPANSION)
Damien Georgebd375df2022-06-08 12:21:51 +100015 # Enable extmod components that will be configured by extmod.cmake.
16 # A board may also have enabled additional components.
17 set(MICROPY_PY_BTREE ON)
18
Michael O'Cleirigh0ccd9e02021-03-27 17:10:39 -040019 include(${MICROPY_DIR}/py/usermod.cmake)
Damien George212fe7f2021-04-08 23:45:28 +100020 include(${MICROPY_DIR}/extmod/extmod.cmake)
Michael O'Cleirigh0ccd9e02021-03-27 17:10:39 -040021endif()
22
Damien Georgee4650122023-05-09 09:52:54 +100023list(APPEND MICROPY_QSTRDEFS_PORT
Brian 'redbeard' Harrington5fe2a3f2023-06-12 13:02:10 -070024 ${MICROPY_PORT_DIR}/qstrdefsport.h
Damien George75db0b92021-02-21 11:33:15 +110025)
26
Damien Georgee4650122023-05-09 09:52:54 +100027list(APPEND MICROPY_SOURCE_SHARED
Damien George136369d2021-07-09 14:19:15 +100028 ${MICROPY_DIR}/shared/readline/readline.c
29 ${MICROPY_DIR}/shared/netutils/netutils.c
30 ${MICROPY_DIR}/shared/timeutils/timeutils.c
31 ${MICROPY_DIR}/shared/runtime/interrupt_char.c
32 ${MICROPY_DIR}/shared/runtime/stdout_helpers.c
33 ${MICROPY_DIR}/shared/runtime/sys_stdio_mphal.c
34 ${MICROPY_DIR}/shared/runtime/pyexec.c
35)
36
Damien Georgee4650122023-05-09 09:52:54 +100037list(APPEND MICROPY_SOURCE_LIB
Damien George9b908822020-09-23 15:55:55 +100038 ${MICROPY_DIR}/lib/littlefs/lfs1.c
39 ${MICROPY_DIR}/lib/littlefs/lfs1_util.c
40 ${MICROPY_DIR}/lib/littlefs/lfs2.c
41 ${MICROPY_DIR}/lib/littlefs/lfs2_util.c
Damien Georgee4650122023-05-09 09:52:54 +100042 #${MICROPY_DIR}/lib/mbedtls_errors/esp32_mbedtls_errors.c
Damien George9b908822020-09-23 15:55:55 +100043 ${MICROPY_DIR}/lib/oofatfs/ff.c
44 ${MICROPY_DIR}/lib/oofatfs/ffunicode.c
Damien George9b908822020-09-23 15:55:55 +100045)
46
Damien Georgee4650122023-05-09 09:52:54 +100047list(APPEND MICROPY_SOURCE_DRIVERS
Damien George9b908822020-09-23 15:55:55 +100048 ${MICROPY_DIR}/drivers/bus/softspi.c
49 ${MICROPY_DIR}/drivers/dht/dht.c
50)
51
Damien Georgee4650122023-05-09 09:52:54 +100052list(APPEND MICROPY_SOURCE_PORT
Brian 'redbeard' Harrington5fe2a3f2023-06-12 13:02:10 -070053 main.c
Damien George1db40ed2023-06-21 15:09:26 +100054 ppp_set_auth.c
Brian 'redbeard' Harrington5fe2a3f2023-06-12 13:02:10 -070055 uart.c
56 usb.c
57 usb_serial_jtag.c
58 gccollect.c
59 mphalport.c
60 fatfs_port.c
61 help.c
62 machine_bitstream.c
63 machine_timer.c
64 machine_pin.c
65 machine_touchpad.c
66 machine_adc.c
67 machine_adcblock.c
68 machine_dac.c
69 machine_i2c.c
70 machine_i2s.c
71 machine_uart.c
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
86 machine_wdt.c
87 mpthreadport.c
88 machine_rtc.c
89 machine_sdcard.c
90 modespnow.c
Damien George9b908822020-09-23 15:55:55 +100091)
Brian 'redbeard' Harrington5fe2a3f2023-06-12 13:02:10 -070092list(TRANSFORM MICROPY_SOURCE_PORT PREPEND ${MICROPY_PORT_DIR}/)
Damien George9b908822020-09-23 15:55:55 +100093
Damien Georgee4650122023-05-09 09:52:54 +100094list(APPEND MICROPY_SOURCE_QSTR
Damien George9b908822020-09-23 15:55:55 +100095 ${MICROPY_SOURCE_PY}
96 ${MICROPY_SOURCE_EXTMOD}
Michael O'Cleirigh0ccd9e02021-03-27 17:10:39 -040097 ${MICROPY_SOURCE_USERMOD}
Damien George136369d2021-07-09 14:19:15 +100098 ${MICROPY_SOURCE_SHARED}
Damien George9b908822020-09-23 15:55:55 +100099 ${MICROPY_SOURCE_LIB}
100 ${MICROPY_SOURCE_PORT}
Damien Georgef046b502021-09-22 00:00:26 +1000101 ${MICROPY_SOURCE_BOARD}
Damien George9b908822020-09-23 15:55:55 +1000102)
103
Damien Georgee4650122023-05-09 09:52:54 +1000104list(APPEND IDF_COMPONENTS
Damien George9b908822020-09-23 15:55:55 +1000105 app_update
106 bootloader_support
Damien Georgeda2b5fa2021-02-14 01:36:30 +1100107 bt
Damien George9b908822020-09-23 15:55:55 +1000108 driver
Damien Georgee4650122023-05-09 09:52:54 +1000109 esp_adc
110 esp_app_format
Damien George9b908822020-09-23 15:55:55 +1000111 esp_common
112 esp_eth
113 esp_event
Damien Georgee4650122023-05-09 09:52:54 +1000114 esp_hw_support
115 esp_netif
116 esp_partition
117 esp_pm
118 esp_psram
Damien George9b908822020-09-23 15:55:55 +1000119 esp_ringbuf
120 esp_rom
Damien Georgee4650122023-05-09 09:52:54 +1000121 esp_system
122 esp_timer
Damien George9b908822020-09-23 15:55:55 +1000123 esp_wifi
124 freertos
Damien Georgee4650122023-05-09 09:52:54 +1000125 hal
Damien George9b908822020-09-23 15:55:55 +1000126 heap
127 log
128 lwip
129 mbedtls
Damien George9b908822020-09-23 15:55:55 +1000130 newlib
131 nvs_flash
132 sdmmc
133 soc
134 spi_flash
Damien George9b908822020-09-23 15:55:55 +1000135 ulp
136 vfs
137 xtensa
138)
139
Damien George9b908822020-09-23 15:55:55 +1000140# Register the main IDF component.
141idf_component_register(
142 SRCS
143 ${MICROPY_SOURCE_PY}
144 ${MICROPY_SOURCE_EXTMOD}
Damien George136369d2021-07-09 14:19:15 +1000145 ${MICROPY_SOURCE_SHARED}
Damien George9b908822020-09-23 15:55:55 +1000146 ${MICROPY_SOURCE_LIB}
147 ${MICROPY_SOURCE_DRIVERS}
148 ${MICROPY_SOURCE_PORT}
Damien Georgef046b502021-09-22 00:00:26 +1000149 ${MICROPY_SOURCE_BOARD}
Damien George9b908822020-09-23 15:55:55 +1000150 INCLUDE_DIRS
Damien George5dcc9b32021-04-09 00:59:16 +1000151 ${MICROPY_INC_CORE}
Michael O'Cleirigh0ccd9e02021-03-27 17:10:39 -0400152 ${MICROPY_INC_USERMOD}
Damien George9b908822020-09-23 15:55:55 +1000153 ${MICROPY_PORT_DIR}
154 ${MICROPY_BOARD_DIR}
155 ${CMAKE_BINARY_DIR}
156 REQUIRES
157 ${IDF_COMPONENTS}
158)
159
160# Set the MicroPython target as the current (main) IDF component target.
161set(MICROPY_TARGET ${COMPONENT_TARGET})
162
163# Define mpy-cross flags, for use with frozen code.
164set(MICROPY_CROSS_FLAGS -march=xtensawin)
165
166# Set compile options for this port.
167target_compile_definitions(${MICROPY_TARGET} PUBLIC
Damien Georgeab9d47e2021-04-08 23:56:28 +1000168 ${MICROPY_DEF_CORE}
Damien George9b908822020-09-23 15:55:55 +1000169 MICROPY_ESP_IDF_4=1
170 MICROPY_VFS_FAT=1
171 MICROPY_VFS_LFS2=1
172 FFCONF_H=\"${MICROPY_OOFATFS_DIR}/ffconf.h\"
173 LFS1_NO_MALLOC LFS1_NO_DEBUG LFS1_NO_WARN LFS1_NO_ERROR LFS1_NO_ASSERT
174 LFS2_NO_MALLOC LFS2_NO_DEBUG LFS2_NO_WARN LFS2_NO_ERROR LFS2_NO_ASSERT
175)
176
177# Disable some warnings to keep the build output clean.
178target_compile_options(${MICROPY_TARGET} PUBLIC
179 -Wno-clobbered
180 -Wno-deprecated-declarations
181 -Wno-missing-field-initializers
182)
183
Damien George5dbb8222021-03-17 12:35:59 +1100184# Additional include directories needed for private NimBLE headers.
185target_include_directories(${MICROPY_TARGET} PUBLIC
186 ${IDF_PATH}/components/bt/host/nimble/nimble
187)
188
Damien Georgeab9d47e2021-04-08 23:56:28 +1000189# Add additional extmod and usermod components.
190target_link_libraries(${MICROPY_TARGET} micropy_extmod_btree)
Michael O'Cleirigh0ccd9e02021-03-27 17:10:39 -0400191target_link_libraries(${MICROPY_TARGET} usermod)
192
Damien George9b908822020-09-23 15:55:55 +1000193# Collect all of the include directories and compile definitions for the IDF components.
194foreach(comp ${IDF_COMPONENTS})
Damien George0fabda32021-04-08 23:42:22 +1000195 micropy_gather_target_properties(__idf_${comp})
Damien Georgee4650122023-05-09 09:52:54 +1000196 micropy_gather_target_properties(${comp})
Damien George9b908822020-09-23 15:55:55 +1000197endforeach()
198
Damien George9b908822020-09-23 15:55:55 +1000199# Include the main MicroPython cmake rules.
200include(${MICROPY_DIR}/py/mkrules.cmake)