CMake
How to build and integrate the CMake project that the LVGL Pro Editor generates when you export C code.
Overview
When you export C code, the Editor generates a small set of CMake files next to your UI so it can be dropped into any CMake-based build. The exported code is built as a library target called lib-ui that you link into your application.
| File | Edit it? | Purpose |
|---|---|---|
CMakeLists.txt | No | Builds the lib-ui library from your UI sources. Regenerated on every export. |
file_list_gen.cmake | No | The generated list of all .c files (screens, components, fonts, images, generated code). Regenerated on every export. |
component_lib_list_gen.cmake | No | Generated list of component/widget sub-libraries, when your project uses them. |
user_config.cmake | Yes | The one file meant for you — add your own source files here. It is never overwritten. |
CMakeLists.txt, file_list_gen.cmake, and component_lib_list_gen.cmake are regenerated every time you export, so don't edit them. Put anything of your own in user_config.cmake.
Adding the UI to your project
The generated CMakeLists.txt expects an lvgl target to already exist so it can link against it and use its lv_conf.h. In your application's CMake, create/fetch LVGL first, then add the exported UI folder and link lib-ui:
# 1. Make an `lvgl` target available (FetchContent, add_subdirectory, a package, ...)
include(FetchContent)
FetchContent_Declare(lvgl
GIT_REPOSITORY https://github.com/lvgl/lvgl.git
GIT_TAG v9.5.0)
FetchContent_MakeAvailable(lvgl)
# 2. Add the exported UI. It builds a `lib-ui` target.
add_subdirectory(ui)
# 3. The generated code uses `#include "lvgl.h"`, so enable simple includes.
target_compile_definitions(lib-ui PUBLIC LV_LVGL_H_INCLUDE_SIMPLE)
# 4. Link it into your application.
target_link_libraries(my_app PRIVATE lib-ui lvgl)If the UI folder is outside your source tree, give add_subdirectory a binary dir:
add_subdirectory(${UI_DIR} ${CMAKE_BINARY_DIR}/ui)lib-ui exports the UI folder as a public include directory, so your application can include the generated header and call the init function:
#include "my_project.h" /* "<project name>.h" from project.xml */
my_project_init("A:ui"); /* asset path for file-based images/fonts */
lv_screen_load(home_create());The library header and init function are named after the name attribute in ui/project.xml: header "<name>.h", init function <name>_init(). Run your program from the folder where the A: asset path resolves (usually the UI folder).
Adding your own source files
To compile your own .c files alongside the UI (for example custom widgets or event-handler code), list them in user_config.cmake. This file is included by the generated CMakeLists.txt and is never overwritten:
list(APPEND LV_EDITOR_PROJECT_SOURCES
${CMAKE_CURRENT_LIST_DIR}/src/my_widget.c
${CMAKE_CURRENT_LIST_DIR}/src/my_screen.c
)Use ${CMAKE_CURRENT_LIST_DIR} so the paths are relative to user_config.cmake. Your sources are compiled into the same lib-ui target and can use LVGL directly.
Building standalone
If you configure the exported folder itself as the CMake source directory, it detects that it is top-level (project(LVGLProject)) and builds lib-ui on its own. This is mainly useful as a quick compile check — because it only produces the library, there is no executable to run. To actually run the UI, integrate it into an application as shown above, or use one of the ready-made projects such as the VS Code project, simulator, Linux project, or Zephyr project, which already provide the LVGL target and an entry point.
Last updated on
VS Code project
A standalone desktop project for VS Code that builds, runs, and debugs your exported LVGL UI and can be extended with any VS Code extension.
Linux project
Create a ready-to-build embedded Linux project from the LVGL Pro Editor launcher, with DRM/KMS, framebuffer, SDL2, Wayland, and X11 backends.