-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathCMakeLists.txt
788 lines (702 loc) · 25.3 KB
/
CMakeLists.txt
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
# yagears Yet Another Gears OpenGL / Vulkan demo
# Copyright (C) 2013-2024 Nicolas Caramelli
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
cmake_minimum_required(VERSION 3.0)
project(yagears VERSION 2.8)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
include(CheckLibraryExists)
include(CheckCSourceCompiles)
include(GNUInstallDirs)
find_package(PkgConfig)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -D_GNU_SOURCE")
link_libraries(m)
# Configuration options
option(ENABLE_ENGINE_CTOR "Use constructor attribute to register an engine" ON)
if(ENABLE_ENGINE_CTOR)
add_definitions(-DENGINE_CTOR)
endif()
option(ENABLE_GL "OpenGL 1.0 Engine" ON)
option(ENABLE_GLESV1_CM "OpenGL ES 1.1 CM Engine" ON)
option(ENABLE_GLESV2 "OpenGL ES 2.0 Engine" ON)
set(WITH_PGL OFF CACHE STRING "PATH to PortableGL platform header")
set(WITH_PGL_CFLAGS CACHE STRING "CFLAGS for PortableGL platform header")
option(ENABLE_GL_X11 "OpenGL extension for Xlib Backend" ON)
option(ENABLE_GL_DIRECTFB "OpenGL extension for DirectFB Backend" ON)
option(ENABLE_GL_FBDEV "OpenGL extension for Linux Framebuffer Backend" ON)
option(ENABLE_EGL_X11 "EGL interface for Xlib Backend" ON)
option(ENABLE_EGL_DIRECTFB "EGL interface for DirectFB Backend" ON)
option(ENABLE_EGL_FBDEV "EGL interface for Linux Framebuffer Backend" ON)
option(ENABLE_EGL_WAYLAND "EGL interface for Wayland Backend" ON)
option(ENABLE_EGL_XCB "EGL interface for XCB Backend" ON)
option(ENABLE_EGL_DRM "EGL interface for DRM Backend" ON)
option(ENABLE_EGL_RPI "EGL interface for Raspberry Pi Dispmanx Backend" ON)
option(ENABLE_WAFFLE "Waffle cross-platform wrapper" ON)
option(ENABLE_VK_X11 "Vulkan extension for Xlib WSI" ON)
option(ENABLE_VK_DIRECTFB "Vulkan extension for DirectFB WSI" ON)
option(ENABLE_VK_FBDEV "Vulkan extension for Linux Framebuffer WSI" ON)
option(ENABLE_VK_WAYLAND "Vulkan extension for Wayland WSI" ON)
option(ENABLE_VK_XCB "Vulkan extension for XCB WSI" ON)
option(ENABLE_VK_D2D "Vulkan extension for Direct-to-Display WSI" ON)
option(ENABLE_EFL "EFL GUI Toolkit" ON)
option(ENABLE_FLTK "FLTK GUI Toolkit" ON)
option(ENABLE_GLFW "GLFW GUI Toolkit" ON)
option(ENABLE_GLUT "GLUT GUI Toolkit" ON)
option(ENABLE_GTK "GTK+ GUI Toolkit" ON)
option(ENABLE_QT "Qt GUI Toolkit" ON)
option(ENABLE_SDL "SDL GUI Toolkit" ON)
option(ENABLE_SFML "SFML GUI Toolkit" ON)
option(ENABLE_WX "wxWidgets GUI Toolkit" ON)
set(WITH_GTK 3 CACHE STRING "GTK+ GUI Toolkit version")
set_property(CACHE WITH_GTK PROPERTY STRINGS 2 3)
set(WITH_QT 5 CACHE STRING "Qt GUI Toolkit version")
set_property(CACHE WITH_QT PROPERTY STRINGS 4 5)
set(WITH_SDL 2 CACHE STRING "SDL GUI Toolkit version")
set_property(CACHE WITH_SDL PROPERTY STRINGS 1 2)
option(ENABLE_PNG "PNG loader" ON)
option(ENABLE_TIFF "TIFF loader" ON)
# OpenGL Engines
if(WITH_PGL)
set(ENABLE_GL OFF)
set(ENABLE_GLESV1_CM OFF)
set(ENABLE_GLESV2 OFF)
if(EXISTS ${WITH_PGL})
if(WITH_PGL_CFLAGS)
STRING(REPLACE " " ";" WITH_PGL_CFLAGS ${WITH_PGL_CFLAGS})
endif()
set(PGL_CFLAGS -DPGL_H="${WITH_PGL}" ${WITH_PGL_CFLAGS})
else()
message(FATAL_ERROR "PortableGL platform header not found")
endif()
endif()
if(ENABLE_GL)
pkg_check_modules(GL gl)
if(GL_FOUND)
if(ENABLE_GLESV1_CM)
list(APPEND GL_CFLAGS -DGLESV1_CM_H=<GL/gl.h> -DGLESV1_CM_LIB="libGL.so.1" -DGL_GLEXT_PROTOTYPES)
endif()
if(ENABLE_GLESV2)
find_program(XXD xxd)
if(XXD)
list(APPEND GL_CFLAGS -DGLESV2_H=<GL/gl.h> -DGLESV2_LIB="libGL.so.1" -DGL_GLEXT_PROTOTYPES)
else()
set(ENABLE_GLESV2 OFF)
endif()
endif()
if(ENABLE_GLESV1_CM OR ENABLE_GLESV2)
list(APPEND GL_LDFLAGS -ldl)
endif()
else()
set(ENABLE_GL OFF)
endif()
endif()
if(NOT ENABLE_GL)
if(ENABLE_GLESV1_CM)
pkg_check_modules(GLESV1_CM glesv1_cm)
if(GLESV1_CM_FOUND)
list(APPEND GLESV1_CM_CFLAGS -DGLESV1_CM_H=<GLES/gl.h> -DGLESV1_CM_LIB="libGLESv1_CM.so.1")
set(GLESV1_CM_LDFLAGS -ldl)
else()
set(ENABLE_GLESV1_CM OFF)
endif()
endif()
if(ENABLE_GLESV2)
pkg_check_modules(GLESV2 glesv2)
find_program(XXD xxd)
if(GLESV2_FOUND AND XXD)
list(APPEND GLESV2_CFLAGS -DGLESV2_H=<GLES2/gl2.h> -DGLESV2_LIB="libGLESv2.so.2")
set(GLESV2_LDFLAGS -ldl)
else()
set(ENABLE_GLESV2 OFF)
endif()
endif()
endif()
if(NOT ENABLE_GL AND NOT ENABLE_GLESV1_CM AND NOT ENABLE_GLESV2 AND NOT WITH_PGL)
message(WARNING "No OpenGL Engines found")
endif()
# OpenGL Backends
if(ENABLE_GL)
if(ENABLE_GL_X11)
execute_process(COMMAND pkg-config --variable=libdir gl OUTPUT_VARIABLE LIBDIR)
string(STRIP ${LIBDIR} LIBDIR)
check_library_exists(GL glXCreateContext ${LIBDIR} GLX_FOUND)
if(GLX_FOUND)
pkg_check_modules(X11 x11)
if(NOT X11_FOUND)
set(ENABLE_GL_X11 OFF)
endif()
else()
set(ENABLE_GL_X11 OFF)
endif()
endif()
else()
set(ENABLE_GL_X11 OFF)
endif()
set(GL_X11 ${ENABLE_GL_X11})
if(ENABLE_GL_DIRECTFB)
message(STATUS "Checking for DirectFBGL module")
execute_process(COMMAND pkg-config --variable=moduledir directfb-internal OUTPUT_VARIABLE MODULEDIR ERROR_QUIET)
string(STRIP "${MODULEDIR}" MODULEDIR)
if(EXISTS ${MODULEDIR}/interfaces/IDirectFBGL)
message(STATUS " Found")
pkg_check_modules(DIRECTFB directfb)
if(NOT DIRECTFB_FOUND)
set(ENABLE_GL_DIRECTFB OFF)
endif()
else()
message(STATUS " Not found")
set(ENABLE_GL_DIRECTFB OFF)
endif()
else()
set(ENABLE_GL_DIRECTFB OFF)
endif()
set(GL_DIRECTFB ${ENABLE_GL_DIRECTFB})
if(ENABLE_GL)
if(ENABLE_GL_FBDEV)
execute_process(COMMAND pkg-config --variable=libdir gl OUTPUT_VARIABLE LIBDIR)
string(STRIP ${LIBDIR} LIBDIR)
check_library_exists(GL glFBDevCreateContext ${LIBDIR} GLFBDEV_FOUND)
if(NOT GLFBDEV_FOUND)
set(ENABLE_GL_FBDEV OFF)
endif()
endif()
else()
set(ENABLE_GL_FBDEV OFF)
endif()
set(GL_FBDEV ${ENABLE_GL_FBDEV})
if(ENABLE_EGL_X11 OR ENABLE_EGL_DIRECTFB OR ENABLE_EGL_FBDEV OR ENABLE_EGL_WAYLAND OR ENABLE_EGL_XCB OR ENABLE_EGL_DRM OR ENABLE_EGL_RPI)
if(NOT WITH_PGL)
pkg_check_modules(EGL egl)
endif()
if(EGL_FOUND)
list(APPEND EGL_CFLAGS -DEGL_NO_PLATFORM_SPECIFIC_TYPES -DEGL_EGLEXT_PROTOTYPES)
if(ENABLE_EGL_X11)
if(NOT ENABLE_GL_X11)
pkg_check_modules(X11 x11)
if(NOT X11_FOUND)
set(ENABLE_EGL_X11 OFF)
endif()
endif()
endif()
if(ENABLE_EGL_DIRECTFB)
if(NOT ENABLE_GL_DIRECTFB)
pkg_check_modules(DIRECTFB directfb)
if(NOT DIRECTFB_FOUND)
set(ENABLE_EGL_DIRECTFB OFF)
endif()
endif()
endif()
if(ENABLE_EGL_WAYLAND)
pkg_check_modules(WAYLAND wayland-client xkbcommon)
if(WAYLAND_FOUND)
message(STATUS "Looking for wl_shell_surface_set_position")
set(CMAKE_REQUIRED_FLAGS ${WAYLAND_CFLAGS})
set(CMAKE_REQUIRED_LIBRARIES ${WAYLAND_LDFLAGS})
set(CODE "
#include <wayland-client.h>
int main()
{
wl_shell_surface_set_position(NULL, 0, 0);
return 0;
}
")
check_c_source_compiles("${CODE}" HAVE_WL_SHELL_SURFACE_SET_POSITION)
unset(CMAKE_REQUIRED_FLAGS)
unset(CMAKE_REQUIRED_LIBRARIES)
set(WAYLAND_EGL_CFLAGS ${WAYLAND_CFLAGS})
set(WAYLAND_EGL_LDFLAGS ${WAYLAND_LDFLAGS} -lwayland-egl)
else()
set(ENABLE_EGL_WAYLAND OFF)
endif()
endif()
if(ENABLE_EGL_XCB)
pkg_check_modules(XCB xcb)
if(NOT XCB_FOUND)
set(ENABLE_EGL_XCB OFF)
endif()
endif()
if(ENABLE_EGL_DRM)
pkg_check_modules(DRM gbm libdrm libevdev)
if(DRM_FOUND)
pkg_check_modules(DRI dri)
if(DRI_FOUND)
execute_process(COMMAND pkg-config --variable=dridriverdir dri OUTPUT_VARIABLE DRIDRIVERDIR)
string(STRIP ${DRIDRIVERDIR} DRIDRIVERDIR)
execute_process(COMMAND pkg-config --modversion dri OUTPUT_VARIABLE MODVERSION)
string(STRIP ${MODVERSION} MODVERSION)
string(REGEX REPLACE "([0-9]+).([0-9]+).([0-9]+)" \\1 DRIMAJORVERSION ${MODVERSION})
string(REGEX REPLACE "([0-9]+).([0-9]+).([0-9]+)" \\2 DRIMINORVERSION ${MODVERSION})
list(APPEND DRM_CFLAGS -DDRI_DRIVERDIR="${DRIDRIVERDIR}" -DDRI_MAJOR_VERSION=${DRIMAJORVERSION} -DDRI_MINOR_VERSION=${DRIMINORVERSION})
list(APPEND DRM_LDFLAGS -ldl)
set(HAVE_DRI ON)
endif()
else()
set(ENABLE_EGL_DRM OFF)
endif()
endif()
if(ENABLE_EGL_RPI)
pkg_check_modules(RPI bcm_host)
if(RPI_FOUND)
list(APPEND RPI_LDFLAGS -lvchostif)
else()
set(ENABLE_EGL_RPI OFF)
endif()
endif()
else()
set(ENABLE_EGL_X11 OFF)
set(ENABLE_EGL_DIRECTFB OFF)
set(ENABLE_EGL_FBDEV OFF)
set(ENABLE_EGL_WAYLAND OFF)
set(ENABLE_EGL_XCB OFF)
set(ENABLE_EGL_DRM OFF)
set(ENABLE_EGL_RPI OFF)
endif()
endif()
set(EGL_X11 ${ENABLE_EGL_X11})
set(EGL_DIRECTFB ${ENABLE_EGL_DIRECTFB})
set(EGL_FBDEV ${ENABLE_EGL_FBDEV})
set(EGL_WAYLAND ${ENABLE_EGL_WAYLAND})
set(EGL_XCB ${ENABLE_EGL_XCB})
set(EGL_DRM ${ENABLE_EGL_DRM})
set(EGL_RPI ${ENABLE_EGL_RPI})
if(ENABLE_WAFFLE AND NOT WITH_PGL)
pkg_check_modules(WAFFLE libinput waffle-1)
if(NOT WAFFLE_FOUND)
set(ENABLE_WAFFLE OFF)
endif()
else()
set(ENABLE_WAFFLE OFF)
endif()
set(WAFFLE ${ENABLE_WAFFLE})
if(NOT ENABLE_GL_X11 AND NOT ENABLE_GL_DIRECTFB AND NOT ENABLE_GL_FBDEV AND NOT ENABLE_EGL_X11 AND NOT ENABLE_EGL_DIRECTFB AND NOT ENABLE_EGL_FBDEV AND NOT ENABLE_EGL_WAYLAND AND NOT ENABLE_EGL_XCB AND NOT ENABLE_EGL_DRM AND NOT ENABLE_EGL_RPI AND NOT ENABLE_WAFFLE)
message(WARNING "No OpenGL Backends found")
endif()
# Vulkan WSIs
if(ENABLE_VK_X11 OR ENABLE_VK_DIRECTFB OR ENABLE_VK_FBDEV OR ENABLE_VK_WAYLAND OR ENABLE_VK_XCB OR ENABLE_VK_D2D)
pkg_check_modules(VULKAN vulkan)
find_program(GLSLANG_VALIDATOR glslangValidator)
if(VULKAN_FOUND AND GLSLANG_VALIDATOR)
execute_process(COMMAND pkg-config --variable=libdir vulkan OUTPUT_VARIABLE LIBDIR)
string(STRIP ${LIBDIR} LIBDIR)
if(ENABLE_VK_X11)
check_library_exists(vulkan vkCreateXlibSurfaceKHR ${LIBDIR} XLIB_WSI_FOUND)
if(XLIB_WSI_FOUND)
if(NOT ENABLE_GL_X11 AND NOT ENABLE_EGL_X11)
pkg_check_modules(X11 x11)
if(NOT X11_FOUND)
set(ENABLE_VK_X11 OFF)
endif()
endif()
else()
set(ENABLE_VK_X11 OFF)
endif()
endif()
if(ENABLE_VK_DIRECTFB)
check_library_exists(vulkan vkCreateDirectFBSurfaceEXT ${LIBDIR} DIRECTFB_WSI_FOUND)
if(DIRECTFB_WSI_FOUND)
if(NOT ENABLE_GL_DIRECTFB AND NOT ENABLE_EGL_DIRECTFB)
pkg_check_modules(DIRECTFB directfb)
if(NOT DIRECTFB_FOUND)
set(ENABLE_VK_DIRECTFB OFF)
endif()
endif()
else()
set(ENABLE_VK_DIRECTFB OFF)
endif()
endif()
if(ENABLE_VK_FBDEV)
check_library_exists(vulkan vkCreateFBDevSurfaceEXT ${LIBDIR} FBDEV_WSI_FOUND)
if(NOT FBDEV_WSI_FOUND)
set(ENABLE_VK_FBDEV OFF)
endif()
endif()
if(ENABLE_VK_WAYLAND)
check_library_exists(vulkan vkCreateWaylandSurfaceKHR ${LIBDIR} WAYLAND_WSI_FOUND)
if(WAYLAND_WSI_FOUND)
if(NOT ENABLE_EGL_WAYLAND)
pkg_check_modules(WAYLAND wayland-client xkbcommon)
if(WAYLAND_FOUND)
message(STATUS "Looking for wl_shell_surface_set_position")
set(CMAKE_REQUIRED_FLAGS ${WAYLAND_CFLAGS})
set(CMAKE_REQUIRED_LIBRARIES ${WAYLAND_LDFLAGS})
set(CODE "
#include <wayland-client.h>
int main()
{
wl_shell_surface_set_position(NULL, 0, 0);
return 0;
}
")
check_c_source_compiles("${CODE}" HAVE_WL_SHELL_SURFACE_SET_POSITION)
unset(CMAKE_REQUIRED_FLAGS)
unset(CMAKE_REQUIRED_LIBRARIES)
else()
set(ENABLE_VK_WAYLAND OFF)
endif()
endif()
else()
set(ENABLE_VK_WAYLAND OFF)
endif()
endif()
if(ENABLE_VK_XCB)
check_library_exists(vulkan vkCreateXcbSurfaceKHR ${LIBDIR} XCB_WSI_FOUND)
if(XCB_WSI_FOUND)
if(NOT ENABLE_EGL_XCB)
pkg_check_modules(XCB xcb)
if(NOT XCB_FOUND)
set(ENABLE_VK_XCB OFF)
endif()
endif()
else()
set(ENABLE_VK_XCB OFF)
endif()
endif()
if(ENABLE_VK_D2D)
check_library_exists(vulkan vkCreateDisplayPlaneSurfaceKHR ${LIBDIR} D2D_WSI_FOUND)
if(D2D_WSI_FOUND)
pkg_check_modules(D2D libevdev)
if(NOT D2D_FOUND)
set(ENABLE_VK_D2D OFF)
endif()
else()
set(ENABLE_VK_D2D OFF)
endif()
endif()
else()
set(ENABLE_VK_X11 OFF)
set(ENABLE_VK_DIRECTFB OFF)
set(ENABLE_VK_FBDEV OFF)
set(ENABLE_VK_WAYLAND OFF)
set(ENABLE_VK_XCB OFF)
set(ENABLE_VK_D2D OFF)
endif()
endif()
set(VK_X11 ${ENABLE_VK_X11})
set(VK_DIRECTFB ${ENABLE_VK_DIRECTFB})
set(VK_FBDEV ${ENABLE_VK_FBDEV})
set(VK_WAYLAND ${ENABLE_VK_WAYLAND})
set(VK_XCB ${ENABLE_VK_XCB})
set(VK_D2D ${ENABLE_VK_D2D})
if(NOT ENABLE_VK_X11 AND NOT ENABLE_VK_DIRECTFB AND NOT ENABLE_VK_FBDEV AND NOT ENABLE_VK_WAYLAND AND NOT ENABLE_VK_XCB AND NOT ENABLE_VK_D2D)
message(WARNING "No Vulkan WSIs found")
endif()
# Graphical User Interface Toolkits
if(NOT ENABLE_GL AND NOT ENABLE_GLESV1_CM AND NOT ENABLE_GLESV2)
set(ENABLE_GLUT OFF)
endif()
if(WITH_PGL AND NOT ENABLE_VK_X11 AND NOT ENABLE_VK_DIRECTFB AND NOT ENABLE_VK_FBDEV AND NOT ENABLE_VK_WAYLAND AND NOT ENABLE_VK_XCB AND NOT ENABLE_VK_D2D)
set(ENABLE_EFL OFF)
set(ENABLE_FLTK OFF)
set(ENABLE_GLFW OFF)
set(ENABLE_GTK OFF)
set(ENABLE_QT OFF)
set(ENABLE_SDL OFF)
set(ENABLE_SFML OFF)
set(ENABLE_WX OFF)
endif()
if(ENABLE_EFL)
pkg_check_modules(EFL elementary)
if(NOT EFL_FOUND)
set(ENABLE_EFL OFF)
endif()
endif()
set(EFL ${ENABLE_EFL})
if(ENABLE_FLTK)
message(STATUS "Checking for fltk-config")
find_program(FLTK_CONFIG fltk-config)
if(FLTK_CONFIG)
message(STATUS " Found")
execute_process(COMMAND ${FLTK_CONFIG} --cflags OUTPUT_VARIABLE FLTK_CFLAGS)
string(STRIP ${FLTK_CFLAGS} FLTK_CFLAGS)
separate_arguments(FLTK_CFLAGS)
execute_process(COMMAND ${FLTK_CONFIG} --use-gl --ldflags OUTPUT_VARIABLE FLTK_LDFLAGS)
string(STRIP ${FLTK_LDFLAGS} FLTK_LDFLAGS)
else()
message(STATUS " Not found")
set(ENABLE_FLTK OFF)
endif()
endif()
set(FLTK ${ENABLE_FLTK})
if(ENABLE_GLFW)
pkg_check_modules(GLFW glfw3)
if(NOT GLFW_FOUND)
set(ENABLE_GLFW OFF)
endif()
endif()
set(GLFW ${ENABLE_GLFW})
if(ENABLE_GLUT)
pkg_check_modules(GLUT glut)
if(NOT GLUT_FOUND)
unset(GLUT_FOUND CACHE)
check_library_exists(glut glutExit "" GLUT_FOUND)
if(NOT GLUT_FOUND)
set(ENABLE_GLUT OFF)
else()
set(GLUT_LDFLAGS -lglut)
endif()
endif()
endif()
set(GLUT ${ENABLE_GLUT})
if(ENABLE_GTK)
message(STATUS "Checking for GTK+ version: ${WITH_GTK}")
if(WITH_GTK STREQUAL 3)
pkg_check_modules(GTK gtk+-3.0>=3.16.0)
if(NOT GTK_FOUND)
set(ENABLE_GTK OFF)
endif()
else()
set(ENABLE_GTK OFF)
endif()
if(NOT ENABLE_GTK)
if(WITH_GTK STREQUAL 3)
pkg_check_modules(GTK gtkgl-3.0)
if(GTK_FOUND)
set(ENABLE_GTK ON)
else()
set(ENABLE_GTK OFF)
endif()
endif()
if(NOT ENABLE_GTK)
pkg_check_modules(GTK gtkgl-2.0)
if(GTK_FOUND)
set(ENABLE_GTK ON)
else()
set(ENABLE_GTK OFF)
endif()
endif()
endif()
endif()
set(GTK ${ENABLE_GTK})
if(ENABLE_QT)
message(STATUS "Checking for Qt version: ${WITH_QT}")
if(WITH_QT STREQUAL 5)
pkg_check_modules(QT Qt5OpenGL)
if(NOT QT_FOUND)
set(ENABLE_QT OFF)
endif()
else()
set(ENABLE_QT OFF)
endif()
if(NOT ENABLE_QT)
pkg_check_modules(QT QtOpenGL)
if(QT_FOUND)
set(ENABLE_QT ON)
else()
set(ENABLE_QT OFF)
endif()
endif()
endif()
set(QT ${ENABLE_QT})
if(ENABLE_SDL)
message(STATUS "Checking for SDL version: ${WITH_SDL}")
if(WITH_SDL STREQUAL 2)
pkg_check_modules(SDL sdl2)
if(NOT SDL_FOUND)
set(ENABLE_SDL OFF)
set(WITH_SDL 1)
endif()
else()
set(ENABLE_SDL OFF)
endif()
if(NOT ENABLE_SDL)
pkg_check_modules(SDL sdl)
if(SDL_FOUND)
set(ENABLE_SDL ON)
else()
set(ENABLE_SDL OFF)
endif()
endif()
endif()
set(SDL ${ENABLE_SDL})
if(ENABLE_SFML)
pkg_check_modules(SFML sfml-graphics)
if(NOT SFML_FOUND)
set(ENABLE_SFML OFF)
endif()
endif()
set(SFML ${ENABLE_SFML})
if(ENABLE_WX)
message(STATUS "Checking for wx-config")
find_program(WX_CONFIG wx-config)
if(WX_CONFIG)
message(STATUS " Found")
execute_process(COMMAND ${WX_CONFIG} --cflags OUTPUT_VARIABLE WX_CFLAGS)
string(STRIP ${WX_CFLAGS} WX_CFLAGS)
separate_arguments(WX_CFLAGS)
execute_process(COMMAND ${WX_CONFIG} --libs core,gl OUTPUT_VARIABLE WX_LDFLAGS)
string(STRIP ${WX_LDFLAGS} WX_LDFLAGS)
else()
message(STATUS " Not found")
set(ENABLE_WX OFF)
endif()
endif()
set(WX ${ENABLE_WX})
if(NOT ENABLE_EFL AND NOT ENABLE_FLTK AND NOT ENABLE_GLFW AND NOT ENABLE_GLUT AND NOT ENABLE_GTK AND NOT ENABLE_QT AND NOT ENABLE_SDL AND NOT ENABLE_SFML AND NOT ENABLE_WX)
message(WARNING "No Graphical User Interface Toolkits found")
endif()
# Image libraries
if(ENABLE_PNG)
pkg_check_modules(PNG libpng)
if(NOT PNG_FOUND)
set(ENABLE_PNG OFF)
endif()
endif()
if(ENABLE_TIFF)
pkg_check_modules(TIFF libtiff)
if(NOT TIFF_FOUND)
set(ENABLE_TIFF OFF)
endif()
endif()
# Build configuration
configure_file(config.h.cmake config.h)
message("")
message("OpenGL Engines:")
message("")
message(" OpenGL 1.0 ${ENABLE_GL}")
message(" OpenGL ES 1.1 CM ${ENABLE_GLESV1_CM}")
message(" OpenGL ES 2.0 ${ENABLE_GLESV2}")
message(" PortableGL ${WITH_PGL}")
message("")
message("")
message("OpenGL Backends:")
message("")
message(" OpenGL extension for Xlib ${ENABLE_GL_X11}")
message(" OpenGL extension for DirectFB ${ENABLE_GL_DIRECTFB}")
message(" OpenGL extension for Linux FBDev ${ENABLE_GL_FBDEV}")
message(" EGL interface for Xlib ${ENABLE_EGL_X11}")
message(" EGL interface for DirectFB ${ENABLE_EGL_DIRECTFB}")
message(" EGL interface for Linux FBDev ${ENABLE_EGL_FBDEV}")
message(" EGL interface for Wayland ${ENABLE_EGL_WAYLAND}")
message(" EGL interface for XCB ${ENABLE_EGL_XCB}")
message(" EGL interface for DRM ${ENABLE_EGL_DRM}")
message(" EGL interface for RPi Dispmanx ${ENABLE_EGL_RPI}")
message(" Waffle cross-platform wrapper ${ENABLE_WAFFLE}")
message("")
message("")
message("Vulkan WSIs:")
message("")
message(" Vulkan extension for Xlib ${ENABLE_VK_X11}")
message(" Vulkan extension for DirectFB ${ENABLE_VK_DIRECTFB}")
message(" Vulkan extension for Linux FBDev ${ENABLE_VK_FBDEV}")
message(" Vulkan extension for Wayland ${ENABLE_VK_WAYLAND}")
message(" Vulkan extension for XCB ${ENABLE_VK_XCB}")
message(" Vulkan extension for D2D ${ENABLE_VK_D2D}")
message("")
message("")
message("Graphical User Interface Toolkits:")
message("")
message(" EFL ${ENABLE_EFL}")
message(" FLTK ${ENABLE_FLTK}")
message(" GLFW ${ENABLE_GLFW}")
message(" GLUT ${ENABLE_GLUT}")
message(" GTK ${ENABLE_GTK}")
message(" QT ${ENABLE_QT}")
message(" SDL ${ENABLE_SDL}")
message(" SFML ${ENABLE_SFML}")
message(" WX ${ENABLE_WX}")
message("")
# Build rules
set(PNG ${ENABLE_PNG})
set(TIFF ${ENABLE_TIFF})
if(ENABLE_GL OR ENABLE_GLESV1_CM OR ENABLE_GLESV2 OR WITH_PGL)
set(GL ${ENABLE_GL})
set(GLESV1_CM ${ENABLE_GLESV1_CM})
set(GLESV2 ${ENABLE_GLESV2})
if(WITH_PGL)
set(PGL ON)
else()
set(PGL OFF)
endif()
set(OPENGL ON)
else()
set(OPENGL OFF)
endif()
if(ENABLE_VK_X11 OR ENABLE_VK_DIRECTFB OR ENABLE_VK_FBDEV OR ENABLE_VK_WAYLAND OR ENABLE_VK_XCB OR ENABLE_VK_D2D)
set(VK ON)
else()
set(VK OFF)
endif()
set(MOSAIC ${ENABLE_GLUT})
if((ENABLE_GL OR ENABLE_GLESV1_CM OR ENABLE_GLESV2) AND (ENABLE_EFL OR ENABLE_FLTK OR ENABLE_GLFW OR ENABLE_GLUT OR ENABLE_GTK OR ENABLE_QT OR ENABLE_SDL OR ENABLE_SFML OR ENABLE_WX))
set(GUI ON)
else()
set(GUI OFF)
endif()
if((ENABLE_VK_X11 OR ENABLE_VK_DIRECTFB OR ENABLE_VK_FBDEV OR ENABLE_VK_WAYLAND OR ENABLE_VK_XCB OR ENABLE_VK_D2D) AND (ENABLE_GLFW OR ENABLE_SDL AND WITH_SDL STREQUAL 2 OR ENABLE_SFML))
set(VK_GUI ON)
else()
set(VK_GUI OFF)
endif()
if(PNG)
set(PNG_SOURCE png_image.c)
endif()
if(TIFF)
set(TIFF_SOURCE tiff_image.c)
endif()
if(OPENGL)
if(GL)
set(GL_SOURCE gl_gears.c)
endif()
if(GLESV1_CM)
set(GLESV1_CM_SOURCE glesv1_cm_gears.c)
endif()
if(GLESV2)
set(VERT_XXD_FILE vert.xxd)
add_custom_command(OUTPUT ${VERT_XXD_FILE} COMMAND ${CMAKE_SOURCE_DIR}/xxd.sh ${CMAKE_SOURCE_DIR}/glesv2_gears.vert ${VERT_XXD_FILE} DEPENDS ${CMAKE_SOURCE_DIR}/glesv2_gears.vert)
set(FRAG_XXD_FILE frag.xxd)
add_custom_command(OUTPUT ${FRAG_XXD_FILE} COMMAND ${CMAKE_SOURCE_DIR}/xxd.sh ${CMAKE_SOURCE_DIR}/glesv2_gears.frag ${FRAG_XXD_FILE} DEPENDS ${CMAKE_SOURCE_DIR}/glesv2_gears.frag)
set(GLESV2_SOURCE glesv2_gears.c)
endif()
if(PGL)
set(PGL_SOURCE pgl_gears.c)
endif()
add_library(yagears gears_engine.c ${GL_SOURCE} ${GLESV1_CM_SOURCE} ${GLESV2_SOURCE} ${VERT_XXD_FILE} ${FRAG_XXD_FILE} ${PGL_SOURCE} image_loader.c ${PNG_SOURCE} ${TIFF_SOURCE})
target_compile_options(yagears PRIVATE ${GL_CFLAGS} ${GLESV1_CM_CFLAGS} ${GLESV2_CFLAGS} ${PGL_CFLAGS} ${PNG_CFLAGS} ${TIFF_CFLAGS})
target_link_libraries(yagears ${GL_LDFLAGS} ${GLESV1_CM_LDFLAGS} ${GLESV2_LDFLAGS} ${PNG_LDFLAGS} ${TIFF_LDFLAGS})
add_executable(yagears2 main.c)
target_compile_options(yagears2 PRIVATE ${WAFFLE_CFLAGS} ${EGL_CFLAGS} ${X11_CFLAGS} ${DIRECTFB_CFLAGS} ${WAYLAND_EGL_CFLAGS} ${XCB_CFLAGS} ${DRM_CFLAGS} ${RPI_CFLAGS})
target_link_libraries(yagears2 -Wl,--whole-archive yagears -Wl,--no-whole-archive ${WAFFLE_LDFLAGS} ${EGL_LDFLAGS} ${X11_LDFLAGS} ${DIRECTFB_LDFLAGS} ${WAYLAND_EGL_LDFLAGS} ${XCB_LDFLAGS} ${DRM_LDFLAGS} ${RPI_LDFLAGS})
install(TARGETS yagears2 DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()
if(VK)
add_custom_command(OUTPUT vert.spv COMMAND ${GLSLANG_VALIDATOR} ${CMAKE_SOURCE_DIR}/vulkan_gears.vert -V -x DEPENDS ${CMAKE_SOURCE_DIR}/vulkan_gears.vert)
add_custom_command(OUTPUT frag.spv COMMAND ${GLSLANG_VALIDATOR} ${CMAKE_SOURCE_DIR}/vulkan_gears.frag -V -x DEPENDS ${CMAKE_SOURCE_DIR}/vulkan_gears.frag)
add_executable(yagears2-vk vk.c vulkan_gears.c vert.spv frag.spv image_loader.c ${PNG_SOURCE} ${TIFF_SOURCE})
target_compile_options(yagears2-vk PRIVATE ${VULKAN_CFLAGS} ${PNG_CFLAGS} ${TIFF_CFLAGS} ${X11_CFLAGS} ${DIRECTFB_CFLAGS} ${WAYLAND_CFLAGS} ${XCB_CFLAGS} ${D2D_CFLAGS})
target_link_libraries(yagears2-vk ${VULKAN_LDFLAGS} ${PNG_LDFLAGS} ${TIFF_LDFLAGS} ${X11_LDFLAGS} ${DIRECTFB_LDFLAGS} ${WAYLAND_LDFLAGS} ${XCB_LDFLAGS} ${D2D_LDFLAGS})
install(TARGETS yagears2-vk DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()
if(MOSAIC)
add_executable(yagears2-mosaic mosaic.c)
target_compile_options(yagears2-mosaic PRIVATE ${GLUT_CFLAGS})
target_link_libraries(yagears2-mosaic -Wl,--whole-archive yagears -Wl,--no-whole-archive ${GLUT_LDFLAGS})
install(TARGETS yagears2-mosaic DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()
if(GUI)
add_executable(yagears2-gui gui.cc)
target_compile_options(yagears2-gui PRIVATE ${EFL_CFLAGS} ${FLTK_CFLAGS} ${GLFW_CFLAGS} ${GLUT_CFLAGS} ${GTK_CFLAGS} ${QT_CFLAGS} ${SDL_CFLAGS} ${SFML_CFLAGS} ${WX_CFLAGS})
target_link_libraries(yagears2-gui -Wl,--whole-archive yagears -Wl,--no-whole-archive ${EFL_LDFLAGS} ${FLTK_LDFLAGS} ${GLFW_LDFLAGS} ${GLUT_LDFLAGS} ${GTK_LDFLAGS} ${QT_LDFLAGS} ${SDL_LDFLAGS} ${SFML_LDFLAGS} ${WX_LDFLAGS})
install(TARGETS yagears2-gui DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()
if(VK_GUI)
add_executable(yagears2-vk-gui vk-gui.cc vulkan_gears.c image_loader.c ${PNG_SOURCE} ${TIFF_SOURCE})
target_compile_options(yagears2-vk-gui PRIVATE ${VULKAN_CFLAGS} ${PNG_CFLAGS} ${TIFF_CFLAGS} ${GLFW_CFLAGS} ${SDL_CFLAGS} ${SFML_LDFLAGS})
target_link_libraries(yagears2-vk-gui ${VULKAN_LDFLAGS} ${PNG_LDFLAGS} ${TIFF_LDFLAGS} ${GLFW_LDFLAGS} ${SDL_LDFLAGS} ${SFML_LDFLAGS})
install(TARGETS yagears2-vk-gui DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()