cmake_minimum_required(VERSION 3.5)

# 设置LVGL相关路径
set(LVGL_DIR_NAME lvgl)
set(LVGL_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(LV_DRIVER_DIR_NAME lvgl_driver)

# 添加主源文件
set(MAINSRC
    lvgl_app.c
    VIF.c
    Menu.c
    updata_hzk.c
    Manu_str.c
    Manu_usr_str.c
    GBhzk22.c
    GBhzk30.c
    GBwryh40.c
    Interface_dat.c
    app_ch423.c
    UnicodetoGkb.c
    report_record.c
)

# 添加LVGL驱动源文件
set(LV_DRIVER_SRCS
    ${LVGL_DIR}/${LV_DRIVER_DIR_NAME}/fbdev.c
    ${LVGL_DIR}/${LV_DRIVER_DIR_NAME}/evdev.c
    ${LVGL_DIR}/${LV_DRIVER_DIR_NAME}/lv_fs_posix.c
    ${LVGL_DIR}/${LV_DRIVER_DIR_NAME}/lv_port_indev.c
)

# 递归收集LVGL核心源文件，但排除不需要的旧文件
file(GLOB_RECURSE LVGL_CORE_SRCS
    ${LVGL_DIR}/${LVGL_DIR_NAME}/src/*.c
)

# 排除不需要的旧文件（特别是lv_fs-bak.c）
list(FILTER LVGL_CORE_SRCS EXCLUDE REGEX ".*lv_fs-bak\\.c$")
list(FILTER LVGL_CORE_SRCS EXCLUDE REGEX ".*/bak/.*")  # 排除所有bak目录下的文件

# 创建静态库目标
add_library(lvgl_fdtu STATIC
    ${MAINSRC}
    ${LV_DRIVER_SRCS}
    ${LVGL_CORE_SRCS}
)

# 设置包含目录
target_include_directories(lvgl_fdtu PRIVATE
    ${LVGL_DIR}
    ${LVGL_DIR}/${LVGL_DIR_NAME}
    ${LVGL_DIR}/${LVGL_DIR_NAME}/src
    ${LVGL_DIR}/${LV_DRIVER_DIR_NAME}
)

# 设置编译选项
target_compile_options(lvgl_fdtu PRIVATE
    -fPIC
    -D__DEFAULT_SOURCE
    -D_BSD_SOURCE
    $<$<COMPILE_LANGUAGE:C>:-std=gnu99>
)

# 设置输出目录
set_target_properties(lvgl_fdtu PROPERTIES
    ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/archive
)

# 打印包含的文件列表用于调试
message(STATUS "Building lvgl_fdtu with source files:")
foreach(SRC ${MAINSRC} ${LV_DRIVER_SRCS} ${LVGL_CORE_SRCS})
    message(STATUS "  ${SRC}")
endforeach()