|
| 1 | + |
| 2 | + |
| 3 | +find_package(Python3 REQUIRED COMPONENTS Interpreter) |
| 4 | +find_program(AWK awk mawk gawk) |
| 5 | + |
| 6 | +set(LV_BINDINGS_DIR ${CMAKE_CURRENT_LIST_DIR}) |
| 7 | + |
| 8 | +# Common function for creating LV bindings |
| 9 | + |
| 10 | +function(lv_bindings) |
| 11 | + set(_options) |
| 12 | + set(_one_value_args OUTPUT) |
| 13 | + set(_multi_value_args INPUT DEPENDS COMPILE_OPTIONS PP_OPTIONS GEN_OPTIONS FILTER) |
| 14 | + cmake_parse_arguments( |
| 15 | + PARSE_ARGV 0 LV |
| 16 | + "${_options}" |
| 17 | + "${_one_value_args}" |
| 18 | + "${_multi_value_args}" |
| 19 | + ) |
| 20 | + |
| 21 | + set(LV_PP ${LV_OUTPUT}.pp) |
| 22 | + set(LV_MPY_METADATA ${LV_OUTPUT}.json) |
| 23 | + |
| 24 | + add_custom_command( |
| 25 | + OUTPUT |
| 26 | + ${LV_PP} |
| 27 | + COMMAND |
| 28 | + ${CMAKE_C_COMPILER} -E -DPYCPARSER ${LV_COMPILE_OPTIONS} ${LV_PP_OPTIONS} "${LV_CFLAGS}" -I ${LV_BINDINGS_DIR}/pycparser/utils/fake_libc_include ${MICROPY_CPP_FLAGS} ${LV_INPUT} > ${LV_PP} |
| 29 | + DEPENDS |
| 30 | + ${LV_INPUT} |
| 31 | + ${LV_DEPENDS} |
| 32 | + ${LV_BINDINGS_DIR}/pycparser/utils/fake_libc_include |
| 33 | + IMPLICIT_DEPENDS |
| 34 | + C ${LV_INPUT} |
| 35 | + VERBATIM |
| 36 | + COMMAND_EXPAND_LISTS |
| 37 | + ) |
| 38 | + |
| 39 | + # if(ESP_PLATFORM) |
| 40 | + # target_compile_options(${COMPONENT_LIB} PRIVATE ${LV_COMPILE_OPTIONS}) |
| 41 | + # else() |
| 42 | + # target_compile_options(usermod_lv_bindings INTERFACE ${LV_COMPILE_OPTIONS}) |
| 43 | + # endif() |
| 44 | + |
| 45 | + if (DEFINED LV_FILTER) |
| 46 | + |
| 47 | + set(LV_PP_FILTERED ${LV_PP}.filtered) |
| 48 | + set(LV_AWK_CONDITION) |
| 49 | + foreach(_f ${LV_FILTER}) |
| 50 | + string(APPEND LV_AWK_CONDITION "\$3!~\"${_f}\" && ") |
| 51 | + endforeach() |
| 52 | + string(APPEND LV_AWK_COMMAND "\$1==\"#\"{p=(${LV_AWK_CONDITION} 1)} p{print}") |
| 53 | + |
| 54 | + # message("AWK COMMAND: ${LV_AWK_COMMAND}") |
| 55 | + |
| 56 | + add_custom_command( |
| 57 | + OUTPUT |
| 58 | + ${LV_PP_FILTERED} |
| 59 | + COMMAND |
| 60 | + ${AWK} ${LV_AWK_COMMAND} ${LV_PP} > ${LV_PP_FILTERED} |
| 61 | + DEPENDS |
| 62 | + ${LV_PP} |
| 63 | + VERBATIM |
| 64 | + COMMAND_EXPAND_LISTS |
| 65 | + ) |
| 66 | + else() |
| 67 | + set(LV_PP_FILTERED ${LV_PP}) |
| 68 | + endif() |
| 69 | + |
| 70 | + add_custom_command( |
| 71 | + OUTPUT |
| 72 | + ${LV_OUTPUT} |
| 73 | + COMMAND |
| 74 | + ${Python3_EXECUTABLE} ${LV_BINDINGS_DIR}/gen/gen_mpy.py ${LV_GEN_OPTIONS} -MD ${LV_MPY_METADATA} -E ${LV_PP_FILTERED} ${LV_INPUT} > ${LV_OUTPUT} || (rm -f ${LV_OUTPUT} && /bin/false) |
| 75 | + DEPENDS |
| 76 | + ${LV_BINDINGS_DIR}/gen/gen_mpy.py |
| 77 | + ${LV_PP_FILTERED} |
| 78 | + COMMAND_EXPAND_LISTS |
| 79 | + ) |
| 80 | + |
| 81 | +endfunction() |
| 82 | + |
| 83 | +# Definitions for specific bindings |
| 84 | + |
| 85 | +set(LVGL_DIR ${LV_BINDINGS_DIR}/lvgl) |
| 86 | + |
| 87 | +set(LV_MP ${CMAKE_BINARY_DIR}/lv_mp.c) |
| 88 | +# if(ESP_PLATFORM) |
| 89 | +# set(LV_ESPIDF ${CMAKE_BINARY_DIR}/lv_espidf.c) |
| 90 | +# endif() |
| 91 | + |
| 92 | +# Function for creating all specific bindings |
| 93 | + |
| 94 | +function(all_lv_bindings) |
| 95 | + |
| 96 | + # LVGL bindings |
| 97 | + |
| 98 | + file(GLOB_RECURSE LVGL_HEADERS ${LVGL_DIR}/src/*.h ${LV_BINDINGS_DIR}/lv_conf.h) |
| 99 | + lv_bindings( |
| 100 | + OUTPUT |
| 101 | + ${LV_MP} |
| 102 | + INPUT |
| 103 | + ${LVGL_DIR}/lvgl.h |
| 104 | + DEPENDS |
| 105 | + ${LVGL_HEADERS} |
| 106 | + GEN_OPTIONS |
| 107 | + -M lvgl -MP lv |
| 108 | + ) |
| 109 | + |
| 110 | + |
| 111 | + # ESPIDF bindings |
| 112 | + |
| 113 | + # if(ESP_PLATFORM) |
| 114 | + # file(GLOB_RECURSE LV_ESPIDF_HEADERS ${IDF_PATH}/components/*.h ${LV_BINDINGS_DIR}/driver/esp32/*.h) |
| 115 | + # lv_bindings( |
| 116 | + # OUTPUT |
| 117 | + # ${LV_ESPIDF} |
| 118 | + # INPUT |
| 119 | + # ${LV_BINDINGS_DIR}/driver/esp32/espidf.h |
| 120 | + # DEPENDS |
| 121 | + # ${LV_ESPIDF_HEADERS} |
| 122 | + # GEN_OPTIONS |
| 123 | + # -M espidf |
| 124 | + # FILTER |
| 125 | + # i2s_ll.h |
| 126 | + # i2s_hal.h |
| 127 | + # esp_intr_alloc.h |
| 128 | + # soc/spi_periph.h |
| 129 | + # rom/ets_sys.h |
| 130 | + # soc/sens_struct.h |
| 131 | + # soc/rtc.h |
| 132 | + # driver/periph_ctrl.h |
| 133 | + # ) |
| 134 | + # endif(ESP_PLATFORM) |
| 135 | + |
| 136 | +endfunction() |
| 137 | + |
| 138 | +# Add includes to CMake component |
| 139 | + |
| 140 | +set(LV_INCLUDE |
| 141 | + ${LV_BINDINGS_DIR} |
| 142 | +) |
| 143 | + |
| 144 | +# Add sources to CMake component |
| 145 | + |
| 146 | +set(LV_SRC |
| 147 | + ${LV_MP} |
| 148 | +) |
| 149 | + |
| 150 | +# if(ESP_PLATFORM) |
| 151 | +# LIST(APPEND LV_SRC |
| 152 | +# ${LV_BINDINGS_DIR}/driver/esp32/espidf.c |
| 153 | +# ${LV_BINDINGS_DIR}/driver/esp32/modrtch.c |
| 154 | +# ${LV_BINDINGS_DIR}/driver/esp32/sh2lib.c |
| 155 | +# ${LV_ESPIDF} |
| 156 | +# ) |
| 157 | +# endif(ESP_PLATFORM) |
0 commit comments