mirror of
https://github.com/lvgl/lvgl.git
synced 2026-09-28 16:10:54 +08:00
arch(cmake): add native Kconfig support to cmake (#7934)
This commit is contained in:
@@ -8,6 +8,13 @@ option(LV_LVGL_H_INCLUDE_SIMPLE
|
||||
option(LV_CONF_INCLUDE_SIMPLE
|
||||
"Use #include \"lv_conf.h\" instead of #include \"../../lv_conf.h\"" ON)
|
||||
|
||||
set(LV_KCONFIG_IGNORE "Don't use Kconfig. Kconfig is not used by default." ON)
|
||||
|
||||
find_package(Python REQUIRED)
|
||||
|
||||
option(LV_CONF_SKIP "Skip including lv_conf.h during configuration" OFF)
|
||||
option(LV_USE_KCONFIG "Use Kconfig to configure LVGL" OFF)
|
||||
|
||||
# Option LV_CONF_PATH, which should be the path for lv_conf.h
|
||||
# If set parent path LV_CONF_DIR is added to includes
|
||||
if( LV_CONF_PATH )
|
||||
@@ -27,12 +34,63 @@ file(GLOB_RECURSE THORVG_SOURCES ${LVGL_ROOT_DIR}/src/libs/thorvg/*.cpp ${LVGL_R
|
||||
add_library(lvgl ${SOURCES})
|
||||
add_library(lvgl::lvgl ALIAS lvgl)
|
||||
|
||||
if ( LV_USE_KCONFIG )
|
||||
# kconfig.cmake will generate the .config
|
||||
# and autoconf.h, which will be used by lv_conf_kconfig.h
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/kconfig.cmake)
|
||||
|
||||
set(LV_KCONFIG_IGNORE OFF)
|
||||
# Set the flag to specify we are using kconfig, needed for the
|
||||
# generate_cmake_variables.py script
|
||||
set(KCONFIG_FLAG --kconfig)
|
||||
# If using Kconfig, we need to define additional definitions
|
||||
set(PCPP_ADDITIONAL_DEFS "--defs" "LV_CONF_SKIP" "LV_CONF_KCONFIG_EXTERNAL_INCLUDE=\"${LV_CONF_KCONFIG_EXTERNAL_INCLUDE}\"")
|
||||
else()
|
||||
if (LV_CONF_PATH)
|
||||
set(PCPP_ADDITIONAL_DEFS "--defs" "LV_CONF_PATH=\"${LV_CONF_PATH}\"")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
target_compile_definitions(
|
||||
lvgl PUBLIC $<$<BOOL:${LV_LVGL_H_INCLUDE_SIMPLE}>:LV_LVGL_H_INCLUDE_SIMPLE>
|
||||
$<$<BOOL:${LV_CONF_INCLUDE_SIMPLE}>:LV_CONF_INCLUDE_SIMPLE>)
|
||||
$<$<BOOL:${LV_CONF_INCLUDE_SIMPLE}>:LV_CONF_INCLUDE_SIMPLE>
|
||||
$<$<BOOL:${LV_KCONFIG_IGNORE}>:LV_KCONFIG_IGNORE>
|
||||
$<$<BOOL:${LV_CONF_SKIP}>:LV_CONF_SKIP>
|
||||
)
|
||||
|
||||
# Use the portable pcpp to preprocess lv_conf_internal.h
|
||||
execute_process(
|
||||
COMMAND ${Python_EXECUTABLE} ${LVGL_ROOT_DIR}/scripts/preprocess_lv_conf_internal.py
|
||||
--input ${LVGL_ROOT_DIR}/src/lv_conf_internal.h
|
||||
--tmp_file ${CMAKE_CURRENT_BINARY_DIR}/tmp.h
|
||||
--output ${CMAKE_CURRENT_BINARY_DIR}/lv_conf_expanded.h
|
||||
${PCPP_ADDITIONAL_DEFS}
|
||||
--include ${LVGL_ROOT_DIR} ${LVGL_ROOT_DIR}/.. ${LVGL_ROOT_DIR}/src ${LV_CONF_DIR}
|
||||
RESULT_VARIABLE ret
|
||||
)
|
||||
if(NOT "${ret}" STREQUAL "0")
|
||||
message(FATAL_ERROR "preprocess_lv_conf_internal.py failed with return code: ${ret}")
|
||||
endif()
|
||||
|
||||
# Convert the expanded lv_conf_expanded.h to cmake variables
|
||||
execute_process(
|
||||
COMMAND ${Python_EXECUTABLE}
|
||||
${LVGL_ROOT_DIR}/scripts/generate_cmake_variables.py
|
||||
--input ${CMAKE_CURRENT_BINARY_DIR}/lv_conf_expanded.h
|
||||
--output ${CMAKE_CURRENT_BINARY_DIR}/lv_conf.cmake
|
||||
${KCONFIG_FLAG}
|
||||
RESULT_VARIABLE ret
|
||||
)
|
||||
if(NOT "${ret}" STREQUAL "0")
|
||||
message(FATAL_ERROR "generate_cmake_variables.py command failed with return code: ${ret}")
|
||||
endif()
|
||||
|
||||
# This will set all CONFIG_LV_USE_* variables in cmake
|
||||
include(${CMAKE_BINARY_DIR}/lv_conf.cmake)
|
||||
|
||||
# Add definition of LV_CONF_PATH only if needed
|
||||
if(LV_CONF_PATH)
|
||||
# Do not redefine it if already defined in tests/CMakeLists.txt
|
||||
if(LV_CONF_PATH AND NOT LV_BUILD_TEST)
|
||||
target_compile_definitions(lvgl PUBLIC LV_CONF_PATH=${LV_CONF_PATH})
|
||||
endif()
|
||||
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
set(PROJECT_ROOT ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
set(KCONFIG_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/Kconfig)
|
||||
set(AUTOCONF_H ${CMAKE_CURRENT_BINARY_DIR}/autoconf.h)
|
||||
set(OUTPUT_DOTCONFIG ${CMAKE_CURRENT_SOURCE_DIR}/.config)
|
||||
set(KCONFIG_LIST_OUT ${CMAKE_CURRENT_BINARY_DIR}/kconfig_list)
|
||||
set(AUTO_CONF_DIR ${CMAKE_CURRENT_BINARY_DIR})
|
||||
|
||||
# Check if the user want to use a defconfig, using the -DLV_DEFCONFIG_PATH option
|
||||
if(LV_DEFCONFIG_PATH)
|
||||
set(DOTCONFIG ${LV_DEFCONFIG_PATH})
|
||||
else()
|
||||
set(DOTCONFIG ${CMAKE_CURRENT_SOURCE_DIR}/.config)
|
||||
endif()
|
||||
|
||||
execute_process(
|
||||
COMMAND ${Python_EXECUTABLE}
|
||||
${LVGL_ROOT_DIR}/scripts/kconfig.py
|
||||
${LVGL_ROOT_DIR}/Kconfig
|
||||
${OUTPUT_DOTCONFIG}
|
||||
${AUTOCONF_H}
|
||||
${KCONFIG_LIST_OUT}
|
||||
${DOTCONFIG}
|
||||
WORKING_DIRECTORY ${LVGL_ROOT_DIR}
|
||||
# The working directory is set to the app dir such that the user
|
||||
# can use relative paths in CONF_FILE, e.g. CONF_FILE=nrf5.conf
|
||||
RESULT_VARIABLE ret
|
||||
)
|
||||
if(NOT "${ret}" STREQUAL "0")
|
||||
message(FATAL_ERROR "command failed with return code: ${ret}")
|
||||
endif()
|
||||
|
||||
# Re-configure (Re-execute all CMakeLists.txt code) when autoconf.h changes
|
||||
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${AUTOCONF_H})
|
||||
|
||||
# Set compile definitions for lvgl build
|
||||
add_compile_definitions(LV_CONF_KCONFIG_EXTERNAL_INCLUDE="${AUTOCONF_H}")
|
||||
# Set the variable that can be used by the CMakeLists.txt including this file
|
||||
set(LV_CONF_KCONFIG_EXTERNAL_INCLUDE "${AUTOCONF_H}")
|
||||
|
||||
# Ensure LV_DEFCONFIG_PATH is not set in the path, to be able to call it without
|
||||
# the -DLV_DEFCONFIG_PATH after the first configuration, and to work with the .config
|
||||
unset(LV_DEFCONFIG_PATH CACHE)
|
||||
Reference in New Issue
Block a user