|
| 1 | +cmake_minimum_required(VERSION 3.20.0) |
| 2 | + |
| 3 | +set(ZEPHYR_BOARD_ALIASES boards/board_aliases.cmake) |
| 4 | + |
| 5 | +find_package(Zephyr REQUIRED HINTS ../../lib/zephyr) |
| 6 | +project(circuitpython) |
| 7 | + |
| 8 | +target_sources(app PRIVATE zephyr_main.c) |
| 9 | + |
| 10 | +# From: https://github.com/zephyrproject-rtos/zephyr/blob/main/samples/application_development/external_lib/CMakeLists.txt |
| 11 | +# The external static library that we are linking with does not know |
| 12 | +# how to build for this platform so we export all the flags used in |
| 13 | +# this zephyr build to the external build system. |
| 14 | +# |
| 15 | +# Other external build systems may be self-contained enough that they |
| 16 | +# do not need any build information from zephyr. Or they may be |
| 17 | +# incompatible with certain zephyr options and need them to be |
| 18 | +# filtered out. |
| 19 | +zephyr_get_include_directories_for_lang_as_string( C includes) |
| 20 | +zephyr_get_system_include_directories_for_lang_as_string(C system_includes) |
| 21 | +zephyr_get_compile_definitions_for_lang_as_string( C definitions) |
| 22 | +zephyr_get_compile_options_for_lang_as_string( C options) |
| 23 | + |
| 24 | +if(DEFINED CMAKE_C_COMPILER_TARGET) |
| 25 | + set(target_flag "--target=${CMAKE_C_COMPILER_TARGET}") |
| 26 | +endif() |
| 27 | + |
| 28 | +set(external_project_cflags |
| 29 | + "${target_flag} ${includes} ${definitions} ${options} ${system_includes}" |
| 30 | + ) |
| 31 | + |
| 32 | +ExternalProject_Add(circuitpython |
| 33 | + DOWNLOAD_COMMAND "" |
| 34 | + CONFIGURE_COMMAND "" |
| 35 | + BUILD_COMMAND python ${CMAKE_CURRENT_SOURCE_DIR}/cptools/build_circuitpython.py |
| 36 | + CC=${CMAKE_C_COMPILER} |
| 37 | + AR=${CMAKE_AR} |
| 38 | + CFLAGS=${external_project_cflags} |
| 39 | + BOARD=${BOARD} |
| 40 | + BOARD_ALIAS=${BOARD_ALIAS} |
| 41 | + BOARD_REVISION=${BOARD_REVISION} |
| 42 | + BOARD_QUALIFIERS=${BOARD_QUALIFIERS} |
| 43 | + SOC_DIRECTORIES=${SOC_DIRECTORIES} |
| 44 | + OUTPUT_FILE=${CMAKE_CURRENT_BINARY_DIR}/libcircuitpython.a |
| 45 | + PORT_SRC_DIR=${CMAKE_CURRENT_SOURCE_DIR} |
| 46 | + BUILD_BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/libcircuitpython.a |
| 47 | + BUILD_JOB_SERVER_AWARE TRUE |
| 48 | + BUILD_ALWAYS TRUE |
| 49 | + DEPENDS zephyr |
| 50 | + INSTALL_COMMAND "" |
| 51 | + ) |
| 52 | + |
| 53 | +add_library(circuitpython_wrapper STATIC IMPORTED GLOBAL) |
| 54 | +add_dependencies( |
| 55 | + circuitpython_wrapper |
| 56 | + circuitpython |
| 57 | + ) |
| 58 | +set_target_properties(circuitpython_wrapper PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_BINARY_DIR}/libcircuitpython.a) |
| 59 | +target_link_libraries(circuitpython_wrapper INTERFACE kernel) |
| 60 | +target_link_libraries(app PRIVATE circuitpython_wrapper) |
0 commit comments