|
| 1 | +# Top-level cmake file for building MicroPython on ESP32. |
| 2 | + |
| 3 | +cmake_minimum_required(VERSION 3.12) |
| 4 | + |
| 5 | +execute_process(COMMAND bash -c "../shared/grab_submodules.sh" |
| 6 | + WORKING_DIRECTORY ".." |
| 7 | + OUTPUT_VARIABLE GIT_SUBMOD_RESULT) |
| 8 | + |
| 9 | +# We have to do some nasty stuff to get the LVGL MP submodule compiled |
| 10 | +# We generate a lvgl.pp.c file, which is just the compiler preprocessor running in this env |
| 11 | +execute_process(COMMAND bash -c "xtensa-esp32s3-elf-gcc -E -DLVGL_PREPROCESS -I ../../../lv_binding_micropython_tulip/pycparser/utils/fake_libc_include -I../../../lv_binding_micropython_tulip -I. -I../../../lv_binding_micropython_tulip/lvgl/src ../../../lv_binding_micropython_tulip/lvgl/lvgl.h > ../build/lvgl.pp.c" |
| 12 | + WORKING_DIRECTORY "." |
| 13 | + ) |
| 14 | + |
| 15 | +# Then we run a python script which generates a MP module for LVGL based on the source files (and your conf and stuff) |
| 16 | +# This gets compiled into Tulip |
| 17 | +execute_process(COMMAND bash -c "python3 ../../../lv_binding_micropython_tulip/gen/gen_mpy.py -M lvgl -MP lv -MD ../build/lv_mpy.json -E ../build/lvgl.pp.c ../../../lv_binding_micropython_tulip/lvgl/lvgl.h > ../build/lv_mpy.c" |
| 18 | + WORKING_DIRECTORY "." |
| 19 | + ) |
| 20 | + |
| 21 | +# We also have to copy over mpconfigport.h |
| 22 | +execute_process(COMMAND bash -c "cp ../mpconfigport.h ../../../micropython/ports/esp32/mpconfigport.h" WORKING_DIRECTORY ".") |
| 23 | + |
| 24 | +# Turn this on for debugging submodules |
| 25 | +#file(WRITE "submod" "${GIT_SUBMOD_RESULT}") |
| 26 | + |
| 27 | + |
| 28 | +# Set the board if it's not already set. |
| 29 | +if(NOT MICROPY_BOARD) |
| 30 | + set(MICROPY_BOARD TULIP4_R11) |
| 31 | +endif() |
| 32 | + |
| 33 | +# Set the board directory and check that it exists. |
| 34 | +if(NOT MICROPY_BOARD_DIR) |
| 35 | + set(MICROPY_BOARD_DIR ${CMAKE_CURRENT_LIST_DIR}/boards/${MICROPY_BOARD}) |
| 36 | +endif() |
| 37 | +if(NOT EXISTS ${MICROPY_BOARD_DIR}/mpconfigboard.cmake) |
| 38 | + message(FATAL_ERROR "Invalid MICROPY_BOARD specified: ${MICROPY_BOARD}") |
| 39 | +endif() |
| 40 | + |
| 41 | +# Define the output sdkconfig so it goes in the build directory. |
| 42 | +set(SDKCONFIG ${CMAKE_BINARY_DIR}/sdkconfig) |
| 43 | + |
| 44 | +# Save the manifest file set from the cmake command line. |
| 45 | +set(MICROPY_USER_FROZEN_MANIFEST ${MICROPY_FROZEN_MANIFEST}) |
| 46 | + |
| 47 | +# Include board config; this is expected to set (among other options): |
| 48 | +# - SDKCONFIG_DEFAULTS |
| 49 | +# - IDF_TARGET |
| 50 | +include(${MICROPY_BOARD_DIR}/mpconfigboard.cmake) |
| 51 | + |
| 52 | +# Set the frozen manifest file. Note if MICROPY_FROZEN_MANIFEST is set from the cmake |
| 53 | +# command line, then it will override the default and any manifest set by the board. |
| 54 | +if (MICROPY_USER_FROZEN_MANIFEST) |
| 55 | + set(MICROPY_FROZEN_MANIFEST ${MICROPY_USER_FROZEN_MANIFEST}) |
| 56 | +elseif (NOT MICROPY_FROZEN_MANIFEST) |
| 57 | + set(MICROPY_FROZEN_MANIFEST ${CMAKE_CURRENT_LIST_DIR}/boards/manifest.py) |
| 58 | +endif() |
| 59 | + |
| 60 | +# Concatenate all sdkconfig files into a combined one for the IDF to use. |
| 61 | +file(WRITE ${CMAKE_BINARY_DIR}/sdkconfig.combined.in "") |
| 62 | +foreach(SDKCONFIG_DEFAULT ${SDKCONFIG_DEFAULTS}) |
| 63 | + file(READ ${SDKCONFIG_DEFAULT} CONTENTS) |
| 64 | + file(APPEND ${CMAKE_BINARY_DIR}/sdkconfig.combined.in "${CONTENTS}") |
| 65 | +endforeach() |
| 66 | +configure_file(${CMAKE_BINARY_DIR}/sdkconfig.combined.in ${CMAKE_BINARY_DIR}/sdkconfig.combined COPYONLY) |
| 67 | +set(SDKCONFIG_DEFAULTS ${CMAKE_BINARY_DIR}/sdkconfig.combined) |
| 68 | + |
| 69 | +# Include main IDF cmake file. |
| 70 | +include($ENV{IDF_PATH}/tools/cmake/project.cmake) |
| 71 | + |
| 72 | +# Set the location of the main component for the project (one per target). |
| 73 | +#set(EXTRA_COMPONENT_DIRS main components) |
| 74 | + |
| 75 | +# Define the project. |
| 76 | +project(micropython) |
| 77 | +idf_build_set_property(COMPILE_OPTIONS "-fdiagnostics-color=always" APPEND) |
0 commit comments