cmake: Now generates Wayland protocol source bits like the configure script. Fixes Bugzilla #3430.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
diff --git a/cmake/sdlchecks.cmake b/cmake/sdlchecks.cmake
index c175cf5..b100781 100644
--- a/cmake/sdlchecks.cmake
+++ b/cmake/sdlchecks.cmake
@@ -539,6 +539,27 @@ macro(CheckMir)
endif()
endmacro()
+macro(WaylandProtocolGen _SCANNER _XML _PROTL)
+ set(_WAYLAND_PROT_C_CODE "${CMAKE_CURRENT_BINARY_DIR}/wayland-generated-protocols/${_PROTL}-protocol.c")
+ set(_WAYLAND_PROT_H_CODE "${CMAKE_CURRENT_BINARY_DIR}/wayland-generated-protocols/${_PROTL}-client-protocol.h")
+
+ add_custom_command(
+ OUTPUT "${_WAYLAND_PROT_H_CODE}"
+ DEPENDS "${_XML}"
+ COMMAND "${_SCANNER}"
+ ARGS client-header "${_XML}" "${_WAYLAND_PROT_H_CODE}"
+ )
+
+ add_custom_command(
+ OUTPUT "${_WAYLAND_PROT_C_CODE}"
+ DEPENDS "${_WAYLAND_PROT_H_CODE}"
+ COMMAND "${_SCANNER}"
+ ARGS code "${_XML}" "${_WAYLAND_PROT_C_CODE}"
+ )
+
+ set(SOURCE_FILES ${SOURCE_FILES} "${CMAKE_CURRENT_BINARY_DIR}/wayland-generated-protocols/${_PROTL}-protocol.c")
+endmacro()
+
# Requires:
# - EGL
# - PkgCheckModules
@@ -547,7 +568,51 @@ endmacro()
# - HAVE_DLOPEN opt
macro(CheckWayland)
if(VIDEO_WAYLAND)
- pkg_check_modules(WAYLAND wayland-client wayland-cursor wayland-egl egl xkbcommon)
+ pkg_check_modules(WAYLAND wayland-client wayland-scanner wayland-protocols wayland-egl wayland-cursor egl xkbcommon)
+
+ # We have to generate some protocol interface code for some various Wayland features.
+ if(WAYLAND_FOUND)
+ execute_process(
+ COMMAND ${PKG_CONFIG_EXECUTABLE} --variable=pkgdatadir wayland-client
+ WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
+ RESULT_VARIABLE WAYLAND_CORE_PROTOCOL_DIR_RC
+ OUTPUT_VARIABLE WAYLAND_CORE_PROTOCOL_DIR
+ ERROR_QUIET
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ )
+ if(NOT WAYLAND_CORE_PROTOCOL_DIR_RC EQUAL 0)
+ set(WAYLAND_FOUND FALSE)
+ endif()
+ endif()
+
+ if(WAYLAND_FOUND)
+ execute_process(
+ COMMAND ${PKG_CONFIG_EXECUTABLE} --variable=pkgdatadir wayland-protocols
+ WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
+ RESULT_VARIABLE WAYLAND_PROTOCOLS_DIR_RC
+ OUTPUT_VARIABLE WAYLAND_PROTOCOLS_DIR
+ ERROR_QUIET
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ )
+ if(NOT WAYLAND_PROTOCOLS_DIR_RC EQUAL 0)
+ set(WAYLAND_FOUND FALSE)
+ endif()
+ endif()
+
+ if(WAYLAND_FOUND)
+ execute_process(
+ COMMAND ${PKG_CONFIG_EXECUTABLE} --variable=wayland_scanner wayland-scanner
+ WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
+ RESULT_VARIABLE WAYLAND_SCANNER_RC
+ OUTPUT_VARIABLE WAYLAND_SCANNER
+ ERROR_QUIET
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ )
+ if(NOT WAYLAND_SCANNER_RC EQUAL 0)
+ set(WAYLAND_FOUND FALSE)
+ endif()
+ endif()
+
if(WAYLAND_FOUND)
link_directories(
${WAYLAND_LIBRARY_DIRS}
@@ -561,6 +626,17 @@ macro(CheckWayland)
file(GLOB WAYLAND_SOURCES ${SDL2_SOURCE_DIR}/src/video/wayland/*.c)
set(SOURCE_FILES ${SOURCE_FILES} ${WAYLAND_SOURCES})
+ # We have to generate some protocol interface code for some unstable Wayland features.
+ file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/wayland-generated-protocols")
+ include_directories("${CMAKE_CURRENT_BINARY_DIR}/wayland-generated-protocols")
+
+ WaylandProtocolGen("${WAYLAND_SCANNER}" "${WAYLAND_CORE_PROTOCOL_DIR}/wayland.xml" "wayland")
+
+ foreach(_PROTL relative-pointer-unstable-v1 pointer-constraints-unstable-v1)
+ string(REGEX REPLACE "\\-unstable\\-.*$" "" PROTSUBDIR ${_PROTL})
+ WaylandProtocolGen("${WAYLAND_SCANNER}" "${WAYLAND_PROTOCOLS_DIR}/unstable/${PROTSUBDIR}/${_PROTL}.xml" "${_PROTL}")
+ endforeach()
+
if(VIDEO_WAYLAND_QT_TOUCH)
set(SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH 1)
endif()