|
1 | 1 | # SPDX-License-Identifier: Apache-2.0
|
2 | 2 |
|
3 |
| -if (IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/variants/${BOARD}) |
4 |
| - set(variant_dir variants/${BOARD}) |
5 |
| -elseif (IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/variants/${BOARD}${NORMALIZED_BOARD_QUALIFIERS}) |
6 |
| - set(variant_dir variants/${BOARD}${NORMALIZED_BOARD_QUALIFIERS}) |
7 |
| -else() |
8 |
| - message(FATAL_ERROR "Variant dir not found: variants/${BOARD}, variants/${BOARD}${NORMALIZED_BOARD_QUALIFIERS}") |
9 |
| -endif() |
10 | 3 |
|
11 | 4 | if (CONFIG_ARDUINO_API)
|
12 |
| -add_subdirectory(cores) |
13 |
| -add_subdirectory(libraries) |
14 |
| -zephyr_include_directories(${variant_dir}) |
| 5 | + |
| 6 | +function(arduino_sources) |
| 7 | + if (IS_DIRECTORY ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/variants/${BOARD}) |
| 8 | + set(variant_dir variants/${BOARD}) |
| 9 | + elseif (IS_DIRECTORY ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/variants/${BOARD}${NORMALIZED_BOARD_QUALIFIERS}) |
| 10 | + set(variant_dir variants/${BOARD}${NORMALIZED_BOARD_QUALIFIERS}) |
| 11 | + else() |
| 12 | + message(FATAL_ERROR "Variant dir not found: variants/${BOARD}, variants/${BOARD}${NORMALIZED_BOARD_QUALIFIERS}") |
| 13 | + endif() |
| 14 | + |
| 15 | + set(ext_name arduino) |
| 16 | + set(ext_bin ${ZEPHYR_BINARY_DIR}/${ext_name}.llext) |
| 17 | + set(ext_inc ${ZEPHYR_BINARY_DIR}/include/generated/${ext_name}_ext.inc) |
| 18 | + |
| 19 | + set(core_srcs |
| 20 | + ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/cores/arduino/module_export.c |
| 21 | + ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/cores/arduino/zephyrPrint.cpp |
| 22 | + ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/cores/arduino/zephyrSerial.cpp |
| 23 | + ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/cores/arduino/zephyrCommon.cpp |
| 24 | + ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/cores/arduino/main.cpp |
| 25 | + ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/cores/arduino/api/String.cpp |
| 26 | + ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/cores/arduino/api/Stream.cpp |
| 27 | + ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/cores/arduino/api/Common.cpp |
| 28 | + ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/cores/arduino/api/Print.cpp |
| 29 | + ) |
| 30 | + |
| 31 | + if (CONFIG_SPI) |
| 32 | + list(APPEND core_srcs ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/libraries/SPI/SPI.cpp) |
| 33 | + endif() |
| 34 | + |
| 35 | + if (CONFIG_I2C) |
| 36 | + list(APPEND core_srcs ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/libraries/Wire/Wire.cpp) |
| 37 | + endif() |
| 38 | + |
| 39 | + if (CONFIG_CAN) |
| 40 | + list(APPEND core_srcs ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/cores/arduino/api/CanMsgRingbuffer.cpp |
| 41 | + ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/cores/arduino/api/CanMsg.cpp) |
| 42 | + endif() |
| 43 | + |
| 44 | + if (CONFIG_USB) |
| 45 | + list(APPEND core_srcs ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/cores/arduino/api/PluggableUSB.cpp) |
| 46 | + endif() |
| 47 | + |
| 48 | + if (CONFIG_NET_IP) |
| 49 | + list(APPEND core_srcs ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/cores/arduino/api/IPAddress.cpp) |
| 50 | + endif() |
| 51 | + |
| 52 | + add_llext_target(${ext_name}_ext |
| 53 | + OUTPUT ${ext_bin} |
| 54 | + SOURCES |
| 55 | + ${core_srcs} |
| 56 | + ${ARGV} |
| 57 | + ) |
| 58 | + |
| 59 | + llext_include_directories(${ext_name}_ext |
| 60 | + ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/cores/arduino/ |
| 61 | + ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/cores/arduino/api/ |
| 62 | + ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/libraries/SPI/ |
| 63 | + ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/libraries/Wire/ |
| 64 | + ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/${variant_dir} |
| 65 | + ) |
| 66 | + |
| 67 | + generate_inc_file_for_target(app ${ext_bin} ${ext_inc}) |
| 68 | +endfunction() |
| 69 | + |
| 70 | + if(DEFINED CONFIG_ARDUINO_ENTRY) |
| 71 | + target_sources(app PRIVATE cores/arduino/main_loader.c) |
| 72 | + endif() |
| 73 | + |
15 | 74 | endif()
|
16 | 75 |
|
0 commit comments