blob: 18d7dc7fae245e1d6ba79566c31a0deab98ef695 [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)
Damien George68235142021-07-18 12:11:21 +100037if(IDF_TARGET STREQUAL "esp32c3")
38 list(APPEND MICROPY_SOURCE_LIB ${MICROPY_DIR}/shared/runtime/gchelper_generic.c)
39endif()
Damien George9b908822020-09-23 15:55:55 +100040
41set(MICROPY_SOURCE_DRIVERS
42 ${MICROPY_DIR}/drivers/bus/softspi.c
43 ${MICROPY_DIR}/drivers/dht/dht.c
44)
45
46set(MICROPY_SOURCE_PORT
47 ${PROJECT_DIR}/main.c
48 ${PROJECT_DIR}/uart.c
Damien Georgec81d0482021-02-19 12:08:11 +110049 ${PROJECT_DIR}/usb.c
Patrick Van Oosterwijcka66bd7a2021-08-26 12:19:46 -060050 ${PROJECT_DIR}/usb_serial_jtag.c
Damien George9b908822020-09-23 15:55:55 +100051 ${PROJECT_DIR}/gccollect.c
52 ${PROJECT_DIR}/mphalport.c
53 ${PROJECT_DIR}/fatfs_port.c
54 ${PROJECT_DIR}/help.c
55 ${PROJECT_DIR}/modutime.c
56 ${PROJECT_DIR}/moduos.c
Jim Mussared71f4faa2021-08-11 14:26:23 +100057 ${PROJECT_DIR}/machine_bitstream.c
Damien George9b908822020-09-23 15:55:55 +100058 ${PROJECT_DIR}/machine_timer.c
59 ${PROJECT_DIR}/machine_pin.c
60 ${PROJECT_DIR}/machine_touchpad.c
61 ${PROJECT_DIR}/machine_adc.c
62 ${PROJECT_DIR}/machine_dac.c
63 ${PROJECT_DIR}/machine_i2c.c
Mike Teachman8a5bfe42021-04-16 21:27:40 -070064 ${PROJECT_DIR}/machine_i2s.c
Damien George9b908822020-09-23 15:55:55 +100065 ${PROJECT_DIR}/machine_uart.c
66 ${PROJECT_DIR}/modmachine.c
67 ${PROJECT_DIR}/modnetwork.c
68 ${PROJECT_DIR}/network_lan.c
69 ${PROJECT_DIR}/network_ppp.c
70 ${PROJECT_DIR}/mpnimbleport.c
71 ${PROJECT_DIR}/modsocket.c
72 ${PROJECT_DIR}/modesp.c
Thorsten von Eickenc10d4312021-01-18 01:06:12 -080073 ${PROJECT_DIR}/esp32_nvs.c
Damien George9b908822020-09-23 15:55:55 +100074 ${PROJECT_DIR}/esp32_partition.c
75 ${PROJECT_DIR}/esp32_rmt.c
76 ${PROJECT_DIR}/esp32_ulp.c
77 ${PROJECT_DIR}/modesp32.c
Damien George9b908822020-09-23 15:55:55 +100078 ${PROJECT_DIR}/machine_hw_spi.c
79 ${PROJECT_DIR}/machine_wdt.c
80 ${PROJECT_DIR}/mpthreadport.c
81 ${PROJECT_DIR}/machine_rtc.c
82 ${PROJECT_DIR}/machine_sdcard.c
83)
84
85set(MICROPY_SOURCE_QSTR
86 ${MICROPY_SOURCE_PY}
87 ${MICROPY_SOURCE_EXTMOD}
Michael O'Cleirigh0ccd9e02021-03-27 17:10:39 -040088 ${MICROPY_SOURCE_USERMOD}
Damien George136369d2021-07-09 14:19:15 +100089 ${MICROPY_SOURCE_SHARED}
Damien George9b908822020-09-23 15:55:55 +100090 ${MICROPY_SOURCE_LIB}
91 ${MICROPY_SOURCE_PORT}
Damien Georgef046b502021-09-22 00:00:26 +100092 ${MICROPY_SOURCE_BOARD}
Damien George9b908822020-09-23 15:55:55 +100093)
94
95set(IDF_COMPONENTS
96 app_update
97 bootloader_support
Damien Georgeda2b5fa2021-02-14 01:36:30 +110098 bt
Damien George9b908822020-09-23 15:55:55 +100099 driver
Damien George9b908822020-09-23 15:55:55 +1000100 esp_common
101 esp_eth
102 esp_event
103 esp_ringbuf
104 esp_rom
105 esp_wifi
106 freertos
107 heap
108 log
109 lwip
110 mbedtls
111 mdns
112 newlib
113 nvs_flash
114 sdmmc
115 soc
116 spi_flash
117 tcpip_adapter
118 ulp
119 vfs
120 xtensa
121)
122
Damien Georged191d882021-02-15 21:00:01 +1100123if(IDF_VERSION_MINOR GREATER_EQUAL 1)
124 list(APPEND IDF_COMPONENTS esp_netif)
125endif()
126
Damien Georgea9150022021-02-15 21:00:09 +1100127if(IDF_VERSION_MINOR GREATER_EQUAL 2)
128 list(APPEND IDF_COMPONENTS esp_system)
129 list(APPEND IDF_COMPONENTS esp_timer)
130endif()
131
Damien George143372a2021-02-19 10:38:01 +1100132if(IDF_VERSION_MINOR GREATER_EQUAL 3)
133 list(APPEND IDF_COMPONENTS esp_hw_support)
134 list(APPEND IDF_COMPONENTS esp_pm)
135 list(APPEND IDF_COMPONENTS hal)
136endif()
137
Damien George66a86a02021-02-18 21:24:34 +1100138if(IDF_TARGET STREQUAL "esp32")
139 list(APPEND IDF_COMPONENTS esp32)
Damien George68235142021-07-18 12:11:21 +1000140elseif(IDF_TARGET STREQUAL "esp32c3")
141 list(APPEND IDF_COMPONENTS esp32c3)
142 list(APPEND IDF_COMPONENTS riscv)
Damien George66a86a02021-02-18 21:24:34 +1100143elseif(IDF_TARGET STREQUAL "esp32s2")
144 list(APPEND IDF_COMPONENTS esp32s2)
Damien Georgec81d0482021-02-19 12:08:11 +1100145 list(APPEND IDF_COMPONENTS tinyusb)
Damien George5093d492021-05-06 10:58:12 +1000146elseif(IDF_TARGET STREQUAL "esp32s3")
147 list(APPEND IDF_COMPONENTS esp32s3)
148 list(APPEND IDF_COMPONENTS tinyusb)
Damien George66a86a02021-02-18 21:24:34 +1100149endif()
150
Damien George9b908822020-09-23 15:55:55 +1000151# Register the main IDF component.
152idf_component_register(
153 SRCS
154 ${MICROPY_SOURCE_PY}
155 ${MICROPY_SOURCE_EXTMOD}
Damien George136369d2021-07-09 14:19:15 +1000156 ${MICROPY_SOURCE_SHARED}
Damien George9b908822020-09-23 15:55:55 +1000157 ${MICROPY_SOURCE_LIB}
158 ${MICROPY_SOURCE_DRIVERS}
159 ${MICROPY_SOURCE_PORT}
Damien Georgef046b502021-09-22 00:00:26 +1000160 ${MICROPY_SOURCE_BOARD}
Damien George9b908822020-09-23 15:55:55 +1000161 INCLUDE_DIRS
Damien George5dcc9b32021-04-09 00:59:16 +1000162 ${MICROPY_INC_CORE}
Michael O'Cleirigh0ccd9e02021-03-27 17:10:39 -0400163 ${MICROPY_INC_USERMOD}
Damien George9b908822020-09-23 15:55:55 +1000164 ${MICROPY_PORT_DIR}
165 ${MICROPY_BOARD_DIR}
166 ${CMAKE_BINARY_DIR}
167 REQUIRES
168 ${IDF_COMPONENTS}
169)
170
171# Set the MicroPython target as the current (main) IDF component target.
172set(MICROPY_TARGET ${COMPONENT_TARGET})
173
174# Define mpy-cross flags, for use with frozen code.
175set(MICROPY_CROSS_FLAGS -march=xtensawin)
176
177# Set compile options for this port.
178target_compile_definitions(${MICROPY_TARGET} PUBLIC
Damien Georgeab9d47e2021-04-08 23:56:28 +1000179 ${MICROPY_DEF_CORE}
Damien George9b908822020-09-23 15:55:55 +1000180 MICROPY_ESP_IDF_4=1
181 MICROPY_VFS_FAT=1
182 MICROPY_VFS_LFS2=1
183 FFCONF_H=\"${MICROPY_OOFATFS_DIR}/ffconf.h\"
184 LFS1_NO_MALLOC LFS1_NO_DEBUG LFS1_NO_WARN LFS1_NO_ERROR LFS1_NO_ASSERT
185 LFS2_NO_MALLOC LFS2_NO_DEBUG LFS2_NO_WARN LFS2_NO_ERROR LFS2_NO_ASSERT
186)
187
188# Disable some warnings to keep the build output clean.
189target_compile_options(${MICROPY_TARGET} PUBLIC
190 -Wno-clobbered
191 -Wno-deprecated-declarations
192 -Wno-missing-field-initializers
193)
194
Damien Georgeab9d47e2021-04-08 23:56:28 +1000195# Add additional extmod and usermod components.
196target_link_libraries(${MICROPY_TARGET} micropy_extmod_btree)
Michael O'Cleirigh0ccd9e02021-03-27 17:10:39 -0400197target_link_libraries(${MICROPY_TARGET} usermod)
198
199
Damien George9b908822020-09-23 15:55:55 +1000200# Collect all of the include directories and compile definitions for the IDF components.
201foreach(comp ${IDF_COMPONENTS})
Damien George0fabda32021-04-08 23:42:22 +1000202 micropy_gather_target_properties(__idf_${comp})
Damien George9b908822020-09-23 15:55:55 +1000203endforeach()
204
Damien Georgea9150022021-02-15 21:00:09 +1100205if(IDF_VERSION_MINOR GREATER_EQUAL 2)
206 # These paths cannot currently be found by the IDF_COMPONENTS search loop above,
207 # so add them explicitly.
208 list(APPEND MICROPY_CPP_INC_EXTRA ${IDF_PATH}/components/soc/soc/${IDF_TARGET}/include)
209 list(APPEND MICROPY_CPP_INC_EXTRA ${IDF_PATH}/components/soc/soc/include)
Damien Georgec81d0482021-02-19 12:08:11 +1100210 if(IDF_VERSION_MINOR GREATER_EQUAL 3)
211 list(APPEND MICROPY_CPP_INC_EXTRA ${IDF_PATH}/components/tinyusb/additions/include)
212 list(APPEND MICROPY_CPP_INC_EXTRA ${IDF_PATH}/components/tinyusb/tinyusb/src)
213 endif()
Damien Georgea9150022021-02-15 21:00:09 +1100214endif()
215
Damien George9b908822020-09-23 15:55:55 +1000216# Include the main MicroPython cmake rules.
217include(${MICROPY_DIR}/py/mkrules.cmake)