Using CMake to build LVGL project

I am trying to compile an application on Raspberry Pi using LVGL.
I have had success using the standard build system but would like to try using CMake.
I followed the instructions here: CMake — LVGL documentation

I use the the example CMake script that downloads LVGL from Github and the only change I made was to change main.c to main.cpp.

When I run CMake . I get the following error:

[ 11%] Performing download step (download, verify and extract) for 'lvgl-populate'
-- File already exists but no hash specified (use URL_HASH):
Old file will be removed and new file downloaded from URL.
-- Downloading...
-- Using src=''
-- [download 100% complete]
-- Downloading... done
-- extracting...
-- extracting... [tar xf]
CMake Error: Problem with archive_read_open_file(): Unrecognized archive format
CMake Error: Problem extracting tar: /home/pi/projects/cmake_lvgl/_deps/lvgl-subbuild/lvgl-populate-prefix/src/archive.tar
-- extracting... [error clean up]
CMake Error at lvgl-subbuild/lvgl-populate-prefix/src/lvgl-populate-stamp/extract-lvgl-populate.cmake:33 (message):
  error: extract of

gmake[2]: *** [CMakeFiles/lvgl-populate.dir/build.make:113: lvgl-populate-prefix/src/lvgl-populate-stamp/lvgl-populate-download] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:95: CMakeFiles/lvgl-populate.dir/all] Error 2
gmake: *** [Makefile:103: all] Error 2

CMake Error at /usr/share/cmake-3.18/Modules/FetchContent.cmake:987 (message):
  Build step for lvgl failed: 2
Call Stack (most recent call first):
  /usr/share/cmake-3.18/Modules/FetchContent.cmake:1082:EVAL:2 (__FetchContent_directPopulate)
  /usr/share/cmake-3.18/Modules/FetchContent.cmake:1082 (cmake_language)
  /usr/share/cmake-3.18/Modules/FetchContent.cmake:1125 (FetchContent_Populate)
  CMakeLists.txt:16 (FetchContent_MakeAvailable)

-- Configuring incomplete, errors occurred!

It would seem to suggest that the LVGL source on Github is downloaded as an archive and that the .tar file is corrupt !?

Can anyone help?


I had something similar and it was fixed by replacing the line
´FetchContent_Declare(lvgl URL
´FetchContent_Declare(lvgl GIT_REPOSITORY
in my CMakeLists.txt

Thank you, that worked for me :slight_smile:


I’ve just run into this as well. Is it possible to get the documentation (CMake — LVGL documentation) updated?


I’ve just noticed this topic and updated the docs:

Next time feel free to tag me if the docs needs to be updated or just send a PR.