|
| 1 | +# Check ESP-IDF version and error out if it is not in the supported range. |
| 2 | +# |
| 3 | +# Note for arduino-esp32 developers: to bypass the version check locally, |
| 4 | +# set ARDUINO_SKIP_IDF_VERSION_CHECK environment variable to 1. For example: |
| 5 | +# export ARDUINO_SKIP_IDF_VERSION_CHECK=1 |
| 6 | +# idf.py build |
| 7 | + |
| 8 | +set(min_supported_idf_version "5.1.0") |
| 9 | +set(max_supported_idf_version "5.1.99") |
| 10 | +set(idf_version "${IDF_VERSION_MAJOR}.${IDF_VERSION_MINOR}.${IDF_VERSION_PATCH}") |
| 11 | + |
| 12 | +if ("${idf_version}" AND NOT "$ENV{ARDUINO_SKIP_IDF_VERSION_CHECK}") |
| 13 | + if (idf_version VERSION_LESS min_supported_idf_version) |
| 14 | + message(FATAL_ERROR "Arduino-esp32 can be used with ESP-IDF versions " |
| 15 | + "between ${min_supported_idf_version} and ${max_supported_idf_version}, " |
| 16 | + "but an older version is detected: ${idf_version}.") |
| 17 | + endif() |
| 18 | + if (idf_version VERSION_GREATER max_supported_idf_version) |
| 19 | + message(FATAL_ERROR "Arduino-esp32 can be used with ESP-IDF versions " |
| 20 | + "between ${min_supported_idf_version} and ${max_supported_idf_version}, " |
| 21 | + "but a newer version is detected: ${idf_version}.") |
| 22 | + endif() |
| 23 | +endif() |
| 24 | + |
| 25 | +set(CORE_SRCS |
| 26 | + cores/esp32/base64.cpp |
| 27 | + cores/esp32/cbuf.cpp |
| 28 | + cores/esp32/chip-debug-report.cpp |
| 29 | + cores/esp32/esp32-hal-adc.c |
| 30 | + cores/esp32/esp32-hal-bt.c |
| 31 | + cores/esp32/esp32-hal-cpu.c |
| 32 | + cores/esp32/esp32-hal-dac.c |
| 33 | + cores/esp32/esp32-hal-gpio.c |
| 34 | + cores/esp32/esp32-hal-i2c.c |
| 35 | + cores/esp32/esp32-hal-i2c-slave.c |
| 36 | + cores/esp32/esp32-hal-ledc.c |
| 37 | + cores/esp32/esp32-hal-matrix.c |
| 38 | + cores/esp32/esp32-hal-misc.c |
| 39 | + cores/esp32/esp32-hal-periman.c |
| 40 | + cores/esp32/esp32-hal-psram.c |
| 41 | + cores/esp32/esp32-hal-rgb-led.c |
| 42 | + cores/esp32/esp32-hal-sigmadelta.c |
| 43 | + cores/esp32/esp32-hal-spi.c |
| 44 | + cores/esp32/esp32-hal-time.c |
| 45 | + cores/esp32/esp32-hal-timer.c |
| 46 | + cores/esp32/esp32-hal-tinyusb.c |
| 47 | + cores/esp32/esp32-hal-touch.c |
| 48 | + cores/esp32/esp32-hal-uart.c |
| 49 | + cores/esp32/esp32-hal-rmt.c |
| 50 | + cores/esp32/Esp.cpp |
| 51 | + cores/esp32/FunctionalInterrupt.cpp |
| 52 | + cores/esp32/HardwareSerial.cpp |
| 53 | + cores/esp32/HEXBuilder.cpp |
| 54 | + cores/esp32/IPAddress.cpp |
| 55 | + cores/esp32/libb64/cdecode.c |
| 56 | + cores/esp32/libb64/cencode.c |
| 57 | + cores/esp32/MacAddress.cpp |
| 58 | + cores/esp32/main.cpp |
| 59 | + cores/esp32/MD5Builder.cpp |
| 60 | + cores/esp32/Print.cpp |
| 61 | + cores/esp32/SHA1Builder.cpp |
| 62 | + cores/esp32/stdlib_noniso.c |
| 63 | + cores/esp32/Stream.cpp |
| 64 | + cores/esp32/StreamString.cpp |
| 65 | + cores/esp32/Tone.cpp |
| 66 | + cores/esp32/HWCDC.cpp |
| 67 | + cores/esp32/USB.cpp |
| 68 | + cores/esp32/USBCDC.cpp |
| 69 | + cores/esp32/USBMSC.cpp |
| 70 | + cores/esp32/FirmwareMSC.cpp |
| 71 | + cores/esp32/firmware_msc_fat.c |
| 72 | + cores/esp32/wiring_pulse.c |
| 73 | + cores/esp32/wiring_shift.c |
| 74 | + cores/esp32/WMath.cpp |
| 75 | + cores/esp32/WString.cpp |
| 76 | + ) |
| 77 | + |
| 78 | +set(ARDUINO_ALL_LIBRARIES |
| 79 | + ArduinoOTA |
| 80 | + AsyncUDP |
| 81 | + BLE |
| 82 | + BluetoothSerial |
| 83 | + DNSServer |
| 84 | + EEPROM |
| 85 | + ESP_I2S |
| 86 | + ESP_NOW |
| 87 | + ESPmDNS |
| 88 | + Ethernet |
| 89 | + FFat |
| 90 | + FS |
| 91 | + HTTPClient |
| 92 | + HTTPUpdate |
| 93 | + LittleFS |
| 94 | + NetBIOS |
| 95 | + Network |
| 96 | + PPP |
| 97 | + Preferences |
| 98 | + SD_MMC |
| 99 | + SD |
| 100 | + SimpleBLE |
| 101 | + SPIFFS |
| 102 | + SPI |
| 103 | + Ticker |
| 104 | + Update |
| 105 | + USB |
| 106 | + WebServer |
| 107 | + NetworkClientSecure |
| 108 | + WiFi |
| 109 | + WiFiProv |
| 110 | + Wire |
| 111 | + ) |
| 112 | + |
| 113 | +set(ARDUINO_LIBRARY_ArduinoOTA_SRCS libraries/ArduinoOTA/src/ArduinoOTA.cpp) |
| 114 | +set(ARDUINO_LIBRARY_ArduinoOTA_REQUIRES esp_https_ota) |
| 115 | + |
| 116 | +set(ARDUINO_LIBRARY_AsyncUDP_SRCS libraries/AsyncUDP/src/AsyncUDP.cpp) |
| 117 | + |
| 118 | +set(ARDUINO_LIBRARY_BluetoothSerial_SRCS |
| 119 | + libraries/BluetoothSerial/src/BluetoothSerial.cpp |
| 120 | + libraries/BluetoothSerial/src/BTAddress.cpp |
| 121 | + libraries/BluetoothSerial/src/BTAdvertisedDeviceSet.cpp |
| 122 | + libraries/BluetoothSerial/src/BTScanResultsSet.cpp) |
| 123 | + |
| 124 | +set(ARDUINO_LIBRARY_DNSServer_SRCS libraries/DNSServer/src/DNSServer.cpp) |
| 125 | + |
| 126 | +set(ARDUINO_LIBRARY_EEPROM_SRCS libraries/EEPROM/src/EEPROM.cpp) |
| 127 | + |
| 128 | +set(ARDUINO_LIBRARY_ESP_I2S_SRCS libraries/ESP_I2S/src/ESP_I2S.cpp) |
| 129 | + |
| 130 | +set(ARDUINO_LIBRARY_ESP_NOW_SRCS |
| 131 | + libraries/ESP_NOW/src/ESP32_NOW.cpp |
| 132 | + libraries/ESP_NOW/src/ESP32_NOW_Serial.cpp) |
| 133 | + |
| 134 | +set(ARDUINO_LIBRARY_ESPmDNS_SRCS libraries/ESPmDNS/src/ESPmDNS.cpp) |
| 135 | + |
| 136 | +set(ARDUINO_LIBRARY_Ethernet_SRCS libraries/Ethernet/src/ETH.cpp) |
| 137 | + |
| 138 | +set(ARDUINO_LIBRARY_FFat_SRCS libraries/FFat/src/FFat.cpp) |
| 139 | + |
| 140 | +set(ARDUINO_LIBRARY_FS_SRCS |
| 141 | + libraries/FS/src/FS.cpp |
| 142 | + libraries/FS/src/vfs_api.cpp) |
| 143 | + |
| 144 | +set(ARDUINO_LIBRARY_HTTPClient_SRCS libraries/HTTPClient/src/HTTPClient.cpp) |
| 145 | + |
| 146 | +set(ARDUINO_LIBRARY_HTTPUpdate_SRCS libraries/HTTPUpdate/src/HTTPUpdate.cpp) |
| 147 | + |
| 148 | +set(ARDUINO_LIBRARY_LittleFS_SRCS libraries/LittleFS/src/LittleFS.cpp) |
| 149 | + |
| 150 | +set(ARDUINO_LIBRARY_NetBIOS_SRCS libraries/NetBIOS/src/NetBIOS.cpp) |
| 151 | + |
| 152 | +set(ARDUINO_LIBRARY_PPP_SRCS |
| 153 | + libraries/PPP/src/PPP.cpp |
| 154 | + libraries/PPP/src/ppp.c) |
| 155 | + |
| 156 | +set(ARDUINO_LIBRARY_Preferences_SRCS libraries/Preferences/src/Preferences.cpp) |
| 157 | + |
| 158 | +set(ARDUINO_LIBRARY_SD_MMC_SRCS libraries/SD_MMC/src/SD_MMC.cpp) |
| 159 | + |
| 160 | +set(ARDUINO_LIBRARY_SD_SRCS |
| 161 | + libraries/SD/src/SD.cpp |
| 162 | + libraries/SD/src/sd_diskio.cpp |
| 163 | + libraries/SD/src/sd_diskio_crc.c) |
| 164 | + |
| 165 | +set(ARDUINO_LIBRARY_SimpleBLE_SRCS libraries/SimpleBLE/src/SimpleBLE.cpp) |
| 166 | + |
| 167 | +set(ARDUINO_LIBRARY_SPIFFS_SRCS libraries/SPIFFS/src/SPIFFS.cpp) |
| 168 | + |
| 169 | +set(ARDUINO_LIBRARY_SPI_SRCS libraries/SPI/src/SPI.cpp) |
| 170 | + |
| 171 | +set(ARDUINO_LIBRARY_Ticker_SRCS libraries/Ticker/src/Ticker.cpp) |
| 172 | + |
| 173 | +set(ARDUINO_LIBRARY_Update_SRCS |
| 174 | + libraries/Update/src/Updater.cpp |
| 175 | + libraries/Update/src/HttpsOTAUpdate.cpp) |
| 176 | + |
| 177 | +set(ARDUINO_LIBRARY_USB_SRCS |
| 178 | + libraries/USB/src/USBHID.cpp |
| 179 | + libraries/USB/src/USBMIDI.cpp |
| 180 | + libraries/USB/src/USBHIDMouse.cpp |
| 181 | + libraries/USB/src/USBHIDKeyboard.cpp |
| 182 | + libraries/USB/src/USBHIDGamepad.cpp |
| 183 | + libraries/USB/src/USBHIDConsumerControl.cpp |
| 184 | + libraries/USB/src/USBHIDSystemControl.cpp |
| 185 | + libraries/USB/src/USBHIDVendor.cpp |
| 186 | + libraries/USB/src/USBVendor.cpp) |
| 187 | + |
| 188 | +set(ARDUINO_LIBRARY_WebServer_SRCS |
| 189 | + libraries/WebServer/src/WebServer.cpp |
| 190 | + libraries/WebServer/src/Parsing.cpp |
| 191 | + libraries/WebServer/src/detail/mimetable.cpp) |
| 192 | + |
| 193 | +set(ARDUINO_LIBRARY_NetworkClientSecure_SRCS |
| 194 | + libraries/NetworkClientSecure/src/ssl_client.cpp |
| 195 | + libraries/NetworkClientSecure/src/NetworkClientSecure.cpp) |
| 196 | + |
| 197 | +set(ARDUINO_LIBRARY_Network_SRCS |
| 198 | + libraries/Network/src/NetworkInterface.cpp |
| 199 | + libraries/Network/src/NetworkEvents.cpp |
| 200 | + libraries/Network/src/NetworkManager.cpp |
| 201 | + libraries/Network/src/NetworkClient.cpp |
| 202 | + libraries/Network/src/NetworkServer.cpp |
| 203 | + libraries/Network/src/NetworkUdp.cpp) |
| 204 | + |
| 205 | +set(ARDUINO_LIBRARY_WiFi_SRCS |
| 206 | + libraries/WiFi/src/WiFiAP.cpp |
| 207 | + libraries/WiFi/src/WiFi.cpp |
| 208 | + libraries/WiFi/src/WiFiGeneric.cpp |
| 209 | + libraries/WiFi/src/WiFiMulti.cpp |
| 210 | + libraries/WiFi/src/WiFiScan.cpp |
| 211 | + libraries/WiFi/src/WiFiSTA.cpp |
| 212 | + libraries/WiFi/src/STA.cpp |
| 213 | + libraries/WiFi/src/AP.cpp) |
| 214 | + |
| 215 | +set(ARDUINO_LIBRARY_WiFiProv_SRCS libraries/WiFiProv/src/WiFiProv.cpp) |
| 216 | + |
| 217 | +set(ARDUINO_LIBRARY_Wire_SRCS libraries/Wire/src/Wire.cpp) |
| 218 | + |
| 219 | +set(ARDUINO_LIBRARY_BLE_SRCS |
| 220 | + libraries/BLE/src/BLE2901.cpp |
| 221 | + libraries/BLE/src/BLE2902.cpp |
| 222 | + libraries/BLE/src/BLE2904.cpp |
| 223 | + libraries/BLE/src/BLEAddress.cpp |
| 224 | + libraries/BLE/src/BLEAdvertisedDevice.cpp |
| 225 | + libraries/BLE/src/BLEAdvertising.cpp |
| 226 | + libraries/BLE/src/BLEBeacon.cpp |
| 227 | + libraries/BLE/src/BLECharacteristic.cpp |
| 228 | + libraries/BLE/src/BLECharacteristicMap.cpp |
| 229 | + libraries/BLE/src/BLEClient.cpp |
| 230 | + libraries/BLE/src/BLEDescriptor.cpp |
| 231 | + libraries/BLE/src/BLEDescriptorMap.cpp |
| 232 | + libraries/BLE/src/BLEDevice.cpp |
| 233 | + libraries/BLE/src/BLEEddystoneTLM.cpp |
| 234 | + libraries/BLE/src/BLEEddystoneURL.cpp |
| 235 | + libraries/BLE/src/BLEExceptions.cpp |
| 236 | + libraries/BLE/src/BLEHIDDevice.cpp |
| 237 | + libraries/BLE/src/BLERemoteCharacteristic.cpp |
| 238 | + libraries/BLE/src/BLERemoteDescriptor.cpp |
| 239 | + libraries/BLE/src/BLERemoteService.cpp |
| 240 | + libraries/BLE/src/BLEScan.cpp |
| 241 | + libraries/BLE/src/BLESecurity.cpp |
| 242 | + libraries/BLE/src/BLEServer.cpp |
| 243 | + libraries/BLE/src/BLEService.cpp |
| 244 | + libraries/BLE/src/BLEServiceMap.cpp |
| 245 | + libraries/BLE/src/BLEUtils.cpp |
| 246 | + libraries/BLE/src/BLEUUID.cpp |
| 247 | + libraries/BLE/src/BLEValue.cpp |
| 248 | + libraries/BLE/src/FreeRTOS.cpp |
| 249 | + libraries/BLE/src/GeneralUtils.cpp |
| 250 | + ) |
| 251 | + |
| 252 | +set(ARDUINO_LIBRARIES_SRCS) |
| 253 | +set(ARDUINO_LIBRARIES_REQUIRES) |
| 254 | +set(ARDUINO_LIBRARIES_INCLUDEDIRS) |
| 255 | +foreach(libname IN LISTS ARDUINO_ALL_LIBRARIES) |
| 256 | + if(NOT CONFIG_ARDUINO_SELECTIVE_COMPILATION OR CONFIG_ARDUINO_SELECTIVE_${libname}) |
| 257 | + if(ARDUINO_LIBRARY_${libname}_SRCS) |
| 258 | + list(APPEND ARDUINO_LIBRARIES_SRCS ${ARDUINO_LIBRARY_${libname}_SRCS}) |
| 259 | + endif() |
| 260 | + if(ARDUINO_LIBRARY_${libname}_REQUIRES) |
| 261 | + list(APPEND ARDUINO_LIBRARIES_REQUIRES ${ARDUINO_LIBRARY_${libname}_REQUIRES}) |
| 262 | + endif() |
| 263 | + if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/libraries/${libname}/src) |
| 264 | + list(APPEND ARDUINO_LIBRARIES_INCLUDEDIRS libraries/${libname}/src) |
| 265 | + endif() |
| 266 | + endif() |
| 267 | +endforeach() |
| 268 | + |
| 269 | +set(includedirs variants/${CONFIG_ARDUINO_VARIANT}/ cores/esp32/ ${ARDUINO_LIBRARIES_INCLUDEDIRS}) |
| 270 | +set(srcs ${CORE_SRCS} ${ARDUINO_LIBRARIES_SRCS}) |
| 271 | +set(priv_includes cores/esp32/libb64) |
| 272 | +set(requires spi_flash esp_partition mbedtls wpa_supplicant esp_adc esp_eth http_parser espressif__network_provisioning) |
| 273 | +set(priv_requires fatfs nvs_flash app_update spiffs bootloader_support bt esp_hid usb esp_psram ${ARDUINO_LIBRARIES_REQUIRES}) |
| 274 | + |
| 275 | +idf_component_register(INCLUDE_DIRS ${includedirs} PRIV_INCLUDE_DIRS ${priv_includes} SRCS ${srcs} REQUIRES ${requires} PRIV_REQUIRES ${priv_requires}) |
| 276 | + |
| 277 | +if(NOT CONFIG_FREERTOS_HZ EQUAL 1000 AND NOT "$ENV{ARDUINO_SKIP_TICK_CHECK}") |
| 278 | + # See delay() in cores/esp32/esp32-hal-misc.c. |
| 279 | + message(FATAL_ERROR "esp32-arduino requires CONFIG_FREERTOS_HZ=1000 " |
| 280 | + "(currently ${CONFIG_FREERTOS_HZ})") |
| 281 | +endif() |
| 282 | + |
| 283 | +string(TOUPPER ${CONFIG_ARDUINO_VARIANT} idf_target_caps) |
| 284 | +string(REPLACE "-" "_" idf_target_for_macro "${idf_target_caps}") |
| 285 | +target_compile_options(${COMPONENT_TARGET} PUBLIC |
| 286 | + -DARDUINO=10812 |
| 287 | + -DARDUINO_${idf_target_for_macro}_DEV |
| 288 | + -DARDUINO_ARCH_ESP32 |
| 289 | + -DARDUINO_BOARD="${idf_target_caps}_DEV" |
| 290 | + -DARDUINO_VARIANT="${CONFIG_ARDUINO_VARIANT}" |
| 291 | + -DESP32) |
| 292 | + |
| 293 | +if(CONFIG_AUTOSTART_ARDUINO) |
| 294 | + # in autostart mode, arduino-esp32 contains app_main() function and needs to |
| 295 | + # reference setup() and loop() in the main component. If we add main |
| 296 | + # component to priv_requires then we create a large circular dependency |
| 297 | + # (arduino-esp32 -> main -> arduino-esp32) and can get linker errors, so |
| 298 | + # instead we add setup() and loop() to the undefined symbols list so the |
| 299 | + # linker will always include them. |
| 300 | + # |
| 301 | + # (As they are C++ symbol, we need to add the C++ mangled names.) |
| 302 | + target_link_libraries(${COMPONENT_LIB} INTERFACE "-u _Z5setupv -u _Z4loopv") |
| 303 | +endif() |
| 304 | + |
| 305 | +# This function adds a dependency on the given component if the component is included into the build. |
| 306 | +function(maybe_add_component component_name) |
| 307 | + idf_build_get_property(components BUILD_COMPONENTS) |
| 308 | + if (${component_name} IN_LIST components) |
| 309 | + idf_component_get_property(lib_name ${component_name} COMPONENT_LIB) |
| 310 | + target_link_libraries(${COMPONENT_LIB} PUBLIC ${lib_name}) |
| 311 | + endif() |
| 312 | +endfunction() |
| 313 | + |
| 314 | +if(IDF_TARGET MATCHES "esp32s2|esp32s3" AND CONFIG_TINYUSB_ENABLED) |
| 315 | + maybe_add_component(arduino_tinyusb) |
| 316 | +endif() |
| 317 | +if(NOT CONFIG_ARDUINO_SELECTIVE_COMPILATION OR CONFIG_ARDUINO_SELECTIVE_ArduinoOTA) |
| 318 | + maybe_add_component(esp_https_ota) |
| 319 | +endif() |
0 commit comments