Skip to content

Commit 8e98544

Browse files
Improves CMAKE, adds CI workflow, adds EVDEV pointer device support (#60)
* Implements dist. independent dependency detection using pkg-config Improves the cmake file * Adds ci workflow that tests building the project in different environments using docker * Adds support for evdev input pointer device to the example Updates README
1 parent 2547832 commit 8e98544

File tree

6 files changed

+164
-12
lines changed

6 files changed

+164
-12
lines changed

.github/workflows/build.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: Test building the project in different environments
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
build:
7+
strategy:
8+
matrix:
9+
os:
10+
- { image: "debian:bullseye", dockerfile: "Dockerfile_DEBIAN" }
11+
- { image: "debian:bookworm", dockerfile: "Dockerfile_DEBIAN" }
12+
- { image: "ubuntu:20.04", dockerfile: "Dockerfile_DEBIAN" }
13+
- { image: "ubuntu:22.04", dockerfile: "Dockerfile_DEBIAN" }
14+
- { image: "rockylinux:8", dockerfile: "Dockerfile_RHEL" }
15+
- { image: "rockylinux:9", dockerfile: "Dockerfile_RHEL" }
16+
- { image: "oraclelinux:8", dockerfile: "Dockerfile_RHEL" }
17+
- { image: "oraclelinux:9", dockerfile: "Dockerfile_RHEL" }
18+
fail-fast: false
19+
20+
runs-on: ubuntu-latest
21+
22+
steps:
23+
- name: Checkout repository
24+
uses: actions/checkout@v3
25+
with:
26+
submodules: recursive
27+
28+
- name: Set up Docker Buildx
29+
uses: docker/setup-buildx-action@v2
30+
31+
- name: Build the Docker image
32+
run: |
33+
docker build \
34+
--build-arg BASE_OS=${{ matrix.os.image }} \
35+
-f docker/${{ matrix.os.dockerfile }} \
36+
-t test_${{ matrix.os.image }} .
37+
38+
- name: FBDEV Test building the project
39+
run: |
40+
sed -i "s/^#define LV_USE_LINUX_FBDEV.*$/#define LV_USE_LINUX_FBDEV 1/g" lv_conf.h && \
41+
sed -i "s/^#define LV_USE_LINUX_DRM.*$/#define LV_USE_LINUX_DRM 0/g" lv_conf.h && \
42+
sed -i "s/^#define LV_USE_SDL.*$/#define LV_USE_SDL 0/g" lv_conf.h && \
43+
docker run --rm -v "$(pwd)":/workdir -t test_${{ matrix.os.image }} \
44+
/bin/bash -ec "mkdir build/ && cd build/ && cmake .. && make -j && ldd ../bin/main"
45+
46+
- name: DRM Test building the project
47+
run: |
48+
sudo rm -Rf build/ bin/ && \
49+
sed -i "s/^#define LV_USE_LINUX_FBDEV.*$/#define LV_USE_LINUX_FBDEV 0/g" lv_conf.h && \
50+
sed -i "s/^#define LV_USE_LINUX_DRM.*$/#define LV_USE_LINUX_DRM 1/g" lv_conf.h && \
51+
sed -i "s/^#define LV_USE_SDL.*$/#define LV_USE_SDL 0/g" lv_conf.h && \
52+
docker run --rm -v "$(pwd)":/workdir -t test_${{ matrix.os.image }} \
53+
/bin/bash -ec "mkdir build/ && cd build/ && cmake .. && make -j && ldd ../bin/main"
54+
55+
- name: SDL Test building the project
56+
run: |
57+
sudo rm -Rf build/ bin/ && \
58+
sed -i "s/^#define LV_USE_LINUX_FBDEV.*$/#define LV_USE_LINUX_FBDEV 0/g" lv_conf.h && \
59+
sed -i "s/^#define LV_USE_LINUX_DRM.*$/#define LV_USE_LINUX_DRM 0/g" lv_conf.h && \
60+
sed -i "s/^#define LV_USE_SDL.*$/#define LV_USE_SDL 1/g" lv_conf.h && \
61+
docker run --rm -v "$(pwd)":/workdir -t test_${{ matrix.os.image }} \
62+
/bin/bash -ec "mkdir build/ && cd build/ && cmake .. && make -j && ldd ../bin/main"

CMakeLists.txt

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,26 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
88
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
99

1010
add_subdirectory(lvgl)
11-
target_include_directories(lvgl PUBLIC ${PROJECT_SOURCE_DIR})
12-
1311
add_executable(main main.c mouse_cursor_icon.c)
1412

15-
include(${CMAKE_CURRENT_LIST_DIR}/lvgl/tests/FindLibDRM.cmake)
16-
include_directories(${Libdrm_INCLUDE_DIRS})
17-
18-
find_package(SDL2)
19-
find_package(SDL2_image)
20-
include_directories(${SDL2_INCLUDE_DIRS} ${SDL2_IMAGE_INCLUDE_DIRS})
21-
22-
target_link_libraries(main lvgl lvgl::examples lvgl::demos lvgl::thorvg ${SDL2_LIBRARIES} ${SDL2_IMAGE_LIBRARIES} ${Libdrm_LIBRARIES} m pthread)
23-
add_custom_target (run COMMAND ${EXECUTABLE_OUTPUT_PATH}/main DEPENDS main)
13+
find_package(PkgConfig REQUIRED) # We use the platform independent pkg-config to find all the libs
14+
pkg_check_modules(LIBDRM REQUIRED libdrm)
15+
pkg_check_modules(SDL2 REQUIRED sdl2)
16+
pkg_check_modules(SDL2_image REQUIRED SDL2_image)
2417

18+
target_include_directories(lvgl PUBLIC ${PROJECT_SOURCE_DIR})
19+
target_include_directories(lvgl PRIVATE ${SDL2_INCLUDE_DIRS})
20+
target_include_directories(lvgl PRIVATE ${SDL2_IMAGE_INCLUDE_DIRS})
21+
target_include_directories(lvgl PRIVATE ${LIBDRM_INCLUDE_DIRS})
22+
23+
target_link_libraries(main PRIVATE lvgl) # Add '-static' if you want a standalone binary
24+
target_link_libraries(main PRIVATE lvgl::examples)
25+
target_link_libraries(main PRIVATE lvgl::demos)
26+
target_link_libraries(main PRIVATE lvgl::thorvg)
27+
target_link_libraries(main PRIVATE ${SDL2_LIBRARIES})
28+
target_link_libraries(main PRIVATE ${SDL2_IMAGE_LIBRARIES})
29+
target_link_libraries(main PRIVATE ${LIBDRM_LIBRARIES})
30+
target_link_libraries(main PRIVATE m)
31+
target_link_libraries(main PRIVATE pthread)
32+
33+
add_custom_target(run COMMAND ${EXECUTABLE_OUTPUT_PATH}/main DEPENDS main)

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ resolution of 800x480.
1111
Check out this blog post for a step by step tutorial:
1212
https://blog.lvgl.io/2018-01-03/linux_fb
1313

14+
## Build dependencies
15+
Check the [Dockerfiles](docker/) for the build dependencies.
16+
1417
## Clone the project
1518

1619
Clone the LVGL Framebuffer Demo project and its related sub modules.
@@ -70,6 +73,11 @@ The following variables are supported.
7073

7174
- `LV_LINUX_FBDEV_DEVICE` - override default (`/dev/fb0`) framebuffer device node.
7275

76+
77+
### EVDEV touchscreen/mouse pointer device
78+
79+
- `LV_LINUX_EVDEV_POINTER_DEVICE` - override default (`/dev/input/by-id/my-mouse-or-touchscreen`) input device
80+
7381
### DRM/KMS
7482

7583
- `LV_LINUX_DRM_CARD` - override default (`/dev/dri/card0`) card.

docker/Dockerfile_DEBIAN

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
ARG BASE_OS
2+
FROM "$BASE_OS"
3+
4+
RUN DEBIAN_FRONTEND="noninteractive" apt-get update
5+
6+
# Build tools
7+
RUN DEBIAN_FRONTEND="noninteractive" apt-get install -y make cmake build-essential
8+
9+
# Required for LV_USE_SDL
10+
RUN DEBIAN_FRONTEND="noninteractive" apt-get install -y libsdl2-dev libsdl2-image-dev
11+
12+
# Required for LV_USE_LINUX_DRM linux-headers-generic provides an included header file
13+
RUN DEBIAN_FRONTEND="noninteractive" apt-get install -y libdrm-dev linux-headers-generic
14+
15+
RUN mkdir /workdir
16+
WORKDIR /workdir

docker/Dockerfile_RHEL

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
ARG BASE_OS
2+
FROM "$BASE_OS"
3+
4+
RUN dnf makecache --refresh
5+
RUN dnf -y install 'dnf-command(config-manager)'
6+
RUN dnf repolist --all
7+
8+
# Rocky 8
9+
RUN dnf config-manager --set-enabled powertools || true
10+
11+
# Oracle 8
12+
RUN dnf config-manager --set-enabled ol8_codeready_builder || true
13+
14+
# Rocky/Oracle 9+
15+
RUN dnf config-manager --set-enabled crb || true
16+
17+
RUN dnf -y install epel-release
18+
RUN dnf makecache --refresh
19+
20+
# Build tools
21+
RUN dnf -y groupinstall "Development Tools"
22+
RUN dnf -y install cmake
23+
24+
# Required for LV_USE_SDL
25+
RUN dnf -y install SDL2-devel SDL2_image-devel
26+
27+
# Required for LV_USE_LINUX_DRM
28+
RUN dnf -y install libdrm-devel
29+
30+
RUN mkdir /workdir
31+
WORKDIR /workdir

main.c

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,34 @@ static const char *getenv_default(const char *name, const char *dflt)
1111
return getenv(name) ? : dflt;
1212
}
1313

