blob: 2455a4cdd2e94bf5b8b62a37e349c93427cd79e4 [file] [log] [blame]
Damien George9b908822020-09-23 15:55:55 +10001# Set location of base MicroPython directory.
2get_filename_component(MICROPY_DIR ${PROJECT_DIR}/../.. ABSOLUTE)
3
4# Include core source components.
5include(${MICROPY_DIR}/py/py.cmake)
6include(${MICROPY_DIR}/extmod/extmod.cmake)
7
8set(MICROPY_SOURCE_EXTMOD_EXTRA
9 ${MICROPY_DIR}/extmod/modonewire.c
10)
11
12set(MICROPY_SOURCE_LIB
13 ${MICROPY_DIR}/lib/littlefs/lfs1.c
14 ${MICROPY_DIR}/lib/littlefs/lfs1_util.c
15 ${MICROPY_DIR}/lib/littlefs/lfs2.c
16 ${MICROPY_DIR}/lib/littlefs/lfs2_util.c
17 ${MICROPY_DIR}/lib/mbedtls_errors/mp_mbedtls_errors.c
18 ${MICROPY_DIR}/lib/mp-readline/readline.c
19 ${MICROPY_DIR}/lib/netutils/netutils.c
20 ${MICROPY_DIR}/lib/oofatfs/ff.c
21 ${MICROPY_DIR}/lib/oofatfs/ffunicode.c
22 ${MICROPY_DIR}/lib/timeutils/timeutils.c
23 ${MICROPY_DIR}/lib/utils/interrupt_char.c
24 ${MICROPY_DIR}/lib/utils/stdout_helpers.c
25 ${MICROPY_DIR}/lib/utils/sys_stdio_mphal.c
26 ${MICROPY_DIR}/lib/utils/pyexec.c
27)
28
29set(MICROPY_SOURCE_DRIVERS
30 ${MICROPY_DIR}/drivers/bus/softspi.c
31 ${MICROPY_DIR}/drivers/dht/dht.c
32)
33
34set(MICROPY_SOURCE_PORT
35 ${PROJECT_DIR}/main.c
36 ${PROJECT_DIR}/uart.c
37 ${PROJECT_DIR}/gccollect.c
38 ${PROJECT_DIR}/mphalport.c
39 ${PROJECT_DIR}/fatfs_port.c
40 ${PROJECT_DIR}/help.c
41 ${PROJECT_DIR}/modutime.c
42 ${PROJECT_DIR}/moduos.c
43 ${PROJECT_DIR}/machine_timer.c
44 ${PROJECT_DIR}/machine_pin.c
45 ${PROJECT_DIR}/machine_touchpad.c
46 ${PROJECT_DIR}/machine_adc.c
47 ${PROJECT_DIR}/machine_dac.c
48 ${PROJECT_DIR}/machine_i2c.c
49 ${PROJECT_DIR}/machine_pwm.c
50 ${PROJECT_DIR}/machine_uart.c
51 ${PROJECT_DIR}/modmachine.c
52 ${PROJECT_DIR}/modnetwork.c
53 ${PROJECT_DIR}/network_lan.c
54 ${PROJECT_DIR}/network_ppp.c
55 ${PROJECT_DIR}/mpnimbleport.c
56 ${PROJECT_DIR}/modsocket.c
57 ${PROJECT_DIR}/modesp.c
58 ${PROJECT_DIR}/esp32_partition.c
59 ${PROJECT_DIR}/esp32_rmt.c
60 ${PROJECT_DIR}/esp32_ulp.c
61 ${PROJECT_DIR}/modesp32.c
62 ${PROJECT_DIR}/espneopixel.c
63 ${PROJECT_DIR}/machine_hw_spi.c
64 ${PROJECT_DIR}/machine_wdt.c
65 ${PROJECT_DIR}/mpthreadport.c
66 ${PROJECT_DIR}/machine_rtc.c
67 ${PROJECT_DIR}/machine_sdcard.c
68)
69
70set(MICROPY_SOURCE_QSTR
71 ${MICROPY_SOURCE_PY}
72 ${MICROPY_SOURCE_EXTMOD}
73 ${MICROPY_SOURCE_EXTMOD_EXTRA}
74 ${MICROPY_SOURCE_LIB}
75 ${MICROPY_SOURCE_PORT}
76)
77
78set(IDF_COMPONENTS
79 app_update
80 bootloader_support
Damien Georgeda2b5fa2021-02-14 01:36:30 +110081 bt
Damien George9b908822020-09-23 15:55:55 +100082 driver
83 esp32
84 esp_common
85 esp_eth
86 esp_event
87 esp_ringbuf
88 esp_rom
89 esp_wifi
90 freertos
91 heap
92 log
93 lwip
94 mbedtls
95 mdns
96 newlib
97 nvs_flash
98 sdmmc
99 soc
100 spi_flash
101 tcpip_adapter
102 ulp
103 vfs
104 xtensa
105)
106
Damien Georged191d882021-02-15 21:00:01 +1100107if(IDF_VERSION_MINOR GREATER_EQUAL 1)
108 list(APPEND IDF_COMPONENTS esp_netif)
109endif()
110
Damien George9b908822020-09-23 15:55:55 +1000111# Register the main IDF component.
112idf_component_register(
113 SRCS
114 ${MICROPY_SOURCE_PY}
115 ${MICROPY_SOURCE_EXTMOD}
116 ${MICROPY_SOURCE_EXTMOD_EXTRA}
117 ${MICROPY_SOURCE_LIB}
118 ${MICROPY_SOURCE_DRIVERS}
119 ${MICROPY_SOURCE_PORT}
120 INCLUDE_DIRS
121 ${MICROPY_DIR}
122 ${MICROPY_PORT_DIR}
123 ${MICROPY_BOARD_DIR}
124 ${CMAKE_BINARY_DIR}
125 REQUIRES
126 ${IDF_COMPONENTS}
127)
128
129# Set the MicroPython target as the current (main) IDF component target.
130set(MICROPY_TARGET ${COMPONENT_TARGET})
131
132# Define mpy-cross flags, for use with frozen code.
133set(MICROPY_CROSS_FLAGS -march=xtensawin)
134
135# Set compile options for this port.
136target_compile_definitions(${MICROPY_TARGET} PUBLIC
137 MICROPY_ESP_IDF_4=1
138 MICROPY_VFS_FAT=1
139 MICROPY_VFS_LFS2=1
140 FFCONF_H=\"${MICROPY_OOFATFS_DIR}/ffconf.h\"
141 LFS1_NO_MALLOC LFS1_NO_DEBUG LFS1_NO_WARN LFS1_NO_ERROR LFS1_NO_ASSERT
142 LFS2_NO_MALLOC LFS2_NO_DEBUG LFS2_NO_WARN LFS2_NO_ERROR LFS2_NO_ASSERT
143)
144
145# Disable some warnings to keep the build output clean.
146target_compile_options(${MICROPY_TARGET} PUBLIC
147 -Wno-clobbered
148 -Wno-deprecated-declarations
149 -Wno-missing-field-initializers
150)
151
152# Collect all of the include directories and compile definitions for the IDF components.
153foreach(comp ${IDF_COMPONENTS})
154 get_target_property(type __idf_${comp} TYPE)
155 set(_inc OFF)
156 set(_def OFF)
157 if(${type} STREQUAL STATIC_LIBRARY)
158 get_target_property(_inc __idf_${comp} INCLUDE_DIRECTORIES)
159 get_target_property(_def __idf_${comp} COMPILE_DEFINITIONS)
160 elseif(${type} STREQUAL INTERFACE_LIBRARY)
161 get_target_property(_inc __idf_${comp} INTERFACE_INCLUDE_DIRECTORIES)
162 get_target_property(_def __idf_${comp} INTERFACE_COMPILE_DEFINITIONS)
163 endif()
164 if(_inc)
165 list(APPEND MICROPY_CPP_INC_EXTRA ${_inc})
166 endif()
167 if(_def)
168 list(APPEND MICROPY_CPP_DEF_EXTRA ${_def})
169 endif()
170endforeach()
171
172# Include the main MicroPython cmake rules.
173include(${MICROPY_DIR}/py/mkrules.cmake)