1commit 69914d79c3d86b0aee80665c51074cf8cc55f660
2Author: K900 <me@0upti.me>
3Date: 2025-03-05 13:14:02 +0300
4
5 meson: support building with system libgbm
6
7 This is the next step towards making libgbm just a loader.
8
9diff --git a/meson.build b/meson.build
10index 4766ce838ba..300a6bb0cc8 100644
11--- a/meson.build
12+++ b/meson.build
13@@ -2377,7 +2377,7 @@ summary(egl_summary, section: 'EGL', bool_yn: true, list_sep: ' ')
14
15 gbm_summary = {'Enabled': with_gbm}
16 if with_gbm
17- gbm_summary += {'Backends path': gbm_backends_path}
18+ gbm_summary += {'External libgbm': get_option('libgbm-external'), 'Backends path': gbm_backends_path}
19 endif
20 summary(gbm_summary, section: 'GBM', bool_yn: true, list_sep: ' ')
21
22diff --git a/meson_options.txt b/meson_options.txt
23index 2622cf1d235..7bf8ae8a1c5 100644
24--- a/meson_options.txt
25+++ b/meson_options.txt
26@@ -329,6 +329,13 @@ option(
27 description : 'Build support for gbm platform'
28 )
29
30+option(
31+ 'libgbm-external',
32+ type: 'boolean',
33+ value: false,
34+ description: 'Whether to use external libgbm (default: use in-tree copy)'
35+)
36+
37 option(
38 'gbm-backends-path',
39 type : 'string',
40diff --git a/src/egl/meson.build b/src/egl/meson.build
41index a02b83419c4..ae4b0c5e063 100644
42--- a/src/egl/meson.build
43+++ b/src/egl/meson.build
44@@ -108,9 +108,8 @@ if with_dri
45 endif
46 if with_gbm and not with_platform_android
47 files_egl += files('drivers/dri2/platform_drm.c')
48- link_for_egl += libgbm
49- incs_for_egl += [inc_gbm, include_directories('../gbm/main')]
50- deps_for_egl += dep_libdrm
51+ incs_for_egl += [include_directories('../gbm/backends/dri')]
52+ deps_for_egl += [dep_libdrm, dep_gbm]
53 endif
54 if with_platform_wayland
55 deps_for_egl += [dep_wayland_client, dep_wayland_server, dep_wayland_egl_headers]
56diff --git a/src/gallium/targets/dril/dril_target.c b/src/gallium/targets/dril/dril_target.c
57index 339e9376c3d..f1a0bb18ed8 100644
58--- a/src/gallium/targets/dril/dril_target.c
59+++ b/src/gallium/targets/dril/dril_target.c
60@@ -25,7 +25,7 @@
61 #include <dlfcn.h>
62 #include <EGL/egl.h>
63 #include <EGL/eglext.h>
64-#include "gbm/main/gbm.h"
65+#include <gbm.h>
66 #include "drm-uapi/drm_fourcc.h"
67
68 #define EGL_PLATFORM_GBM_MESA 0x31D7
69diff --git a/src/gallium/targets/dril/meson.build b/src/gallium/targets/dril/meson.build
70index 7cfa982ffe1..22b955b9074 100644
71--- a/src/gallium/targets/dril/meson.build
72+++ b/src/gallium/targets/dril/meson.build
73@@ -51,10 +51,10 @@ dril_dri = shared_library(
74 link_depends : dril_link_depends,
75 link_with : [
76 libgallium,
77- libgbm,
78 ],
79 dependencies : [
80 idep_mesautil,
81+ dep_gbm,
82 ],
83 # Will be deleted during installation, see install_megadrivers.py
84 install : true,
85diff --git a/src/gbm/backends/dri/gbm_dri.c b/src/gbm/backends/dri/gbm_dri.c
86index a51e3cb3b8d..f1a5e0f7649 100644
87--- a/src/gbm/backends/dri/gbm_dri.c
88+++ b/src/gbm/backends/dri/gbm_dri.c
89@@ -43,7 +43,7 @@
90
91 #include "mesa_interface.h"
92 #include "gbm_driint.h"
93-#include "gbmint.h"
94+#include <gbm_backend_abi.h>
95 #include "loader_dri_helper.h"
96 #include "kopper_interface.h"
97 #include "loader.h"
98diff --git a/src/gbm/backends/dri/gbm_driint.h b/src/gbm/backends/dri/gbm_driint.h
99index 9b324aeaf12..9c7588e5726 100644
100--- a/src/gbm/backends/dri/gbm_driint.h
101+++ b/src/gbm/backends/dri/gbm_driint.h
102@@ -31,7 +31,7 @@
103 #include <xf86drm.h>
104 #include <string.h>
105 #include <sys/mman.h>
106-#include "gbmint.h"
107+#include <gbm_backend_abi.h>
108 #include "c11/threads.h"
109
110 #include <GL/gl.h> /* mesa_interface needs GL types */
111diff --git a/src/gbm/backends/dri/meson.build b/src/gbm/backends/dri/meson.build
112index 9b5d13e9db8..84a40656980 100644
113--- a/src/gbm/backends/dri/meson.build
114+++ b/src/gbm/backends/dri/meson.build
115@@ -11,10 +11,10 @@ endif
116 shared_library(
117 'dri_gbm',
118 files('gbm_dri.c', 'gbm_driint.h'),
119- include_directories : [incs_gbm, incs_gbm_dri, inc_st_dri, inc_gallium_aux],
120+ include_directories : [inc_gallium, incs_gbm_dri, inc_loader, inc_st_dri, inc_gallium_aux],
121 link_args : [ld_args_gc_sections],
122 link_with : [libloader, libgallium_dri],
123- dependencies : [deps_gbm_dri, dep_dl, dep_libdrm, idep_mesautil, idep_xmlconfig],
124+ dependencies : [deps_gbm_dri, dep_dl, dep_gbm, dep_libdrm, idep_mesautil, idep_xmlconfig],
125 gnu_symbol_visibility : 'hidden',
126 install : true,
127 install_dir: join_paths(get_option('libdir'), 'gbm'),
128diff --git a/src/gbm/meson.build b/src/gbm/meson.build
129index eaed028d049..97e8d5fa044 100644
130--- a/src/gbm/meson.build
131+++ b/src/gbm/meson.build
132@@ -15,10 +15,6 @@ args_gbm = [
133 ]
134 incs_gbm = [include_directories('main'), inc_loader, inc_gallium]
135
136-if with_dri2
137- subdir('backends/dri')
138-endif
139-
140 libgbm_name = 'gbm'
141
142 if with_platform_android and get_option('platform-sdk-version') >= 30
143@@ -43,7 +39,7 @@ if with_tests
144 test('gbm-abi-check', abi_check, suite : ['gbm'])
145 endif
146
147-install_headers('main/gbm.h')
148+install_headers('main/gbm.h', 'main/gbm_backend_abi.h')
149
150 pkg.generate(
151 name : 'gbm',
152@@ -67,3 +63,8 @@ if with_symbols_check
153 suite : ['gbm'],
154 )
155 endif
156+
157+dep_gbm = declare_dependency(
158+ link_with : libgbm,
159+ include_directories : inc_gbm,
160+)
161diff --git a/src/meson.build b/src/meson.build
162index d443d2b41bb..74250ed2148 100644
163--- a/src/meson.build
164+++ b/src/meson.build
165@@ -127,11 +127,17 @@ endif
166 if with_glx == 'dri'
167 subdir('glx')
168 endif
169+
170 if with_gbm
171- subdir('gbm')
172+ if get_option('libgbm-external')
173+ dep_gbm = dependency('gbm')
174+ else
175+ subdir('gbm')
176+ endif
177 else
178- inc_gbm = []
179+ dep_gbm = null_dep
180 endif
181+
182 if with_egl
183 subdir('egl')
184 endif
185@@ -141,6 +147,10 @@ if with_gallium and with_gbm
186 endif
187 endif
188
189+if with_gbm and with_dri2
190+ subdir('gbm/backends/dri')
191+endif
192+
193 # This must be after at least mesa, glx, and gallium, since libgl will be
194 # defined in one of those subdirs depending on the glx provider.
195 if with_glx != 'disabled' and not with_glvnd