14+
#if LV_USE_EVDEV
15+
static void lv_linux_init_input_pointer(lv_display_t *disp)
16+
{
17+
// Enables a pointer (touchscreen/mouse) input device
18+
// Use 'evtest' to find the correct input device. /dev/input/by-id/ is recommeded if possible
19+
// Use /dev/input/by-id/my-mouse-or-touchscreen or /dev/input/eventX
20+
const char *input_device = getenv_default("LV_LINUX_EVDEV_POINTER_DEVICE", "/dev/input/by-id/my-mouse-or-touchscreen");
21+
lv_indev_t *touch = lv_evdev_create(LV_INDEV_TYPE_POINTER, input_device);
22+
lv_indev_set_display(touch, disp);
23+
24+
// Disable this if you want no cursor
25+
LV_IMAGE_DECLARE(mouse_cursor_icon); /*Declare the image source.*/
26+
lv_obj_t * cursor_obj = lv_image_create(lv_screen_active()); /*Create an image object for the cursor */
27+
lv_image_set_src(cursor_obj, &mouse_cursor_icon); /*Set the image source*/
28+
lv_indev_set_cursor(touch, cursor_obj); /*Connect the image object to the driver*/
29+
}
30+
#endif
31+
1432
#if LV_USE_LINUX_FBDEV
1533
static void lv_linux_disp_init(void)
1634
{
1735
const char *device = getenv_default("LV_LINUX_FBDEV_DEVICE", "/dev/fb0");
1836
lv_display_t * disp = lv_linux_fbdev_create();
19-
37+
38+
#if LV_USE_EVDEV
39+
lv_linux_init_input_pointer(disp);
40+
#endif
41+
2042
lv_linux_fbdev_set_file(disp, device);
2143
}
2244
#elif LV_USE_LINUX_DRM
@@ -25,6 +47,10 @@ static void lv_linux_disp_init(void)
2547
const char *device = getenv_default("LV_LINUX_DRM_CARD", "/dev/dri/card0");
2648
lv_display_t * disp = lv_linux_drm_create();
2749

50+
#if LV_USE_EVDEV
51+
lv_linux_init_input_pointer(disp);
52+
#endif
53+
2854
lv_linux_drm_set_file(disp, device, -1);
2955
}
3056
#elif LV_USE_SDL

0 commit comments

Comments
 (0)