Skip to content

Commit 743a790

Browse files
committed
feat(wayland) Simplify CMakeLists file
Use external scripts to obtain the selected backend in lv_conf.h Generate wayland protocol via a shell script instead of CMake
1 parent 47f8fdc commit 743a790

File tree

5 files changed

+31
-49
lines changed

5 files changed

+31
-49
lines changed

CMakeLists.txt

+12-47
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,25 @@
11
cmake_minimum_required(VERSION 3.10)
22
project(lvgl)
33

4-
# Please set the wanted option to 'ON'. By default, FBDEV is used
5-
# be sure to also enable the selected driver in lv_conf.h
4+
foreach(BACKEND_NAME "SDL" "LINUX_DRM" "LINUX_FBDEV" "X11" "WAYLAND")
65

7-
option(LV_USE_WAYLAND "Use the wayland client backend" OFF)
8-
option(LV_USE_SDL "Use the SDL backend" OFF)
9-
option(LV_USE_DRM "Use the libdrm backend" OFF)
10-
option(DEBUG_MODE "Disable optimizations and enable debugging" OFF)
6+
execute_process(COMMAND "scripts/backend_conf.sh" ${BACKEND_NAME} OUTPUT_VARIABLE IS_BACKEND_ENABLED)
7+
set("LV_USE_${BACKEND_NAME}" ${IS_BACKEND_ENABLED})
8+
9+
endforeach()
10+
11+
# Uncomment if the program needs debugging
12+
#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0 -ggdb")
1113

1214
set(CMAKE_C_STANDARD 99) # LVGL officially supports C99 and above
1315
set(CMAKE_CXX_STANDARD 17) #C17
1416
set(CMAKE_CXX_STANDARD_REQUIRED ON)
15-
16-
if (DEBUG_MODE)
17-
18-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0 -ggdb")
19-
20-
endif(DEBUG_MODE)
21-
2217
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
2318

2419
add_subdirectory(lvgl)
2520
target_include_directories(lvgl PUBLIC ${PROJECT_SOURCE_DIR})
2621

22+
2723
if (LV_USE_DRM)
2824

2925
include(${CMAKE_CURRENT_LIST_DIR}/lvgl/tests/FindLibDRM.cmake)
@@ -47,43 +43,12 @@ elseif (LV_USE_WAYLAND)
4743
pkg_check_modules(xkbcommon REQUIRED xkbcommon)
4844

4945
# Wayland protocols
50-
set(WAYLAND_PROTOCOLS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/protocols")
51-
find_program(WAYLAND_SCANNER_EXECUTABLE NAMES wayland-scanner)
5246
pkg_check_modules(WAYLAND_PROTOCOLS REQUIRED wayland-protocols>=1.25)
5347
pkg_get_variable(WAYLAND_PROTOCOLS_BASE wayland-protocols pkgdatadir)
5448

55-
macro(wayland_generate protocol_xml_file output_dir target)
56-
get_filename_component(output_file_base ${protocol_xml_file} NAME_WE)
57-
set(output_file_noext "${output_dir}/wayland-${output_file_base}-client-protocol")
58-
add_custom_command(OUTPUT "${output_file_noext}.h"
59-
COMMAND "${WAYLAND_SCANNER_EXECUTABLE}" client-header "${protocol_xml_file}" "${output_file_noext}.h"
60-
DEPENDS "${protocol_xml_file}"
61-
VERBATIM)
62-
63-
add_custom_command(OUTPUT "${output_file_noext}.c"
64-
COMMAND "${WAYLAND_SCANNER_EXECUTABLE}" private-code "${protocol_xml_file}" "${output_file_noext}.c"
65-
DEPENDS "${protocol_xml_file}"
66-
VERBATIM)
67-
68-
if(NOT EXISTS ${protocol_xml_file})
69-
message("Protocol XML file not found: " ${protocol_xml_file})
70-
else()
71-
set_property(TARGET ${target} APPEND PROPERTY SOURCES "${output_file_noext}.h" "${output_file_noext}.c")
72-
endif()
73-
74-
endmacro()
75-
76-
file(MAKE_DIRECTORY ${WAYLAND_PROTOCOLS_DIR})
77-
78-
add_custom_target(generate_protocols ALL)
79-
80-
wayland_generate("${WAYLAND_PROTOCOLS_BASE}/stable/xdg-shell/xdg-shell.xml" ${WAYLAND_PROTOCOLS_DIR} generate_protocols)
81-
82-
target_include_directories(lvgl PUBLIC ${PROJECT_SOURCE_DIR} ${WAYLAND_PROTOCOLS_DIR})
83-
84-
# TODO Add option to still be able to build wl_shell
85-
add_executable(lvglsim main.c ${WAYLAND_PROTOCOLS_DIR}/wayland-xdg-shell-client-protocol.c mouse_cursor_icon.c)
86-
49+
execute_process(COMMAND "scripts/gen_wl_protocols.sh" OUTPUT_VARIABLE WAYLAND_PROTOCOLS_SRC)
50+
target_include_directories(lvgl PUBLIC ${PROJECT_SOURCE_DIR} "wl_protocols")
51+
add_executable(lvglsim main.c ${WAYLAND_PROTOCOLS_SRC} mouse_cursor_icon.c)
8752
target_compile_definitions(lvglsim PRIVATE LV_CONF_INCLUDE_SIMPLE)
8853
target_link_libraries(lvglsim lvgl lvgl::examples lvgl::demos lvgl::thorvg m wayland-client xkbcommon wayland-cursor)
8954

main.c

-2
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ static void lv_linux_disp_init(void)
5454
lv_display_t *disp;
5555
lv_group_t *g;
5656

57-
lv_wayland_init();
58-
5957
disp = lv_wayland_window_create(window_width, window_height, "LVGL Simulator", NULL);
6058

6159
if (fullscreen) {

scripts/backend_conf.sh

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/sh
2+
grep "^#define LV_USE_$1" lv_conf.h | sed 's/#define //g' | awk '{ if ($2=="1") { printf "ON" } else { printf "OFF" }}'

scripts/gen_wl_protocols.sh

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/sh
2+
# Generate wayland xdg shell protocol
3+
4+
if ! test -d /usr/share/wayland-protocols
5+
then
6+
exit 1
7+
fi
8+
9+
if ! test -d wl_protocols
10+
then
11+
mkdir wl_protocols
12+
wayland-scanner client-header "/usr/share/wayland-protocols/stable/xdg-shell/xdg-shell.xml" "wl_protocols/wayland_xdg_shell.h"
13+
wayland-scanner private-code "/usr/share/wayland-protocols/stable/xdg-shell/xdg-shell.xml" "wl_protocols/wayland_xdg_shell.c"
14+
fi
15+
16+
printf "wl_protocols/wayland_xdg_shell.c"

scripts/testing.sh

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
printf "ON"

0 commit comments

Comments
 (0)