Skip to content

Commit

Permalink
fix(build): enable LV_CONF_PATH option
Browse files Browse the repository at this point in the history
This allows to set custom `lv_conf.h` file per board
in `mpconfigboard.(h,cmake)`
  • Loading branch information
Carglglz authored and pi-anl committed Jan 31, 2025
1 parent e88717b commit 3ac48fc
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
11 changes: 10 additions & 1 deletion micropython.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ idf_build_set_property(COMPILE_OPTIONS "-Wno-unused-function" APPEND)
idf_build_set_property(SRCS "${LV_SRC}" APPEND)
idf_build_set_property(INCLUDE_DIRS "${LV_INCLUDE}" APPEND)

# DEBUG LV_CONF_PATH
message(STATUS "LV_CONF_PATH=${LV_CONF_PATH}")

# Fix for idf 5.2.x
idf_build_get_property(component_targets __COMPONENT_TARGETS)
string(REPLACE "___idf_lvgl" "" component_targets "${component_targets}")
Expand Down Expand Up @@ -45,12 +48,18 @@ target_compile_options(lvgl_interface INTERFACE ${LV_CFLAGS})
add_library(usermod_lvgl INTERFACE)
target_sources(usermod_lvgl INTERFACE ${LV_SRC})
target_include_directories(usermod_lvgl INTERFACE ${LV_INCLUDE})

if (DEFINED LV_CONF_DIR)
target_include_directories(usermod_lvgl INTERFACE ${LV_CONF_DIR})
endif()

file(WRITE ${LV_MP} "")

target_link_libraries(usermod_lvgl INTERFACE lvgl_interface)

# # # make usermod (target declared by Micropython for all user compiled modules) link to bindings
# # # this way the bindings (and transitively lvgl_interface) get proper compilation flags
if (DEFINED LV_CONF_DIR)
target_include_directories(usermod INTERFACE ${LV_CONF_DIR})
endif()
target_compile_options(usermod INTERFACE -DLV_CONF_PATH=${LV_CONF_PATH})
target_link_libraries(usermod INTERFACE usermod_lvgl)
8 changes: 7 additions & 1 deletion micropython.mk
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,17 @@ LVGL_BINDING_DIR := $(USERMOD_DIR)
LVGL_DIR = $(LVGL_BINDING_DIR)/lvgl
LVGL_GENERIC_DRV_DIR = $(LVGL_BINDING_DIR)/driver/generic

ifeq ($(LV_CONF_PATH),)
LV_CONF_PATH = $(LVGL_BINDING_DIR)/lv_conf.h
endif
$(info LV_CONF_PATH is $(LV_CONF_PATH))
CFLAGS_USERMOD += "-DLV_CONF_PATH=<$(LV_CONF_PATH)>"

ifeq ($(wildcard $(LVGL_DIR)/.),,)
$(info lvgl submodule not init)
else
# This listing of all lvgl src files is used by make to track when the bindings need to be regenerated
ALL_LVGL_SRC = $(shell find $(LVGL_DIR) -type f -name '*.h') $(LVGL_BINDING_DIR)/lv_conf.h
ALL_LVGL_SRC = $(shell find $(LVGL_DIR) -type f -name '*.h') $(LV_CONF_PATH)
endif

LVGL_PP = $(BUILD)/lvgl/lvgl.pp.c
Expand Down
21 changes: 18 additions & 3 deletions mkrules_usermod.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ find_program(AWK awk mawk gawk)

set(LV_BINDINGS_DIR ${CMAKE_CURRENT_LIST_DIR})

# first check
if(NOT DEFINED LV_CONF_PATH)
set(LV_CONF_PATH ${LV_BINDINGS_DIR}/lv_conf.h)

message(STATUS "LV_CONF_PATH=${LV_CONF_PATH}")
endif()

# Common function for creating LV bindings

function(lv_bindings)
Expand All @@ -25,13 +32,15 @@ function(lv_bindings)
OUTPUT
${LV_PP}
COMMAND
${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}
${CMAKE_C_COMPILER} -E -DPYCPARSER -DLV_CONF_PATH=${LV_CONF_PATH} ${LV_COMPILE_OPTIONS} ${LV_PP_OPTIONS} "${LV_CFLAGS}" -I ${LV_BINDINGS_DIR}/pycparser/utils/fake_libc_include ${MICROPY_CPP_FLAGS} ${LV_INPUT} > ${LV_PP}
DEPENDS
${LV_INPUT}
${LV_DEPENDS}
${LV_BINDINGS_DIR}/pycparser/utils/fake_libc_include
IMPLICIT_DEPENDS
C ${LV_INPUT}
COMMENT
"LV_BINDINGS CPP"
VERBATIM
COMMAND_EXPAND_LISTS
)
Expand Down Expand Up @@ -60,6 +69,9 @@ function(lv_bindings)
${AWK} ${LV_AWK_COMMAND} ${LV_PP} > ${LV_PP_FILTERED}
DEPENDS
${LV_PP}

COMMENT
"LV_BINDINGS: FILTER"
VERBATIM
COMMAND_EXPAND_LISTS
)
Expand All @@ -71,10 +83,13 @@ function(lv_bindings)
OUTPUT
${LV_OUTPUT}
COMMAND
${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)
${Python3_EXECUTABLE} ${LV_BINDINGS_DIR}/gen/gen_mpy.py ${LV_GEN_OPTIONS} -DLV_CONF_PATH=${LV_CONF_PATH} -MD ${LV_MPY_METADATA} -E ${LV_PP_FILTERED} ${LV_INPUT} > ${LV_OUTPUT} || (rm -f ${LV_OUTPUT} && /bin/false)
DEPENDS
${LV_BINDINGS_DIR}/gen/gen_mpy.py
${LV_PP_FILTERED}

COMMENT
"LV_BINDINGS GEN MPY"
COMMAND_EXPAND_LISTS
)

Expand All @@ -95,7 +110,7 @@ function(all_lv_bindings)

# LVGL bindings

file(GLOB_RECURSE LVGL_HEADERS ${LVGL_DIR}/src/*.h ${LV_BINDINGS_DIR}/lv_conf.h)
file(GLOB_RECURSE LVGL_HEADERS ${LVGL_DIR}/src/*.h ${LV_CONF_PATH})
lv_bindings(
OUTPUT
${LV_MP}
Expand Down

0 comments on commit 3ac48fc

Please sign in to comment.