xmake交叉编译lvgl

  • 环境

# ubuntu:22.20 前置依赖
apt install build-essential git libreadline-dev ccache wget curl make file
# 目录可写 ~/.local/bin
# 配置到rc文件 source ~/.xmake/profile

# 32位程序兼容,好使用工具链
dpkg --add-architecture i386
apt update
apt install libc6:i386 libncurses5:i386 libstdc++6:i386 lib32z1 libbz2-1.0:i386

# 安装xmake
wget https://github.com/xmake-io/xmake/releases/download/v2.8.1/xmake-v2.8.1.xz.run
chmod 777 ./xmake-x.x.x.gz.run
./xmake-v2.8.1.xz.run

# 源码安装
git clone --recursive https://github.com/xmake-io/xmake.git
cd ./xmake
# On macOS, you may need to run: export SDKROOT=$(xcrun --sdk macosx --show-sdk-path)
./configure
make
./scripts/get.sh __local__ __install_only__
source ~/.xmake/profile
  • lvgl 编译, 创建 xmake.lua 文件

-- 自定义工具链
toolchain("mymips32")
    -- 标记为独立工具链
    set_kind("standalone")
    -- 定义交叉编译工具链地址
    set_sdkdir("/xuniji/mipseltools-gcc412-lnx26")
    add_linkdirs("/xuniji/mipseltools-gcc412-lnx26/lib")
    add_includedirs("/xuniji/mipseltools-gcc412-lnx26/include")
toolchain_end()


target("lvgl_fb.o")  -- 设置目标程序名字
    set_kind("binary")   -- 设置编译成二进制程序,不设置默认编译成二进制程序,可选择编译成动静态库等
    -- 设置使用的交叉编译工具链
    set_toolchains("mymips32")
    -- 设置平台
    set_plat("cross")
    -- 设置架构
    set_arch("mips")
    -- 设置链接的库
    -- add_links("m", "pthread", "ts");

    stdc = "c99"
    set_languages(stdc, "c++11")

    add_files("./*.c")

    -- 递归遍历获取所有子目录
    for _, dir in ipairs(os.dirs("lvgl/src/**")) do
        add_files(dir.."/*.c");
        add_includedirs(dir);
    end

    -- 递归遍历获取所有子目录
    for _, dir in ipairs(os.dirs("lvgl/demos/**")) do
        add_files(dir.."/*.c");   -- 添加目录下所有C文件
        add_includedirs(dir);  -- 添加目录作为头文件搜索路径
    end

    for _, v in ipairs(os.dirs("lv_drivers/**")) do
        add_files(v.."/*.c");
        add_includedirs(v);
    end

    add_includedirs(".")
    -- add_includedirs("/opt/tslib-1.21/include")
  • 执行

# 编译,打印
xmake -P . -v

file build/cross/mips/release/lvgl_fb.o

# 可以手动设置交叉编译工具链位置
xmake f -p cross --sdk=/xuniji/mipseltools-gcc412-lnx26
cat ./.xmake/linux/x86_64/xmake.conf