Skip to content

Commit 1c4f83e

Browse files
committed
use config.h file for feature config
- make all source files that query features import `config.h` - change clang-format to sort config.h last in includes
1 parent 599d5d6 commit 1c4f83e

20 files changed

+150
-76
lines changed

.clang-format

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,18 @@ IncludeCategories:
9292
# POSIX headers
9393
- Regex: '^<(ctype|dlfcn|fcntl|glob|limits|locale|poll|pthread|regex|semaphore|unistd|sys/mman|sys/stat|sys/types|sys/select)\.h>$'
9494
Priority: 2
95-
# everything else
95+
# all <> includes
9696
- Regex: '^<[^>]*>$'
9797
Priority: 3
98-
- Regex: '^"[^"]*"$'
99-
Priority: 6
100-
- Regex: '.*'
98+
# config header should go last
99+
- Regex: '^"config\.h"$'
101100
Priority: 5
101+
# all "" includes
102+
- Regex: '^"[^"]*"$'
103+
Priority: 4
104+
# all other includes
105+
- Regex: '^.*$'
106+
Priority: 4
102107

103108
IncludeIsMainRegex: '(_test)?$'
104109
IndentCaseLabels: true

CMakeLists.txt

Lines changed: 34 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ target_link_libraries(flutterpi_module PUBLIC
129129
target_include_directories(flutterpi_module PUBLIC
130130
${CMAKE_SOURCE_DIR}/third_party/flutter_embedder_header/include
131131
${CMAKE_SOURCE_DIR}/src
132+
${CMAKE_BINARY_DIR}
132133
)
133134

134135
target_compile_options(flutterpi_module PUBLIC
@@ -152,23 +153,18 @@ list(GET LIBINPUT_VERSION_AS_LIST 0 LIBINPUT_VERSION_MAJOR)
152153
list(GET LIBINPUT_VERSION_AS_LIST 1 LIBINPUT_VERSION_MINOR)
153154
list(GET LIBINPUT_VERSION_AS_LIST 2 LIBINPUT_VERSION_PATCH)
154155

155-
target_compile_definitions(flutterpi_module PUBLIC
156-
LIBINPUT_VERSION_MAJOR=${LIBINPUT_VERSION_MAJOR}
157-
LIBINPUT_VERSION_MINOR=${LIBINPUT_VERSION_MINOR}
158-
LIBINPUT_VERSION_PATCH=${LIBINPUT_VERSION_PATCH}
159-
)
160-
161156
# TODO: Just unconditionally define those, make them optional later
162-
target_compile_definitions(flutterpi_module PUBLIC HAVE_KMS HAVE_GBM HAVE_FBDEV)
163-
164-
# OpenGL
165-
pkg_check_modules(EGL IMPORTED_TARGET egl)
166-
pkg_check_modules(GLES2 IMPORTED_TARGET glesv2)
157+
set(HAVE_KMS ON)
158+
set(HAVE_GBM ON)
159+
set(HAVE_FBDEV ON)
167160

161+
# OpenGL support
168162
set(HAVE_EGL OFF)
169163
set(HAVE_GLES2 OFF)
170164
set(HAVE_EGL_GLES2 OFF)
171165

166+
pkg_check_modules(EGL IMPORTED_TARGET egl)
167+
pkg_check_modules(GLES2 IMPORTED_TARGET glesv2)
172168
if (ENABLE_OPENGL)
173169
if (EGL_FOUND AND GLES2_FOUND)
174170
target_sources(flutterpi_module PRIVATE
@@ -179,10 +175,10 @@ if (ENABLE_OPENGL)
179175
PkgConfig::EGL
180176
PkgConfig::GLES2
181177
)
178+
182179
set(HAVE_EGL ON)
183180
set(HAVE_GLES2 ON)
184181
set(HAVE_EGL_GLES2 ON)
185-
target_compile_definitions(flutterpi_module PUBLIC HAVE_EGL HAVE_GLES2 HAVE_EGL_GLES2)
186182
elseif (TRY_ENABLE_OPENGL)
187183
message("EGL and/or OpenGL was not found. Flutter-pi will build without EGL/OpenGL rendering support.")
188184
else()
@@ -192,16 +188,12 @@ endif()
192188

193189
message(STATUS "EGL/GLES support ....... ${HAVE_EGL_GLES2}")
194190

195-
if (LINT_EGL_HEADERS)
196-
target_compile_definitions(flutterpi_module PUBLIC LINT_EGL_HEADERS)
197-
message(STATUS "Lint EGL headers ....... ON")
198-
else()
199-
message(STATUS "Lint EGL headers ....... OFF")
200-
endif()
201-
202-
pkg_check_modules(VULKAN IMPORTED_TARGET vulkan)
191+
message(STATUS "Lint EGL headers ....... ${LINT_EGL_HEADERS}")
203192

193+
# Vulkan support
204194
set(HAVE_VULKAN OFF)
195+
196+
pkg_check_modules(VULKAN IMPORTED_TARGET vulkan)
205197
if (ENABLE_VULKAN)
206198
if (VULKAN_FOUND)
207199
target_sources(flutterpi_module PRIVATE
@@ -211,8 +203,8 @@ if (ENABLE_VULKAN)
211203
target_link_libraries(flutterpi_module PUBLIC
212204
PkgConfig::VULKAN
213205
)
206+
214207
set(HAVE_VULKAN ON)
215-
target_compile_definitions(flutterpi_module PUBLIC HAVE_VULKAN)
216208
elseif (TRY_ENABLE_VULKAN)
217209
message("Vulkan was not found. Flutter-pi will build without vulkan rendering support.")
218210
else()
@@ -222,6 +214,7 @@ endif()
222214

223215
message(STATUS "Vulkan support ......... ${HAVE_VULKAN}")
224216

217+
# We need at least one renderer
225218
if (NOT HAVE_VULKAN AND NOT HAVE_EGL_GLES2)
226219
message(SEND_ERROR "At least one of the EGL/GLES2 and Vulkan backends must be enabled.")
227220
endif()
@@ -234,14 +227,17 @@ if(NOT FILESYSTEM_LAYOUT IN_LIST FILESYSTEM_LAYOUTS)
234227
endif()
235228

236229
message(STATUS "Filesystem Layout ...... ${FILESYSTEM_LAYOUT}")
230+
231+
# config.h takes the defines in form of #cmakedefine FILESYSTEM_LAYOUT_DEFAULT, ...
237232
if(FILESYSTEM_LAYOUT STREQUAL default)
238-
target_compile_definitions(flutterpi_module PUBLIC "FILESYSTEM_LAYOUT_DEFAULT")
233+
set(FILESYSTEM_LAYOUT_DEFAULT ON)
239234
elseif(FILESYSTEM_LAYOUT STREQUAL meta-flutter)
240-
target_compile_definitions(flutterpi_module PUBLIC "FILESYSTEM_LAYOUT_METAFLUTTER")
235+
set(FILESYSTEM_LAYOUT_METAFLUTTER ON)
241236
endif()
242237

243238
# Session switching support (using libseat)
244-
message(STATUS "Session switching ...... ${ENABLE_SESSION_SWITCHING}")
239+
set(HAVE_LIBSEAT OFF)
240+
245241
if (ENABLE_SESSION_SWITCHING)
246242
if (TRY_ENABLE_SESSION_SWITCHING)
247243
pkg_check_modules(LIBSEAT IMPORTED_TARGET libseat)
@@ -251,30 +247,22 @@ if (ENABLE_SESSION_SWITCHING)
251247

252248
if (LIBSEAT_FOUND)
253249
target_link_libraries(flutterpi_module PUBLIC PkgConfig::LIBSEAT)
254-
target_compile_definitions(flutterpi_module PUBLIC HAVE_LIBSEAT)
250+
set(HAVE_LIBSEAT ON)
255251
else()
256252
message("libseat was not found. flutter-pi will be built without session switching support.")
257253
endif()
258254
endif()
259255

260-
if (DEBUG_DRM_PLANE_ALLOCATIONS)
261-
target_compile_definitions(flutterpi_module PUBLIC DEBUG_DRM_PLANE_ALLOCATIONS)
262-
endif()
263-
264-
if (USE_LEGACY_KMS)
265-
target_compile_definitions(flutterpi_module PUBLIC USE_LEGACY_KMS)
266-
endif()
256+
message(STATUS "Session switching ...... ${HAVE_LIBSEAT}")
267257

268258
# TODO: We actually don't need the compile definitions anymore, except for
269259
# text input and raw keyboard plugin (because those have special treatment
270260
# in flutter-pi.c)
271261
if (BUILD_TEXT_INPUT_PLUGIN)
272262
target_sources(flutterpi_module PRIVATE src/plugins/text_input.c)
273-
target_compile_definitions(flutterpi_module PUBLIC "BUILD_TEXT_INPUT_PLUGIN")
274263
endif()
275264
if (BUILD_RAW_KEYBOARD_PLUGIN)
276265
target_sources(flutterpi_module PRIVATE src/plugins/raw_keyboard.c)
277-
target_compile_definitions(flutterpi_module PUBLIC "BUILD_RAW_KEYBOARD_PLUGIN")
278266
endif()
279267
if (BUILD_TEST_PLUGIN)
280268
target_sources(flutterpi_module PRIVATE src/plugins/testplugin.c)
@@ -305,11 +293,6 @@ if (BUILD_GSTREAMER_VIDEO_PLAYER_PLUGIN)
305293
list(GET LIBGSTREAMER_VERSION_AS_LIST 1 LIBGSTREAMER_VERSION_MINOR)
306294
list(GET LIBGSTREAMER_VERSION_AS_LIST 2 LIBGSTREAMER_VERSION_PATCH)
307295

308-
target_compile_definitions(flutterpi_module PUBLIC
309-
LIBGSTREAMER_VERSION_MAJOR=${LIBGSTREAMER_VERSION_MAJOR}
310-
LIBGSTREAMER_VERSION_MINOR=${LIBGSTREAMER_VERSION_MINOR}
311-
LIBGSTREAMER_VERSION_PATCH=${LIBGSTREAMER_VERSION_PATCH}
312-
)
313296
target_sources(flutterpi_module PRIVATE
314297
src/plugins/gstreamer_video_player/plugin.c
315298
src/plugins/gstreamer_video_player/player.c
@@ -359,10 +342,16 @@ endif()
359342
target_link_options(flutterpi_module PUBLIC -rdynamic)
360343

361344
# Define VULKAN_DEBUG if it was set to On, or if it was set to AUTO and we're using debug mode.
362-
if (VULKAN_DEBUG STREQUAL "AUTO")
363-
target_compile_definitions(flutterpi_module PUBLIC $<$<CONFIG:Debug>:VULKAN_DEBUG>)
364-
elseif (VULKAN_DEBUG)
365-
target_compile_definitions(flutterpi_module PUBLIC VULKAN_DEBUG)
345+
if (VULKAN_DEBUG MATCHES AUTO)
346+
if (CMAKE_BUILD_TYPE MATCHES DEBUG)
347+
set(VULKAN_DEBUG ON)
348+
else()
349+
set(VULKAN_DEBUG OFF)
350+
endif()
351+
elseif (VULKAN_DEBUG MATCHES "OFF")
352+
set(VULKAN_DEBUG OFF)
353+
elseif (VULKAN_DEBUG MATCHES "ON")
354+
set(VULKAN_DEBUG ON)
366355
endif()
367356

368357
# Some sanitizer configs.
@@ -389,9 +378,8 @@ if (ENABLE_UBSAN)
389378
target_link_options(flutterpi_module PUBLIC -fsanitize=undefined)
390379
target_compile_options(flutterpi_module PUBLIC -fsanitize=undefined)
391380
endif()
392-
if (ENABLE_MTRACE)
393-
target_compile_definitions(flutterpi_module PUBLIC "ENABLE_MTRACE")
394-
endif()
381+
382+
configure_file(config.h.in config.h @ONLY)
395383

396384
# Actual flutter-pi executable.
397385
add_executable(

config.h.in

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#ifndef _FLUTTERPI_CONFIG_H
2+
#define _FLUTTERPI_CONFIG_H
3+
4+
#define LIBINPUT_VERSION_MAJOR @LIBINPUT_VERSION_MAJOR@
5+
#define LIBINPUT_VERSION_MINOR @LIBINPUT_VERSION_MINOR@
6+
#define LIBINPUT_VERSION_PATCH @LIBINPUT_VERSION_PATCH@
7+
#cmakedefine HAVE_KMS
8+
#cmakedefine HAVE_GBM
9+
#cmakedefine HAVE_FBDEV
10+
#cmakedefine HAVE_EGL
11+
#cmakedefine HAVE_GLES2
12+
#cmakedefine HAVE_EGL_GLES2
13+
#cmakedefine LINT_EGL_HEADERS
14+
#cmakedefine HAVE_VULKAN
15+
#cmakedefine FILESYSTEM_LAYOUT_DEFAULT
16+
#cmakedefine FILESYSTEM_LAYOUT_METAFLUTTER
17+
#cmakedefine HAVE_LIBSEAT
18+
#cmakedefine DEBUG_DRM_PLANE_ALLOCATIONS
19+
#cmakedefine USE_LEGACY_KMS
20+
#cmakedefine BUILD_TEXT_INPUT_PLUGIN
21+
#cmakedefine BUILD_RAW_KEYBOARD_PLUGIN
22+
#define LIBGSTREAMER_VERSION_MAJOR @LIBGSTREAMER_VERSION_MAJOR@
23+
#define LIBGSTREAMER_VERSION_MINOR @LIBGSTREAMER_VERSION_MINOR@
24+
#define LIBGSTREAMER_VERSION_PATCH @LIBGSTREAMER_VERSION_PATCH@
25+
#cmakedefine VULKAN_DEBUG
26+
#cmakedefine ENABLE_MTRACE
27+
28+
#endif

src/compositor_ng.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
*/
1010

1111
#define _GNU_SOURCE
12+
#include "compositor_ng.h"
13+
1214
#include <inttypes.h>
1315
#include <math.h>
1416
#include <stdlib.h>
@@ -19,7 +21,6 @@
1921
#include <flutter_embedder.h>
2022
#include <systemd/sd-event.h>
2123

22-
#include "compositor_ng.h"
2324
#include "flutter-pi.h"
2425
#include "frame_scheduler.h"
2526
#include "modesetting.h"
@@ -32,6 +33,8 @@
3233
#include "util/dynarray.h"
3334
#include "window.h"
3435

36+
#include "config.h"
37+
3538
#ifdef HAVE_GBM
3639
#include <gbm.h>
3740
#endif

src/compositor_ng.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#include "pixel_format.h"
1919
#include "util/collection.h"
2020

21+
#include "config.h"
22+
2123
#ifdef HAVE_EGL_GLES2
2224
#include "egl.h"
2325
#endif

src/dmabuf_surface.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
4545
#include "texture_registry.h"
4646
#include "util/collection.h"
4747

48+
#include "config.h"
49+
4850
FILE_DESCR("dmabuf surface")
4951

5052
struct refcounted_dmabuf {

src/egl.h

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#include <stdbool.h>
1212
#include <string.h>
1313

14+
#include "config.h"
15+
1416
#ifndef HAVE_EGL
1517
#error "egl.h was included but EGL support is disabled."
1618
#endif
@@ -399,16 +401,32 @@
399401
// For functions part of EGL 1.5 we dynamically resolve the functions at
400402
// runtime, since we can't be sure they're actually present.
401403
#if defined(EGL_VERSION_1_5) && !defined(EGL_EGL_PROTOTYPES)
402-
typedef EGLSync (EGLAPIENTRYP PFNEGLCREATESYNCPROC) (EGLDisplay dpy, EGLenum type, const EGLAttrib *attrib_list);
403-
typedef EGLBoolean (EGLAPIENTRYP PFNEGLDESTROYSYNCPROC) (EGLDisplay dpy, EGLSync sync);
404-
typedef EGLint (EGLAPIENTRYP PFNEGLCLIENTWAITSYNCPROC) (EGLDisplay dpy, EGLSync sync, EGLint flags, EGLTime timeout);
405-
typedef EGLBoolean (EGLAPIENTRYP PFNEGLGETSYNCATTRIBPROC) (EGLDisplay dpy, EGLSync sync, EGLint attribute, EGLAttrib *value);
406-
typedef EGLImage (EGLAPIENTRYP PFNEGLCREATEIMAGEPROC) (EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLAttrib *attrib_list);
407-
typedef EGLBoolean (EGLAPIENTRYP PFNEGLDESTROYIMAGEPROC) (EGLDisplay dpy, EGLImage image);
408-
typedef EGLDisplay (EGLAPIENTRYP PFNEGLGETPLATFORMDISPLAYPROC) (EGLenum platform, void *native_display, const EGLAttrib *attrib_list);
409-
typedef EGLSurface (EGLAPIENTRYP PFNEGLCREATEPLATFORMWINDOWSURFACEPROC) (EGLDisplay dpy, EGLConfig config, void *native_window, const EGLAttrib *attrib_list);
410-
typedef EGLSurface (EGLAPIENTRYP PFNEGLCREATEPLATFORMPIXMAPSURFACEPROC) (EGLDisplay dpy, EGLConfig config, void *native_pixmap, const EGLAttrib *attrib_list);
411-
typedef EGLBoolean (EGLAPIENTRYP PFNEGLWAITSYNCPROC) (EGLDisplay dpy, EGLSync sync, EGLint flags);
404+
typedef EGLSync(EGLAPIENTRYP PFNEGLCREATESYNCPROC)(EGLDisplay dpy, EGLenum type, const EGLAttrib *attrib_list);
405+
typedef EGLBoolean(EGLAPIENTRYP PFNEGLDESTROYSYNCPROC)(EGLDisplay dpy, EGLSync sync);
406+
typedef EGLint(EGLAPIENTRYP PFNEGLCLIENTWAITSYNCPROC)(EGLDisplay dpy, EGLSync sync, EGLint flags, EGLTime timeout);
407+
typedef EGLBoolean(EGLAPIENTRYP PFNEGLGETSYNCATTRIBPROC)(EGLDisplay dpy, EGLSync sync, EGLint attribute, EGLAttrib *value);
408+
typedef EGLImage(EGLAPIENTRYP PFNEGLCREATEIMAGEPROC)(
409+
EGLDisplay dpy,
410+
EGLContext ctx,
411+
EGLenum target,
412+
EGLClientBuffer buffer,
413+
const EGLAttrib *attrib_list
414+
);
415+
typedef EGLBoolean(EGLAPIENTRYP PFNEGLDESTROYIMAGEPROC)(EGLDisplay dpy, EGLImage image);
416+
typedef EGLDisplay(EGLAPIENTRYP PFNEGLGETPLATFORMDISPLAYPROC)(EGLenum platform, void *native_display, const EGLAttrib *attrib_list);
417+
typedef EGLSurface(EGLAPIENTRYP PFNEGLCREATEPLATFORMWINDOWSURFACEPROC)(
418+
EGLDisplay dpy,
419+
EGLConfig config,
420+
void *native_window,
421+
const EGLAttrib *attrib_list
422+
);
423+
typedef EGLSurface(EGLAPIENTRYP PFNEGLCREATEPLATFORMPIXMAPSURFACEPROC)(
424+
EGLDisplay dpy,
425+
EGLConfig config,
426+
void *native_pixmap,
427+
const EGLAttrib *attrib_list
428+
);
429+
typedef EGLBoolean(EGLAPIENTRYP PFNEGLWAITSYNCPROC)(EGLDisplay dpy, EGLSync sync, EGLint flags);
412430
#endif
413431

414432
#ifdef HAVE_EGL
@@ -432,7 +450,6 @@ static inline bool check_egl_extension(const char *client_ext_string, const char
432450
return false;
433451
}
434452

435-
436453
static inline const char *egl_strerror(EGLenum result) {
437454
switch (result) {
438455
case EGL_SUCCESS: return "EGL_SUCCESS";
@@ -454,7 +471,7 @@ static inline const char *egl_strerror(EGLenum result) {
454471
}
455472
}
456473

457-
#define LOG_EGL_ERROR(result, fmt, ...) LOG_ERROR(fmt ": %s\n", __VA_ARGS__ egl_strerror(result))
474+
#define LOG_EGL_ERROR(result, fmt, ...) LOG_ERROR(fmt ": %s\n", __VA_ARGS__ egl_strerror(result))
458475
#endif
459476

460477
#endif // _FLUTTERPI_INCLUDE_EGL_H

0 commit comments

Comments
 (0)