Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(cmake) : remove dependence of wayland when not use it #252

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
**/*.o
**/*.d
**/*.d

/build
16 changes: 13 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ project(lv_drivers HOMEPAGE_URL https://github.com/lvgl/lv_drivers/)

# Option to build as shared library (as opposed to static), default: OFF
option(BUILD_SHARED_LIBS "Build shared as library (as opposed to static)" OFF)
option(BUILD_USE_WAYLAND "Build the Wayland driver" OFF)

# Append our module directory to CMake
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)

if (BUILD_USE_WAYLAND)
include(wayland_driver)
endif()

file(GLOB_RECURSE SOURCES ./*.c)

Expand All @@ -18,9 +26,11 @@ add_library(lvgl::drivers ALIAS lv_drivers)

target_include_directories(lv_drivers SYSTEM PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

find_package(PkgConfig)
pkg_check_modules(PKG_WAYLAND wayland-client wayland-cursor wayland-protocols xkbcommon)
target_link_libraries(lv_drivers PUBLIC lvgl ${PKG_WAYLAND_LIBRARIES})
target_link_libraries(lv_drivers PUBLIC lvgl)

if (BUILD_USE_WAYLAND)
target_link_libraries(lv_drivers PUBLIC ${PKG_WAYLAND_LIBRARIES})
endif()

if("${LIB_INSTALL_DIR}" STREQUAL "")
set(LIB_INSTALL_DIR "lib")
Expand Down
61 changes: 61 additions & 0 deletions cmake/wayland_driver.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
project(lv_wayland)

option(USE_WL_SHELL "use wl shell (discard, no recommend)" OFF)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rephrase the comment as:

"use wl_shell (deprecated, not recommended)"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

modified already

option(USE_XDG_SHELL "use xdg shell" OFF)
option(USE_WAYLAND_TIMER_HANDLER "" OFF)

set(WAYLAND_SCANNER_EXECUTABLE)

macro(wayland_generate protocol_xml_file output_dir)

if(NOT EXISTS ${protocol_xml_file})
message(FATAL_ERROR "-- protocol XML file not found: " ${protocol_xml_file})
endif()

get_filename_component(output_file_base ${protocol_xml_file} NAME_WE)
set(xdg_shell_file "${output_dir}/wayland-${output_file_base}-client-protocol")
message("-- generating ${xdg_shell_file}.h")
execute_process(COMMAND "${WAYLAND_SCANNER_EXECUTABLE}" client-header "${protocol_xml_file}" "${xdg_shell_file}.h")
message("-- generating ${xdg_shell_file}.c")
execute_process(COMMAND "${WAYLAND_SCANNER_EXECUTABLE}" private-code "${protocol_xml_file}" "${xdg_shell_file}.c")
endmacro()

if (NOT USE_WL_SHELL AND USE_XDG_SHELL)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you have a bug, it should be:

if (NOT USE_WL_SHELL AND NOT USE_XDG_SHELL)

Otherwise, enabling only XDG shell would trigger the FATAL_ERROR

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

modified already

message(FATAL_ERROR "Please select at least one of USE_WL_SHELL and USE_XDG_SHELL (that is, can both select)")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rephrase the comment as follows:

"Please select at least one of USE_WL_SHELL and USE_XDG_SHELL (multiple choices allowed)"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

modified already

endif()

if (USE_WL_SHELL)
add_definitions(-DLV_WAYLAND_WL_SHELL=1)
endif()

if (USE_XDG_SHELL)
add_definitions(-DLV_WAYLAND_XDG_SHELL=1)
endif()

if (USE_WAYLAND_TIMER_HANDLER)
add_definitions(-DLV_WAYLAND_TIMER_HANDLER=1)
endif()

add_definitions(-DUSE_WAYLAND=1)

# wayland driver dependences
find_package(PkgConfig)
pkg_check_modules(PKG_WAYLAND wayland-client wayland-cursor wayland-protocols xkbcommon)
message("-- Find wayland dependences : ${PKG_WAYLAND_LIBRARIES}")

if (USE_XDG_SHELL)
message("-- select xdg shell")
find_program(WAYLAND_SCANNER_EXECUTABLE NAMES wayland-scanner)
pkg_check_modules(WAYLAND_PROTOCOLS REQUIRED wayland-protocols>=1.25)
if (NOT EXISTS WAYLAND_PROTOCOLS_BASE) # may be you need to specify wayland protocol path for cross compile
pkg_get_variable(WAYLAND_PROTOCOLS_BASE wayland-protocols pkgdatadir)
endif()
message("-- find wayland scanner : ${WAYLAND_SCANNER_EXECUTABLE}")
message("-- find wayland protocol path : ${WAYLAND_PROTOCOLS_BASE}")

# use wayland scanner with xdg-shell.xml to generate xgd protocol source and header files
set(WAYLAND_PROTOCOLS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/wayland/protocols")
file(MAKE_DIRECTORY ${WAYLAND_PROTOCOLS_DIR})
wayland_generate("${WAYLAND_PROTOCOLS_BASE}/stable/xdg-shell/xdg-shell.xml" ${WAYLAND_PROTOCOLS_DIR})
include_directories(${WAYLAND_PROTOCOLS_DIR})
endif()
39 changes: 0 additions & 39 deletions wayland/CMakeLists.txt

This file was deleted.

6 changes: 1 addition & 5 deletions wayland/wayland.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,8 @@
#include <wayland-cursor.h>
#include <xkbcommon/xkbcommon.h>

#if !(LV_WAYLAND_XDG_SHELL || LV_WAYLAND_WL_SHELL)
#error "Please select at least one shell integration for Wayland driver"
#endif

#if LV_WAYLAND_XDG_SHELL
#include "protocols/wayland-xdg-shell-client-protocol.h"
#include "wayland-xdg-shell-client-protocol.h"
#endif

/*********************
Expand Down