blob: f2b3dd4a4f75ab3897821e17f2cb6c69c0cdc780 [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)
3 get_filename_component(MICROPY_DIR ${PROJECT_DIR}/../.. ABSOLUTE)
4endif()
Damien George9b908822020-09-23 15:55:55 +10005
6# Include core source components.
7include(${MICROPY_DIR}/py/py.cmake)
Damien George9b908822020-09-23 15:55:55 +10008
Michael O'Cleirigh0ccd9e02021-03-27 17:10:39 -04009if(NOT CMAKE_BUILD_EARLY_EXPANSION)
10 include(${MICROPY_DIR}/py/usermod.cmake)
Damien George212fe7f2021-04-08 23:45:28 +100011 include(${MICROPY_DIR}/extmod/extmod.cmake)
Michael O'Cleirigh0ccd9e02021-03-27 17:10:39 -040012endif()
13
Damien George75db0b92021-02-21 11:33:15 +110014set(MICROPY_QSTRDEFS_PORT
15 ${PROJECT_DIR}/qstrdefsport.h
16)
17
Damien George136369d2021-07-09 14:19:15 +100018set(MICROPY_SOURCE_SHARED
19 ${MICROPY_DIR}/shared/readline/readline.c
20 ${MICROPY_DIR}/shared/netutils/netutils.c
21 ${MICROPY_DIR}/shared/timeutils/timeutils.c
22 ${MICROPY_DIR}/shared/runtime/interrupt_char.c
23 ${MICROPY_DIR}/shared/runtime/stdout_helpers.c
24 ${MICROPY_DIR}/shared/runtime/sys_stdio_mphal.c
25 ${MICROPY_DIR}/shared/runtime/pyexec.c
26)
27
Damien George9b908822020-09-23 15:55:55 +100028set(MICROPY_SOURCE_LIB
29 ${MICROPY_DIR}/lib/littlefs/lfs1.c
30 ${MICROPY_DIR}/lib/littlefs/lfs1_util.c
31 ${MICROPY_DIR}/lib/littlefs/lfs2.c
32 ${MICROPY_DIR}/lib/littlefs/lfs2_util.c
33 ${MICROPY_DIR}/lib/mbedtls_errors/mp_mbedtls_errors.c
Damien George9b908822020-09-23 15:55:55 +100034 ${MICROPY_DIR}/lib/oofatfs/ff.c
35 ${MICROPY_DIR}/lib/oofatfs/ffunicode.c
Damien George9b908822020-09-23 15:55:55 +100036)
37
38set(MICROPY_SOURCE_DRIVERS
39 ${MICROPY_DIR}/drivers/bus/softspi.c
40 ${MICROPY_DIR}/drivers/dht/dht.c
41)
42
43set(MICROPY_SOURCE_PORT
44 ${PROJECT_DIR}/main.c
45 ${PROJECT_DIR}/uart.c
Damien Georgec81d0482021-02-19 12:08:11 +110046 ${PROJECT_DIR}/usb.c
Damien George9b908822020-09-23 15:55:55 +100047 ${PROJECT_DIR}/gccollect.c
48 ${PROJECT_DIR}/mphalport.c
49 ${PROJECT_DIR}/fatfs_port.c
50 ${PROJECT_DIR}/help.c
51 ${PROJECT_DIR}/modutime.c
52 ${PROJECT_DIR}/moduos.c
53 ${PROJECT_DIR}/machine_timer.c
54 ${PROJECT_DIR}/machine_pin.c
55 ${PROJECT_DIR}/machine_touchpad.c
56 ${PROJECT_DIR}/machine_adc.c
57 ${PROJECT_DIR}/machine_dac.c
58 ${PROJECT_DIR}/machine_i2c.c
Mike Teachman8a5bfe42021-04-16 21:27:40 -070059 ${PROJECT_DIR}/machine_i2s.c
Damien George9b908822020-09-23 15:55:55 +100060 ${PROJECT_DIR}/machine_pwm.c
61 ${PROJECT_DIR}/machine_uart.c
62 ${PROJECT_DIR}/modmachine.c
63 ${PROJECT_DIR}/modnetwork.c
64 ${PROJECT_DIR}/network_lan.c
65 ${PROJECT_DIR}/network_ppp.c
66 ${PROJECT_DIR}/mpnimbleport.c
67 ${PROJECT_DIR}/modsocket.c
68 ${PROJECT_DIR}/modesp.c
Thorsten von Eickenc10d4312021-01-18 01:06:12 -080069 ${PROJECT_DIR}/esp32_nvs.c
Damien George9b908822020-09-23 15:55:55 +100070 ${PROJECT_DIR}/esp32_partition.c
71 ${PROJECT_DIR}/esp32_rmt.c
72 ${PROJECT_DIR}/esp32_ulp.c
73 ${PROJECT_DIR}/modesp32.c
74 ${PROJECT_DIR}/espneopixel.c
75 ${PROJECT_DIR}/machine_hw_spi.c
76 ${PROJECT_DIR}/machine_wdt.c
77 ${PROJECT_DIR}/mpthreadport.c
78 ${PROJECT_DIR}/machine_rtc.c
79 ${PROJECT_DIR}/machine_sdcard.c
80)
81
82set(MICROPY_SOURCE_QSTR
83 ${MICROPY_SOURCE_PY}
84 ${MICROPY_SOURCE_EXTMOD}
Michael O'Cleirigh0ccd9e02021-03-27 17:10:39 -040085 ${MICROPY_SOURCE_USERMOD}
Damien George136369d2021-07-09 14:19:15 +100086 ${MICROPY_SOURCE_SHARED}
Damien George9b908822020-09-23 15:55:55 +100087 ${MICROPY_SOURCE_LIB}
88 ${MICROPY_SOURCE_PORT}
89)
90
91set(IDF_COMPONENTS
92 app_update
93 bootloader_support
Damien Georgeda2b5fa2021-02-14 01:36:30 +110094 bt
Damien George9b908822020-09-23 15:55:55 +100095 driver
Damien George9b908822020-09-23 15:55:55 +100096 esp_common
97 esp_eth
98 esp_event
99 esp_ringbuf
100 esp_rom
101 esp_wifi
102 freertos
103 heap
104 log
105 lwip
106 mbedtls
107 mdns
108 newlib
109 nvs_flash
110 sdmmc
111 soc
112 spi_flash
113 tcpip_adapter
114 ulp
115 vfs
116 xtensa
117)
118
Damien Georged191d882021-02-15 21:00:01 +1100119if(IDF_VERSION_MINOR GREATER_EQUAL 1)
120 list(APPEND IDF_COMPONENTS esp_netif)
121endif()
122
Damien Georgea9150022021-02-15 21:00:09 +1100123if(IDF_VERSION_MINOR GREATER_EQUAL 2)
124 list(APPEND IDF_COMPONENTS esp_system)
125 list(APPEND IDF_COMPONENTS esp_timer)
126endif()
127
Damien George143372a2021-02-19 10:38:01 +1100128if(IDF_VERSION_MINOR GREATER_EQUAL 3)
129 list(APPEND IDF_COMPONENTS esp_hw_support)
130 list(APPEND IDF_COMPONENTS esp_pm)
131 list(APPEND IDF_COMPONENTS hal)
132endif()
133
Damien George66a86a02021-02-18 21:24:34 +1100134if(IDF_TARGET STREQUAL "esp32")
135 list(APPEND IDF_COMPONENTS esp32)
136elseif(IDF_TARGET STREQUAL "esp32s2")
137 list(APPEND IDF_COMPONENTS esp32s2)
Damien Georgec81d0482021-02-19 12:08:11 +1100138 list(APPEND IDF_COMPONENTS tinyusb)
Damien George5093d492021-05-06 10:58:12 +1000139elseif(IDF_TARGET STREQUAL "esp32s3")
140 list(APPEND IDF_COMPONENTS esp32s3)
141 list(APPEND IDF_COMPONENTS tinyusb)
Damien George66a86a02021-02-18 21:24:34 +1100142endif()
143
Damien George9b908822020-09-23 15:55:55 +1000144# Register the main IDF component.
145idf_component_register(
146 SRCS
147 ${MICROPY_SOURCE_PY}
148 ${MICROPY_SOURCE_EXTMOD}
Damien George136369d2021-07-09 14:19:15 +1000149 ${MICROPY_SOURCE_SHARED}
Damien George9b908822020-09-23 15:55:55 +1000150 ${MICROPY_SOURCE_LIB}
151 ${MICROPY_SOURCE_DRIVERS}
152 ${MICROPY_SOURCE_PORT}
153 INCLUDE_DIRS
Damien George5dcc9b32021-04-09 00:59:16 +1000154 ${MICROPY_INC_CORE}
Michael O'Cleirigh0ccd9e02021-03-27 17:10:39 -0400155 ${MICROPY_INC_USERMOD}
Damien George9b908822020-09-23 15:55:55 +1000156 ${MICROPY_PORT_DIR}
157 ${MICROPY_BOARD_DIR}
158 ${CMAKE_BINARY_DIR}
159 REQUIRES
160 ${IDF_COMPONENTS}
161)
162
163# Set the MicroPython target as the current (main) IDF component target.
164set(MICROPY_TARGET ${COMPONENT_TARGET})
165
166# Define mpy-cross flags, for use with frozen code.
167set(MICROPY_CROSS_FLAGS -march=xtensawin)
168
169# Set compile options for this port.
170target_compile_definitions(${MICROPY_TARGET} PUBLIC
Damien Georgeab9d47e2021-04-08 23:56:28 +1000171 ${MICROPY_DEF_CORE}
Damien George9b908822020-09-23 15:55:55 +1000172 MICROPY_ESP_IDF_4=1
173 MICROPY_VFS_FAT=1
174 MICROPY_VFS_LFS2=1
175 FFCONF_H=\"${MICROPY_OOFATFS_DIR}/ffconf.h\"
176 LFS1_NO_MALLOC LFS1_NO_DEBUG LFS1_NO_WARN LFS1_NO_ERROR LFS1_NO_ASSERT
177 LFS2_NO_MALLOC LFS2_NO_DEBUG LFS2_NO_WARN LFS2_NO_ERROR LFS2_NO_ASSERT
178)
179
180# Disable some warnings to keep the build output clean.
181target_compile_options(${MICROPY_TARGET} PUBLIC
182 -Wno-clobbered
183 -Wno-deprecated-declarations
184 -Wno-missing-field-initializers
185)
186
Damien Georgeab9d47e2021-04-08 23:56:28 +1000187# Add additional extmod and usermod components.
188target_link_libraries(${MICROPY_TARGET} micropy_extmod_btree)
Michael O'Cleirigh0ccd9e02021-03-27 17:10:39 -0400189target_link_libraries(${MICROPY_TARGET} usermod)
190
191
Damien George9b908822020-09-23 15:55:55 +1000192# Collect all of the include directories and compile definitions for the IDF components.
193foreach(comp ${IDF_COMPONENTS})
Damien George0fabda32021-04-08 23:42:22 +1000194 micropy_gather_target_properties(__idf_${comp})
Damien George9b908822020-09-23 15:55:55 +1000195endforeach()
196
Damien Georgea9150022021-02-15 21:00:09 +1100197if(IDF_VERSION_MINOR GREATER_EQUAL 2)
198 # These paths cannot currently be found by the IDF_COMPONENTS search loop above,
199 # so add them explicitly.
200 list(APPEND MICROPY_CPP_INC_EXTRA ${IDF_PATH}/components/soc/soc/${IDF_TARGET}/include)
201 list(APPEND MICROPY_CPP_INC_EXTRA ${IDF_PATH}/components/soc/soc/include)
Damien Georgec81d0482021-02-19 12:08:11 +1100202 if(IDF_VERSION_MINOR GREATER_EQUAL 3)
203 list(APPEND MICROPY_CPP_INC_EXTRA ${IDF_PATH}/components/tinyusb/additions/include)
204 list(APPEND MICROPY_CPP_INC_EXTRA ${IDF_PATH}/components/tinyusb/tinyusb/src)
205 endif()
Damien Georgea9150022021-02-15 21:00:09 +1100206endif()
207
Damien George9b908822020-09-23 15:55:55 +1000208# Include the main MicroPython cmake rules.
209include(${MICROPY_DIR}/py/mkrules.cmake)