1From 2747e47393cbca2d09db56223e735bd94b21e2eb Mon Sep 17 00:00:00 2001
2From: Joel Winarske <joel.winarske@gmail.com>
3Date: Mon, 28 Sep 2020 22:23:02 -0700
4Subject: [PATCH] Wayland: Remove extra-cmake-modules dependency
5
6Fixes #1774.
7
8[Retrieved (and backported) from:
9https://github.com/glfw/glfw/commit/2747e47393cbca2d09db56223e735bd94b21e2eb]
10Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
11---
12 .gitignore         |  4 ---
13 CMakeLists.txt     | 16 ++++++------
14 src/CMakeLists.txt | 62 ++++++++++++++++++++++++++++------------------
15 3 files changed, 45 insertions(+), 37 deletions(-)
16
17diff --git a/CMakeLists.txt b/CMakeLists.txt
18index 42bfa1806d..394827520b 100644
19--- a/CMakeLists.txt
20+++ b/CMakeLists.txt
21@@ -191,20 +191,18 @@ endif()
22 # Use Wayland for window creation
23 #--------------------------------------------------------------------
24 if (_GLFW_WAYLAND)
25-    find_package(ECM REQUIRED NO_MODULE)
26-    list(APPEND CMAKE_MODULE_PATH "${ECM_MODULE_PATH}")
27
28-    find_package(Wayland REQUIRED Client Cursor Egl)
29-    find_package(WaylandScanner REQUIRED)
30-    find_package(WaylandProtocols 1.15 REQUIRED)
31+    include(FindPkgConfig)
32+    pkg_check_modules(Wayland REQUIRED
33+        wayland-client>=0.2.7
34+        wayland-cursor>=0.2.7
35+        wayland-egl>=0.2.7
36+        xkbcommon)
37
38     list(APPEND glfw_PKG_DEPS "wayland-client")
39
40     list(APPEND glfw_INCLUDE_DIRS "${Wayland_INCLUDE_DIRS}")
41-    list(APPEND glfw_LIBRARIES "${Wayland_LIBRARIES}" "${CMAKE_THREAD_LIBS_INIT}")
42-
43-    find_package(XKBCommon REQUIRED)
44-    list(APPEND glfw_INCLUDE_DIRS "${XKBCOMMON_INCLUDE_DIRS}")
45+    list(APPEND glfw_LIBRARIES "${Wayland_LINK_LIBRARIES}" "${CMAKE_THREAD_LIBS_INIT}")
46
47     include(CheckIncludeFiles)
48     include(CheckFunctionExists)
49diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
50index 2f2bdd883d..e834506c6c 100644
51--- a/src/CMakeLists.txt
52+++ b/src/CMakeLists.txt
53@@ -45,30 +45,44 @@ if (_GLFW_X11 OR _GLFW_WAYLAND)
54                      posix_time.c posix_thread.c xkb_unicode.c
55                      egl_context.c osmesa_context.c)
56
57-    ecm_add_wayland_client_protocol(glfw_SOURCES
58-        PROTOCOL
59-        "${WAYLAND_PROTOCOLS_PKGDATADIR}/stable/xdg-shell/xdg-shell.xml"
60-        BASENAME xdg-shell)
61-    ecm_add_wayland_client_protocol(glfw_SOURCES
62-        PROTOCOL
63-        "${WAYLAND_PROTOCOLS_PKGDATADIR}/unstable/xdg-decoration/xdg-decoration-unstable-v1.xml"
64-        BASENAME xdg-decoration)
65-    ecm_add_wayland_client_protocol(glfw_SOURCES
66-        PROTOCOL
67-        "${WAYLAND_PROTOCOLS_PKGDATADIR}/stable/viewporter/viewporter.xml"
68-        BASENAME viewporter)
69-    ecm_add_wayland_client_protocol(glfw_SOURCES
70-        PROTOCOL
71-        "${WAYLAND_PROTOCOLS_PKGDATADIR}/unstable/relative-pointer/relative-pointer-unstable-v1.xml"
72-        BASENAME relative-pointer-unstable-v1)
73-    ecm_add_wayland_client_protocol(glfw_SOURCES
74-        PROTOCOL
75-        "${WAYLAND_PROTOCOLS_PKGDATADIR}/unstable/pointer-constraints/pointer-constraints-unstable-v1.xml"
76-        BASENAME pointer-constraints-unstable-v1)
77-    ecm_add_wayland_client_protocol(glfw_SOURCES
78-        PROTOCOL
79-        "${WAYLAND_PROTOCOLS_PKGDATADIR}/unstable/idle-inhibit/idle-inhibit-unstable-v1.xml"
80-        BASENAME idle-inhibit-unstable-v1)
81+    find_program(WAYLAND_SCANNER_EXECUTABLE NAMES wayland-scanner)
82+    pkg_check_modules(WAYLAND_PROTOCOLS REQUIRED wayland-protocols>=1.15)
83+    pkg_get_variable(WAYLAND_PROTOCOLS_BASE wayland-protocols pkgdatadir)
84+
85+    macro(wayland_generate protocol_file output_file)
86+          add_custom_command(OUTPUT ${output_file}.h
87+              COMMAND ${WAYLAND_SCANNER_EXECUTABLE} client-header
88+              < ${protocol_file} > ${output_file}.h
89+              DEPENDS ${protocol_file})
90+          list(APPEND glfw_SOURCES ${output_file}.h)
91+
92+          add_custom_command(OUTPUT ${output_file}.c
93+              COMMAND ${WAYLAND_SCANNER_EXECUTABLE} private-code
94+              < ${protocol_file} > ${output_file}.c
95+              DEPENDS ${protocol_file})
96+          list(APPEND glfw_SOURCES ${output_file}.c)
97+    endmacro()
98+
99+    set(GLFW_WAYLAND_PROTOCOL_SOURCES)
100+    wayland_generate(
101+        ${WAYLAND_PROTOCOLS_BASE}/stable/xdg-shell/xdg-shell.xml
102+        ${CMAKE_BINARY_DIR}/src/wayland-xdg-shell-client-protocol)
103+    wayland_generate(
104+        ${WAYLAND_PROTOCOLS_BASE}/unstable/xdg-decoration/xdg-decoration-unstable-v1.xml
105+        ${CMAKE_BINARY_DIR}/src/wayland-xdg-decoration-client-protocol)
106+    wayland_generate(
107+        ${WAYLAND_PROTOCOLS_BASE}/stable/viewporter/viewporter.xml
108+        ${CMAKE_BINARY_DIR}/src/wayland-viewporter-client-protocol)
109+    wayland_generate(
110+        ${WAYLAND_PROTOCOLS_BASE}/unstable/relative-pointer/relative-pointer-unstable-v1.xml
111+        ${CMAKE_BINARY_DIR}/src/wayland-relative-pointer-unstable-v1-client-protocol)
112+    wayland_generate(
113+        ${WAYLAND_PROTOCOLS_BASE}/unstable/pointer-constraints/pointer-constraints-unstable-v1.xml
114+        ${CMAKE_BINARY_DIR}/src/wayland-pointer-constraints-unstable-v1-client-protocol)
115+    wayland_generate(
116+        ${WAYLAND_PROTOCOLS_BASE}/unstable/idle-inhibit/idle-inhibit-unstable-v1.xml
117+        ${CMAKE_BINARY_DIR}/src/wayland-idle-inhibit-unstable-v1-client-protocol)
118+
119 elseif (_GLFW_OSMESA)
120     set(glfw_HEADERS ${common_HEADERS} null_platform.h null_joystick.h
121                      posix_time.h posix_thread.h osmesa_context.h)
122