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

Simplify adding new wayland protocols #2110

Merged
merged 1 commit into from
Dec 8, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
78 changes: 57 additions & 21 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -273,34 +273,70 @@ if(BUILD_GUI)
endif(BUILD_GUI)

if(BUILD_WAYLAND)
set(wl_srcs
set(wl_sources
wl.cc
wl.h
display-wayland.cc
display-wayland.hh
xdg-shell-protocol.c
wlr-layer-shell-protocol.c
)
set(optional_sources ${optional_sources} ${wl_srcs})

# generate protocol implementations
set(XDG_PROT_DEF "${Wayland_PROTOCOLS_DIR}/stable/xdg-shell/xdg-shell.xml")
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/xdg-shell-client-protocol.h
COMMAND ${Wayland_SCANNER} client-header ${XDG_PROT_DEF} xdg-shell-client-protocol.h)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/xdg-shell-protocol.c
COMMAND ${Wayland_SCANNER} private-code ${XDG_PROT_DEF} xdg-shell-protocol.c
DEPENDS xdg-shell-client-protocol.h)

set(WLR_LAYER_SHELL_PROT_DEF "${CMAKE_CURRENT_SOURCE_DIR}/wlr-layer-shell-unstable-v1.xml")
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/wlr-layer-shell-client-protocol.h
COMMAND ${Wayland_SCANNER} client-header ${WLR_LAYER_SHELL_PROT_DEF} wlr-layer-shell-client-protocol.h)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/wlr-layer-shell-protocol.c
COMMAND ${Wayland_SCANNER} private-code ${WLR_LAYER_SHELL_PROT_DEF} wlr-layer-shell-protocol.c
DEPENDS wlr-layer-shell-client-protocol.h)

# Looks up wayland protocol files, build respective headers/sources, and adds
# them to the build.
#
# Use: add_protocol(name [v<version>])
macro(ADD_PROTOCOL name)
set(WL_PROTOCOL_PATHS
"${CMAKE_CURRENT_SOURCE_DIR}/wl_protocols" # first for reproducibility
"${Wayland_PROTOCOLS_DIR}/stable/${name}"
"${Wayland_PROTOCOLS_DIR}/stable"
"${Wayland_PROTOCOLS_DIR}/unstable/${name}"
"${Wayland_PROTOCOLS_DIR}/unstable"
)
if(${ARGC} GREATER 1)
set(VERSION ${ARGV1})
find_file(PROTOCOL_FILE
NAMES
"${name}-${VERSION}.xml"
"${name}-unstable-${VERSION}.xml"
PATHS ${WL_PROTOCOL_PATHS}
NO_CACHE
REQUIRED
NO_DEFAULT_PATH
)
message(STATUS "PROTOCOL '${name}' ${VERSION} file: ${PROTOCOL_FILE}")
unset(VERSION)
else()
find_file(PROTOCOL_FILE
NAMES
"${name}.xml"
"${name}-unstable.xml"
PATHS ${WL_PROTOCOL_PATHS}
NO_CACHE
REQUIRED
NO_DEFAULT_PATH
)
message(STATUS "PROTOCOL '${name}' file: ${PROTOCOL_FILE}")
endif()


add_custom_command(
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${name}-client-protocol.h"
COMMAND ${Wayland_SCANNER} client-header "${PROTOCOL_FILE}" "${name}-client-protocol.h")
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${name}-protocol.c
COMMAND ${Wayland_SCANNER} private-code "${PROTOCOL_FILE}" "${name}-protocol.c"
DEPENDS "${name}-client-protocol.h")
list(APPEND wl_sources "${name}-protocol.c")
unset(PROTOCOL_FILE)
unset(WL_PROTOCOL_PATHS)
endmacro()

add_protocol(xdg-shell)
add_protocol(wlr-layer-shell v1)
Comment on lines +336 to +337
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This PR allows protocols to be added like this.


set(optional_sources ${optional_sources} ${wl_sources})
endif(BUILD_WAYLAND)

if(BUILD_HDDTEMP)
Expand Down
Loading