summaryrefslogtreecommitdiff
path: root/src/contrib/SDL-2.30.2/cmake/sdlchecks.cmake
diff options
context:
space:
mode:
author3gg <3gg@shellblade.net>2024-05-04 16:51:29 -0700
committer3gg <3gg@shellblade.net>2024-05-04 16:51:29 -0700
commit8222bfe56d4dabe8d92fc4b25ea1b0163b16f3e1 (patch)
tree763389e42276035ac134d94eb1dc32293b88d807 /src/contrib/SDL-2.30.2/cmake/sdlchecks.cmake
Initial commit.
Diffstat (limited to 'src/contrib/SDL-2.30.2/cmake/sdlchecks.cmake')
-rw-r--r--src/contrib/SDL-2.30.2/cmake/sdlchecks.cmake1411
1 files changed, 1411 insertions, 0 deletions
diff --git a/src/contrib/SDL-2.30.2/cmake/sdlchecks.cmake b/src/contrib/SDL-2.30.2/cmake/sdlchecks.cmake
new file mode 100644
index 0000000..8156653
--- /dev/null
+++ b/src/contrib/SDL-2.30.2/cmake/sdlchecks.cmake
@@ -0,0 +1,1411 @@
1include(CMakeParseArguments)
2include(${SDL2_SOURCE_DIR}/cmake/sdlfind.cmake)
3macro(FindLibraryAndSONAME _LIB)
4 cmake_parse_arguments(FLAS "" "" "LIBDIRS" ${ARGN})
5
6 string(TOUPPER ${_LIB} _UPPERLNAME)
7 string(REGEX REPLACE "\\-" "_" _LNAME "${_UPPERLNAME}")
8
9 find_library(${_LNAME}_LIB ${_LIB} PATHS ${FLAS_LIBDIRS})
10
11 if(${_LNAME}_LIB MATCHES ".*\\${CMAKE_SHARED_LIBRARY_SUFFIX}.*" AND NOT ${_LNAME}_LIB MATCHES ".*\\${CMAKE_STATIC_LIBRARY_SUFFIX}.*")
12 set(${_LNAME}_SHARED TRUE)
13 else()
14 set(${_LNAME}_SHARED FALSE)
15 endif()
16
17 if(${_LNAME}_LIB)
18 # reduce the library name for shared linking
19
20 get_filename_component(_LIB_REALPATH ${${_LNAME}_LIB} REALPATH) # resolves symlinks
21 get_filename_component(_LIB_DIRECTORY ${_LIB_REALPATH} DIRECTORY)
22 get_filename_component(_LIB_JUSTNAME ${_LIB_REALPATH} NAME)
23
24 if(APPLE)
25 string(REGEX REPLACE "(\\.[0-9]*)\\.[0-9\\.]*dylib$" "\\1.dylib" _LIB_REGEXD "${_LIB_JUSTNAME}")
26 else()
27 string(REGEX REPLACE "(\\.[0-9]*)\\.[0-9\\.]*$" "\\1" _LIB_REGEXD "${_LIB_JUSTNAME}")
28 endif()
29
30 if(NOT EXISTS "${_LIB_DIRECTORY}/${_LIB_REGEXD}")
31 set(_LIB_REGEXD "${_LIB_JUSTNAME}")
32 endif()
33 set(${_LNAME}_LIBDIR "${_LIB_LIBDIR}")
34
35 SET(_DEBUG_FindSONAME FALSE)
36 if(_DEBUG_FindSONAME)
37 message_warn("DYNLIB OUTPUTVAR: ${_LIB} ... ${_LNAME}_LIB")
38 message_warn("DYNLIB ORIGINAL LIB: ${_LIB} ... ${${_LNAME}_LIB}")
39 message_warn("DYNLIB REALPATH LIB: ${_LIB} ... ${_LIB_REALPATH}")
40 message_warn("DYNLIB JUSTNAME LIB: ${_LIB} ... ${_LIB_JUSTNAME}")
41 message_warn("DYNLIB REGEX'd LIB: ${_LIB} ... ${_LIB_REGEXD}")
42 endif()
43
44 message(STATUS "dynamic lib${_LIB} -> ${_LIB_REGEXD}")
45 set(${_LNAME}_LIB_SONAME ${_LIB_REGEXD})
46 endif()
47endmacro()
48
49macro(CheckDLOPEN)
50 cmake_push_check_state(RESET)
51 check_symbol_exists(dlopen "dlfcn.h" HAVE_DLOPEN_IN_LIBC)
52 if(NOT HAVE_DLOPEN_IN_LIBC)
53 set(CMAKE_REQUIRED_LIBRARIES dl)
54 check_symbol_exists(dlopen "dlfcn.h" HAVE_DLOPEN_IN_LIBDL)
55 if(HAVE_DLOPEN_IN_LIBDL)
56 list(APPEND EXTRA_LIBS dl)
57 endif()
58 endif()
59 if(HAVE_DLOPEN_IN_LIBC OR HAVE_DLOPEN_IN_LIBDL)
60 set(HAVE_DLOPEN TRUE)
61 endif()
62 cmake_pop_check_state()
63endmacro()
64
65macro(CheckO_CLOEXEC)
66 check_c_source_compiles("
67 #include <fcntl.h>
68 int flag = O_CLOEXEC;
69 int main(int argc, char **argv) { return 0; }" HAVE_O_CLOEXEC)
70endmacro()
71
72# Requires:
73# - n/a
74macro(CheckOSS)
75 if(SDL_OSS)
76 check_c_source_compiles("
77 #include <sys/soundcard.h>
78 int main(int argc, char **argv) { int arg = SNDCTL_DSP_SETFRAGMENT; return 0; }" HAVE_OSS_SYS_SOUNDCARD_H)
79
80 if(HAVE_OSS_SYS_SOUNDCARD_H)
81 set(HAVE_OSS TRUE)
82 file(GLOB OSS_SOURCES ${SDL2_SOURCE_DIR}/src/audio/dsp/*.c)
83 set(SDL_AUDIO_DRIVER_OSS 1)
84 list(APPEND SOURCE_FILES ${OSS_SOURCES})
85 if(NETBSD)
86 list(APPEND EXTRA_LIBS ossaudio)
87 endif()
88 set(HAVE_SDL_AUDIO TRUE)
89 endif()
90 endif()
91endmacro()
92
93# Requires:
94# - n/a
95# Optional:
96# - SDL_ALSA_SHARED opt
97# - HAVE_SDL_LOADSO opt
98macro(CheckALSA)
99 if(SDL_ALSA)
100 sdlFindALSA()
101 if(ALSA_FOUND)
102 file(GLOB ALSA_SOURCES "${SDL2_SOURCE_DIR}/src/audio/alsa/*.c")
103 list(APPEND SOURCE_FILES ${ALSA_SOURCES})
104 set(SDL_AUDIO_DRIVER_ALSA 1)
105 set(HAVE_ALSA TRUE)
106 set(HAVE_ALSA_SHARED FALSE)
107 if(SDL_ALSA_SHARED)
108 if(HAVE_SDL_LOADSO)
109 FindLibraryAndSONAME("asound")
110 if(ASOUND_LIB AND ASOUND_SHARED)
111 target_include_directories(sdl-build-options SYSTEM INTERFACE $<TARGET_PROPERTY:ALSA::ALSA,INTERFACE_INCLUDE_DIRECTORIES>)
112 set(SDL_AUDIO_DRIVER_ALSA_DYNAMIC "\"${ASOUND_LIB_SONAME}\"")
113 set(HAVE_ALSA_SHARED TRUE)
114 else()
115 message(WARNING "Unable to find asound shared object")
116 endif()
117 else()
118 message(WARNING "You must have SDL_LoadObject() support for dynamic ALSA loading")
119 endif()
120 endif()
121 if(NOT HAVE_ALSA_SHARED)
122 list(APPEND CMAKE_DEPENDS ALSA::ALSA)
123 list(APPEND PKGCONFIG_DEPENDS alsa)
124 endif()
125 set(HAVE_SDL_AUDIO TRUE)
126 else()
127 set(HAVE_ALSA FALSE)
128 message(WARNING "Unable to found the alsa development library")
129 endif()
130 endif()
131endmacro()
132
133# Requires:
134# - PkgCheckModules
135# Optional:
136# - SDL_PIPEWIRE_SHARED opt
137# - HAVE_SDL_LOADSO opt
138macro(CheckPipewire)
139 if(SDL_PIPEWIRE)
140 pkg_check_modules(PKG_PIPEWIRE libpipewire-0.3>=0.3.20)
141 if(PKG_PIPEWIRE_FOUND)
142 set(HAVE_PIPEWIRE TRUE)
143 file(GLOB PIPEWIRE_SOURCES ${SDL2_SOURCE_DIR}/src/audio/pipewire/*.c)
144 list(APPEND SOURCE_FILES ${PIPEWIRE_SOURCES})
145 set(SDL_AUDIO_DRIVER_PIPEWIRE 1)
146 list(APPEND EXTRA_CFLAGS ${PKG_PIPEWIRE_CFLAGS})
147 if(SDL_PIPEWIRE_SHARED AND NOT HAVE_SDL_LOADSO)
148 message_warn("You must have SDL_LoadObject() support for dynamic Pipewire loading")
149 endif()
150 FindLibraryAndSONAME("pipewire-0.3" LIBDIRS ${PKG_PIPEWIRE_LIBRARY_DIRS})
151 if(SDL_PIPEWIRE_SHARED AND PIPEWIRE_0.3_LIB AND HAVE_SDL_LOADSO)
152 set(SDL_AUDIO_DRIVER_PIPEWIRE_DYNAMIC "\"${PIPEWIRE_0.3_LIB_SONAME}\"")
153 set(HAVE_PIPEWIRE_SHARED TRUE)
154 else()
155 list(APPEND EXTRA_LDFLAGS ${PKG_PIPEWIRE_LDFLAGS})
156 endif()
157 set(HAVE_SDL_AUDIO TRUE)
158 endif()
159 endif()
160endmacro()
161
162# Requires:
163# - PkgCheckModules
164# Optional:
165# - SDL_PULSEAUDIO_SHARED opt
166# - HAVE_SDL_LOADSO opt
167macro(CheckPulseAudio)
168 if(SDL_PULSEAUDIO)
169 pkg_check_modules(PKG_PULSEAUDIO libpulse>=0.9.15)
170 if(PKG_PULSEAUDIO_FOUND)
171 set(HAVE_PULSEAUDIO TRUE)
172 file(GLOB PULSEAUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/pulseaudio/*.c)
173 list(APPEND SOURCE_FILES ${PULSEAUDIO_SOURCES})
174 set(SDL_AUDIO_DRIVER_PULSEAUDIO 1)
175 list(APPEND EXTRA_CFLAGS ${PKG_PULSEAUDIO_CFLAGS})
176 if(SDL_PULSEAUDIO_SHARED AND NOT HAVE_SDL_LOADSO)
177 message_warn("You must have SDL_LoadObject() support for dynamic PulseAudio loading")
178 endif()
179 FindLibraryAndSONAME("pulse" LIBDIRS ${PKG_PULSEAUDIO_LIBRARY_DIRS})
180 if(SDL_PULSEAUDIO_SHARED AND PULSE_LIB AND HAVE_SDL_LOADSO)
181 set(SDL_AUDIO_DRIVER_PULSEAUDIO_DYNAMIC "\"${PULSE_LIB_SONAME}\"")
182 set(HAVE_PULSEAUDIO_SHARED TRUE)
183 else()
184 list(APPEND EXTRA_LDFLAGS ${PKG_PULSEAUDIO_LDFLAGS})
185 endif()
186 set(HAVE_SDL_AUDIO TRUE)
187 endif()
188 endif()
189endmacro()
190
191# Requires:
192# - PkgCheckModules
193# Optional:
194# - SDL_JACK_SHARED opt
195# - HAVE_SDL_LOADSO opt
196macro(CheckJACK)
197 if(SDL_JACK)
198 pkg_check_modules(PKG_JACK jack)
199 if(PKG_JACK_FOUND)
200 set(HAVE_JACK TRUE)
201 file(GLOB JACK_SOURCES ${SDL2_SOURCE_DIR}/src/audio/jack/*.c)
202 list(APPEND SOURCE_FILES ${JACK_SOURCES})
203 set(SDL_AUDIO_DRIVER_JACK 1)
204 list(APPEND EXTRA_CFLAGS ${PKG_JACK_CFLAGS})
205 if(SDL_JACK_SHARED AND NOT HAVE_SDL_LOADSO)
206 message_warn("You must have SDL_LoadObject() support for dynamic JACK audio loading")
207 endif()
208 FindLibraryAndSONAME("jack" LIBDIRS ${PKG_JACK_LIBRARY_DIRS})
209 if(SDL_JACK_SHARED AND JACK_LIB AND HAVE_SDL_LOADSO)
210 set(SDL_AUDIO_DRIVER_JACK_DYNAMIC "\"${JACK_LIB_SONAME}\"")
211 set(HAVE_JACK_SHARED TRUE)
212 else()
213 list(APPEND EXTRA_LDFLAGS ${PKG_JACK_LDFLAGS})
214 endif()
215 set(HAVE_SDL_AUDIO TRUE)
216 endif()
217 endif()
218endmacro()
219
220# Requires:
221# - PkgCheckModules
222# Optional:
223# - SDL_ESD_SHARED opt
224# - HAVE_SDL_LOADSO opt
225macro(CheckESD)
226 if(SDL_ESD)
227 pkg_check_modules(PKG_ESD esound)
228 if(PKG_ESD_FOUND)
229 set(HAVE_ESD TRUE)
230 file(GLOB ESD_SOURCES ${SDL2_SOURCE_DIR}/src/audio/esd/*.c)
231 list(APPEND SOURCE_FILES ${ESD_SOURCES})
232 set(SDL_AUDIO_DRIVER_ESD 1)
233 list(APPEND EXTRA_CFLAGS ${PKG_ESD_CFLAGS})
234 if(SDL_ESD_SHARED AND NOT HAVE_SDL_LOADSO)
235 message_warn("You must have SDL_LoadObject() support for dynamic ESD loading")
236 endif()
237 FindLibraryAndSONAME(esd LIBDIRS ${PKG_ESD_LIBRARY_DIRS})
238 if(SDL_ESD_SHARED AND ESD_LIB AND HAVE_SDL_LOADSO)
239 set(SDL_AUDIO_DRIVER_ESD_DYNAMIC "\"${ESD_LIB_SONAME}\"")
240 set(HAVE_ESD_SHARED TRUE)
241 else()
242 list(APPEND EXTRA_LDFLAGS ${PKG_ESD_LDFLAGS})
243 endif()
244 set(HAVE_SDL_AUDIO TRUE)
245 endif()
246 endif()
247endmacro()
248
249# Requires:
250# - n/a
251# Optional:
252# - SDL_ARTS_SHARED opt
253# - HAVE_SDL_LOADSO opt
254macro(CheckARTS)
255 if(SDL_ARTS)
256 find_program(ARTS_CONFIG arts-config)
257 if(ARTS_CONFIG)
258 execute_process(CMD_ARTSCFLAGS ${ARTS_CONFIG} --cflags
259 OUTPUT_VARIABLE ARTS_CFLAGS OUTPUT_STRIP_TRAILING_WHITESPACE)
260 list(APPEND EXTRA_CFLAGS ${ARTS_CFLAGS})
261 execute_process(CMD_ARTSLIBS ${ARTS_CONFIG} --libs
262 OUTPUT_VARIABLE ARTS_LIBS OUTPUT_STRIP_TRAILING_WHITESPACE)
263 file(GLOB ARTS_SOURCES ${SDL2_SOURCE_DIR}/src/audio/arts/*.c)
264 list(APPEND SOURCE_FILES ${ARTS_SOURCES})
265 set(SDL_AUDIO_DRIVER_ARTS 1)
266 set(HAVE_ARTS TRUE)
267 if(SDL_ARTS_SHARED AND NOT HAVE_SDL_LOADSO)
268 message_warn("You must have SDL_LoadObject() support for dynamic ARTS loading")
269 endif()
270 FindLibraryAndSONAME(artsc)
271 if(SDL_ARTS_SHARED AND ARTSC_LIB AND HAVE_SDL_LOADSO)
272 # TODO
273 set(SDL_AUDIO_DRIVER_ARTS_DYNAMIC "\"${ARTSC_LIB_SONAME}\"")
274 set(HAVE_ARTS_SHARED TRUE)
275 else()
276 list(APPEND EXTRA_LDFLAGS ${ARTS_LIBS})
277 endif()
278 set(HAVE_SDL_AUDIO TRUE)
279 endif()
280 endif()
281endmacro()
282
283# Requires:
284# - n/a
285# Optional:
286# - SDL_NAS_SHARED opt
287# - HAVE_SDL_LOADSO opt
288macro(CheckNAS)
289 if(SDL_NAS)
290 # TODO: set include paths properly, so the NAS headers are found
291 check_include_file(audio/audiolib.h HAVE_NAS_H)
292 find_library(D_NAS_LIB audio)
293 if(HAVE_NAS_H AND D_NAS_LIB)
294 set(HAVE_NAS TRUE)
295 file(GLOB NAS_SOURCES ${SDL2_SOURCE_DIR}/src/audio/nas/*.c)
296 list(APPEND SOURCE_FILES ${NAS_SOURCES})
297 set(SDL_AUDIO_DRIVER_NAS 1)
298 if(SDL_NAS_SHARED AND NOT HAVE_SDL_LOADSO)
299 message_warn("You must have SDL_LoadObject() support for dynamic NAS loading")
300 endif()
301 FindLibraryAndSONAME("audio")
302 if(SDL_NAS_SHARED AND AUDIO_LIB AND HAVE_SDL_LOADSO)
303 set(SDL_AUDIO_DRIVER_NAS_DYNAMIC "\"${AUDIO_LIB_SONAME}\"")
304 set(HAVE_NAS_SHARED TRUE)
305 else()
306 list(APPEND EXTRA_LIBS ${D_NAS_LIB})
307 endif()
308 set(HAVE_SDL_AUDIO TRUE)
309 endif()
310 endif()
311endmacro()
312
313# Requires:
314# - PkgCheckModules
315# Optional:
316# - SDL_SNDIO_SHARED opt
317# - HAVE_SDL_LOADSO opt
318macro(CheckSNDIO)
319 if(SDL_SNDIO)
320 pkg_check_modules(PKG_SNDIO sndio)
321 if(PKG_SNDIO_FOUND)
322 set(HAVE_SNDIO TRUE)
323 file(GLOB SNDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/sndio/*.c)
324 list(APPEND SOURCE_FILES ${SNDIO_SOURCES})
325 set(SDL_AUDIO_DRIVER_SNDIO 1)
326 list(APPEND EXTRA_CFLAGS ${PKG_SNDIO_CFLAGS})
327 if(SDL_SNDIO_SHARED AND NOT HAVE_SDL_LOADSO)
328 message_warn("You must have SDL_LoadObject() support for dynamic sndio loading")
329 endif()
330 FindLibraryAndSONAME("sndio" LIBDIRS ${PKG_SNDIO_LIBRARY_DIRS})
331 if(SDL_SNDIO_SHARED AND SNDIO_LIB AND HAVE_SDL_LOADSO)
332 set(SDL_AUDIO_DRIVER_SNDIO_DYNAMIC "\"${SNDIO_LIB_SONAME}\"")
333 set(HAVE_SNDIO_SHARED TRUE)
334 else()
335 list(APPEND EXTRA_LIBS ${PKG_SNDIO_LDFLAGS})
336 endif()
337 set(HAVE_SDL_AUDIO TRUE)
338 endif()
339 endif()
340endmacro()
341
342# Requires:
343# - PkgCheckModules
344# Optional:
345# - FUSIONSOUND_SHARED opt
346# - HAVE_SDL_LOADSO opt
347macro(CheckFusionSound)
348 if(FUSIONSOUND)
349 pkg_check_modules(PKG_FUSIONSOUND fusionsound>=1.0.0)
350 if(PKG_FUSIONSOUND_FOUND)
351 set(HAVE_FUSIONSOUND TRUE)
352 file(GLOB FUSIONSOUND_SOURCES ${SDL2_SOURCE_DIR}/src/audio/fusionsound/*.c)
353 list(APPEND SOURCE_FILES ${FUSIONSOUND_SOURCES})
354 set(SDL_AUDIO_DRIVER_FUSIONSOUND 1)
355 list(APPEND EXTRA_CFLAGS ${PKG_FUSIONSOUND_CFLAGS})
356 if(FUSIONSOUND_SHARED AND NOT HAVE_SDL_LOADSO)
357 message_warn("You must have SDL_LoadObject() support for dynamic FusionSound loading")
358 endif()
359 FindLibraryAndSONAME("fusionsound" LIBDIRS ${PKG_FUSIONSOUND_LIBRARY_DIRS})
360 if(FUSIONSOUND_SHARED AND FUSIONSOUND_LIB AND HAVE_SDL_LOADSO)
361 set(SDL_AUDIO_DRIVER_FUSIONSOUND_DYNAMIC "\"${FUSIONSOUND_LIB_SONAME}\"")
362 set(HAVE_FUSIONSOUND_SHARED TRUE)
363 else()
364 list(APPEND EXTRA_LDFLAGS ${PKG_FUSIONSOUND_LDFLAGS})
365 endif()
366 set(HAVE_SDL_AUDIO TRUE)
367 endif()
368 endif()
369endmacro()
370
371# Requires:
372# - SDL_LIBSAMPLERATE
373# Optional:
374# - SDL_LIBSAMPLERATE_SHARED opt
375# - HAVE_SDL_LOADSO opt
376macro(CheckLibSampleRate)
377 if(SDL_LIBSAMPLERATE)
378 find_package(SampleRate QUIET)
379 if(SampleRate_FOUND AND TARGET SampleRate::samplerate)
380 set(HAVE_LIBSAMPLERATE TRUE)
381 set(HAVE_LIBSAMPLERATE_H TRUE)
382 if(SDL_LIBSAMPLERATE_SHARED)
383 target_include_directories(sdl-build-options SYSTEM INTERFACE $<TARGET_PROPERTY:SampleRate::samplerate,INTERFACE_INCLUDE_DIRECTORIES>)
384 if(NOT HAVE_SDL_LOADSO)
385 message_warn("You must have SDL_LoadObject() support for dynamic libsamplerate loading")
386 else()
387 get_property(_samplerate_type TARGET SampleRate::samplerate PROPERTY TYPE)
388 if(_samplerate_type STREQUAL "SHARED_LIBRARY")
389 set(HAVE_LIBSAMPLERATE_SHARED TRUE)
390 if(WIN32 OR OS2)
391 set(SDL_LIBSAMPLERATE_DYNAMIC "\"$<TARGET_FILE_NAME:SampleRate::samplerate>\"")
392 else()
393 set(SDL_LIBSAMPLERATE_DYNAMIC "\"$<TARGET_SONAME_FILE_NAME:SampleRate::samplerate>\"")
394 endif()
395 endif()
396 endif()
397 else()
398 target_link_libraries(sdl-build-options INTERFACE SampleRate::samplerate)
399 list(APPEND SDL_REQUIRES_PRIVATE SampleRate::samplerate)
400 endif()
401 else()
402 check_include_file(samplerate.h HAVE_LIBSAMPLERATE_H)
403 if(HAVE_LIBSAMPLERATE_H)
404 set(HAVE_LIBSAMPLERATE TRUE)
405 if(SDL_LIBSAMPLERATE_SHARED AND NOT HAVE_SDL_LOADSO)
406 message_warn("You must have SDL_LoadObject() support for dynamic libsamplerate loading")
407 endif()
408 FindLibraryAndSONAME("samplerate")
409 if(SDL_LIBSAMPLERATE_SHARED AND SAMPLERATE_LIB AND HAVE_SDL_LOADSO)
410 set(SDL_LIBSAMPLERATE_DYNAMIC "\"${SAMPLERATE_LIB_SONAME}\"")
411 set(HAVE_LIBSAMPLERATE_SHARED TRUE)
412 else()
413 list(APPEND EXTRA_LDFLAGS -lsamplerate)
414 endif()
415 endif()
416 endif()
417 endif()
418endmacro()
419
420# Requires:
421# - n/a
422# Optional:
423# - SDL_X11_SHARED opt
424# - HAVE_SDL_LOADSO opt
425macro(CheckX11)
426 cmake_push_check_state(RESET)
427 if(SDL_X11)
428 foreach(_LIB X11 Xext Xcursor Xi Xfixes Xrandr Xrender Xss)
429 FindLibraryAndSONAME("${_LIB}")
430 endforeach()
431
432 set(X11_dirs)
433 find_path(X_INCLUDEDIR
434 NAMES X11/Xlib.h
435 PATHS
436 /usr/pkg/xorg/include
437 /usr/X11R6/include
438 /usr/X11R7/include
439 /usr/local/include/X11
440 /usr/include/X11
441 /usr/openwin/include
442 /usr/openwin/share/include
443 /opt/graphics/OpenGL/include
444 /opt/X11/include
445 )
446
447 if(X_INCLUDEDIR)
448 list(APPEND EXTRA_CFLAGS "-I${X_INCLUDEDIR}")
449 list(APPEND CMAKE_REQUIRED_INCLUDES ${X_INCLUDEDIR})
450 endif()
451
452 find_file(HAVE_XCURSOR_H NAMES "X11/Xcursor/Xcursor.h" HINTS "${X_INCLUDEDIR}")
453 find_file(HAVE_XINPUT2_H NAMES "X11/extensions/XInput2.h" HINTS "${X_INCLUDEDIR}")
454 find_file(HAVE_XRANDR_H NAMES "X11/extensions/Xrandr.h" HINTS "${X_INCLUDEDIR}")
455 find_file(HAVE_XFIXES_H_ NAMES "X11/extensions/Xfixes.h" HINTS "${X_INCLUDEDIR}")
456 find_file(HAVE_XRENDER_H NAMES "X11/extensions/Xrender.h" HINTS "${X_INCLUDEDIR}")
457 find_file(HAVE_XSS_H NAMES "X11/extensions/scrnsaver.h" HINTS "${X_INCLUDEDIR}")
458 find_file(HAVE_XSHAPE_H NAMES "X11/extensions/shape.h" HINTS "${X_INCLUDEDIR}")
459 find_file(HAVE_XDBE_H NAMES "X11/extensions/Xdbe.h" HINTS "${X_INCLUDEDIR}")
460 find_file(HAVE_XEXT_H NAMES "X11/extensions/Xext.h" HINTS "${X_INCLUDEDIR}")
461
462 if(X11_LIB)
463 if(NOT HAVE_XEXT_H)
464 message_error("Missing Xext.h, maybe you need to install the libxext-dev package?")
465 endif()
466
467 set(HAVE_X11 TRUE)
468 set(HAVE_SDL_VIDEO TRUE)
469
470 file(GLOB X11_SOURCES ${SDL2_SOURCE_DIR}/src/video/x11/*.c)
471 list(APPEND SOURCE_FILES ${X11_SOURCES})
472 set(SDL_VIDEO_DRIVER_X11 1)
473
474 # Note: Disabled on Apple because the dynamic mode backend for X11 doesn't
475 # work properly on Apple during several issues like inconsistent paths
476 # among platforms. See #6778 (https://github.com/libsdl-org/SDL/issues/6778)
477 if(APPLE)
478 set(SDL_X11_SHARED OFF)
479 endif()
480
481 check_symbol_exists(shmat "sys/shm.h" HAVE_SHMAT_IN_LIBC)
482 if(NOT HAVE_SHMAT_IN_LIBC)
483 check_library_exists(ipc shmat "" HAVE_SHMAT_IN_LIBIPC)
484 if(HAVE_SHMAT_IN_LIBIPC)
485 list(APPEND EXTRA_LIBS ipc)
486 endif()
487 if(NOT HAVE_SHMAT_IN_LIBIPC)
488 list(APPEND EXTRA_CFLAGS "-DNO_SHARED_MEMORY")
489 endif()
490 endif()
491
492 if(SDL_X11_SHARED)
493 if(NOT HAVE_SDL_LOADSO)
494 message_warn("You must have SDL_LoadObject() support for dynamic X11 loading")
495 set(HAVE_X11_SHARED FALSE)
496 else()
497 set(HAVE_X11_SHARED TRUE)
498 endif()
499 if(X11_LIB)
500 if(HAVE_X11_SHARED)
501 set(SDL_VIDEO_DRIVER_X11_DYNAMIC "\"${X11_LIB_SONAME}\"")
502 else()
503 list(APPEND EXTRA_LIBS ${X11_LIB})
504 endif()
505 endif()
506 if(XEXT_LIB)
507 if(HAVE_X11_SHARED)
508 set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT "\"${XEXT_LIB_SONAME}\"")
509 else()
510 list(APPEND EXTRA_LIBS ${XEXT_LIB_SONAME})
511 endif()
512 endif()
513 else()
514 list(APPEND EXTRA_LIBS ${X11_LIB} ${XEXT_LIB})
515 endif()
516
517 set(CMAKE_REQUIRED_LIBRARIES ${X11_LIB} ${X11_LIB})
518
519 check_c_source_compiles("
520 #include <X11/Xlib.h>
521 int main(int argc, char **argv) {
522 Display *display;
523 XEvent event;
524 XGenericEventCookie *cookie = &event.xcookie;
525 XNextEvent(display, &event);
526 XGetEventData(display, cookie);
527 XFreeEventData(display, cookie);
528 return 0; }" HAVE_XGENERICEVENT)
529 if(HAVE_XGENERICEVENT)
530 set(SDL_VIDEO_DRIVER_X11_SUPPORTS_GENERIC_EVENTS 1)
531 endif()
532
533 check_symbol_exists(XkbKeycodeToKeysym "X11/Xlib.h;X11/XKBlib.h" SDL_VIDEO_DRIVER_X11_HAS_XKBKEYCODETOKEYSYM)
534
535 if(SDL_X11_XCURSOR AND HAVE_XCURSOR_H AND XCURSOR_LIB)
536 set(HAVE_X11_XCURSOR TRUE)
537 if(HAVE_X11_SHARED)
538 set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XCURSOR "\"${XCURSOR_LIB_SONAME}\"")
539 else()
540 list(APPEND EXTRA_LIBS ${XCURSOR_LIB})
541 endif()
542 set(SDL_VIDEO_DRIVER_X11_XCURSOR 1)
543 endif()
544
545 if(SDL_X11_XDBE AND HAVE_XDBE_H)
546 set(HAVE_X11_XDBE TRUE)
547 set(SDL_VIDEO_DRIVER_X11_XDBE 1)
548 endif()
549
550 if(SDL_X11_XINPUT AND HAVE_XINPUT2_H AND XI_LIB)
551 set(HAVE_X11_XINPUT TRUE)
552 if(HAVE_X11_SHARED)
553 set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT2 "\"${XI_LIB_SONAME}\"")
554 else()
555 list(APPEND EXTRA_LIBS ${XI_LIB})
556 endif()
557 set(SDL_VIDEO_DRIVER_X11_XINPUT2 1)
558
559 # Check for multitouch
560 check_c_source_compiles("
561 #include <X11/Xlib.h>
562 #include <X11/Xproto.h>
563 #include <X11/extensions/XInput2.h>
564 int event_type = XI_TouchBegin;
565 XITouchClassInfo *t;
566 Status XIAllowTouchEvents(Display *a,int b,unsigned int c,Window d,int f) {
567 return (Status)0;
568 }
569 int main(int argc, char **argv) { return 0; }" HAVE_XINPUT2_MULTITOUCH)
570 if(HAVE_XINPUT2_MULTITOUCH)
571 set(SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH 1)
572 endif()
573 endif()
574
575 # check along with XInput2.h because we use Xfixes with XIBarrierReleasePointer
576 if(SDL_X11_XFIXES AND HAVE_XFIXES_H_ AND HAVE_XINPUT2_H)
577 check_c_source_compiles("
578 #include <X11/Xlib.h>
579 #include <X11/Xproto.h>
580 #include <X11/extensions/XInput2.h>
581 #include <X11/extensions/Xfixes.h>
582 BarrierEventID b;
583 int main(int argc, char **argv) { return 0; }" HAVE_XFIXES_H)
584 endif()
585 if(SDL_X11_XFIXES AND HAVE_XFIXES_H AND HAVE_XINPUT2_H AND XFIXES_LIB)
586 if(HAVE_X11_SHARED)
587 set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XFIXES "\"${XFIXES_LIB_SONAME}\"")
588 else()
589 list(APPEND EXTRA_LIBS ${XFIXES_LIB})
590 endif()
591 set(SDL_VIDEO_DRIVER_X11_XFIXES 1)
592 set(HAVE_X11_XFIXES TRUE)
593 endif()
594
595 if(SDL_X11_XRANDR AND HAVE_XRANDR_H AND XRANDR_LIB)
596 if(HAVE_X11_SHARED)
597 set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR "\"${XRANDR_LIB_SONAME}\"")
598 else()
599 list(APPEND EXTRA_LIBS ${XRANDR_LIB})
600 endif()
601 set(SDL_VIDEO_DRIVER_X11_XRANDR 1)
602 set(HAVE_X11_XRANDR TRUE)
603 endif()
604
605 if(SDL_X11_XSCRNSAVER AND HAVE_XSS_H AND XSS_LIB)
606 if(HAVE_X11_SHARED)
607 set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XSS "\"${XSS_LIB_SONAME}\"")
608 else()
609 list(APPEND EXTRA_LIBS ${XSS_LIB})
610 endif()
611 set(SDL_VIDEO_DRIVER_X11_XSCRNSAVER 1)
612 set(HAVE_X11_XSCRNSAVER TRUE)
613 endif()
614
615 if(SDL_X11_XSHAPE AND HAVE_XSHAPE_H)
616 set(SDL_VIDEO_DRIVER_X11_XSHAPE 1)
617 set(HAVE_X11_XSHAPE TRUE)
618 endif()
619
620 set(CMAKE_REQUIRED_LIBRARIES)
621 endif()
622 endif()
623 if(NOT HAVE_X11)
624 # Prevent Mesa from including X11 headers
625 list(APPEND EXTRA_CFLAGS "-DMESA_EGL_NO_X11_HEADERS -DEGL_NO_X11")
626 endif()
627 cmake_pop_check_state()
628endmacro()
629
630macro(WaylandProtocolGen _SCANNER _CODE_MODE _XML _PROTL)
631 set(_WAYLAND_PROT_C_CODE "${CMAKE_CURRENT_BINARY_DIR}/wayland-generated-protocols/${_PROTL}-protocol.c")
632 set(_WAYLAND_PROT_H_CODE "${CMAKE_CURRENT_BINARY_DIR}/wayland-generated-protocols/${_PROTL}-client-protocol.h")
633
634 add_custom_command(
635 OUTPUT "${_WAYLAND_PROT_H_CODE}"
636 DEPENDS "${_XML}"
637 COMMAND "${_SCANNER}"
638 ARGS client-header "${_XML}" "${_WAYLAND_PROT_H_CODE}"
639 )
640
641 add_custom_command(
642 OUTPUT "${_WAYLAND_PROT_C_CODE}"
643 DEPENDS "${_WAYLAND_PROT_H_CODE}"
644 COMMAND "${_SCANNER}"
645 ARGS "${_CODE_MODE}" "${_XML}" "${_WAYLAND_PROT_C_CODE}"
646 )
647
648 list(APPEND SDL_GENERATED_HEADERS "${_WAYLAND_PROT_H_CODE}")
649 list(APPEND SOURCE_FILES "${_WAYLAND_PROT_C_CODE}")
650endmacro()
651
652# Requires:
653# - EGL
654# - PkgCheckModules
655# Optional:
656# - SDL_WAYLAND_SHARED opt
657# - HAVE_SDL_LOADSO opt
658macro(CheckWayland)
659 if(SDL_WAYLAND)
660 set(WAYLAND_FOUND FALSE)
661 pkg_check_modules(PKG_WAYLAND "wayland-client>=1.18" wayland-egl wayland-cursor egl "xkbcommon>=0.5.0")
662
663 if(PKG_WAYLAND_FOUND)
664 set(WAYLAND_FOUND TRUE)
665 find_program(WAYLAND_SCANNER NAMES wayland-scanner REQUIRED)
666 execute_process(
667 COMMAND ${WAYLAND_SCANNER} --version
668 RESULT_VARIABLE WAYLAND_SCANNER_VERSION_RC
669 ERROR_VARIABLE WAYLAND_SCANNER_VERSION
670 ERROR_STRIP_TRAILING_WHITESPACE
671 )
672 if(NOT WAYLAND_SCANNER_VERSION_RC EQUAL 0)
673 message(FATAL "Failed to get wayland-scanner version")
674 set(WAYLAND_FOUND FALSE)
675 endif()
676 string(REPLACE "wayland-scanner " "" WAYLAND_SCANNER_VERSION ${WAYLAND_SCANNER_VERSION})
677
678 string(COMPARE LESS ${WAYLAND_SCANNER_VERSION} "1.15.0" WAYLAND_SCANNER_PRE_1_15)
679 if(WAYLAND_SCANNER_PRE_1_15)
680 set(WAYLAND_SCANNER_CODE_MODE "code")
681 else()
682 set(WAYLAND_SCANNER_CODE_MODE "private-code")
683 endif()
684 endif()
685
686 if(WAYLAND_FOUND)
687 target_link_directories(sdl-build-options INTERFACE "${PKG_WAYLAND_LIBRARY_DIRS}")
688 target_include_directories(sdl-build-options SYSTEM INTERFACE "${PKG_WAYLAND_INCLUDE_DIRS}")
689
690 set(HAVE_WAYLAND TRUE)
691 set(HAVE_SDL_VIDEO TRUE)
692
693 file(GLOB WAYLAND_SOURCES ${SDL2_SOURCE_DIR}/src/video/wayland/*.c)
694 list(APPEND SOURCE_FILES ${WAYLAND_SOURCES})
695
696 # We have to generate some protocol interface code for some unstable Wayland features.
697 file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/wayland-generated-protocols")
698 target_include_directories(sdl-build-options SYSTEM INTERFACE "${CMAKE_CURRENT_BINARY_DIR}/wayland-generated-protocols")
699
700 file(GLOB WAYLAND_PROTOCOLS_XML RELATIVE "${SDL2_SOURCE_DIR}/wayland-protocols/" "${SDL2_SOURCE_DIR}/wayland-protocols/*.xml")
701 foreach(_XML ${WAYLAND_PROTOCOLS_XML})
702 string(REGEX REPLACE "\\.xml$" "" _PROTL "${_XML}")
703 WaylandProtocolGen("${WAYLAND_SCANNER}" "${WAYLAND_SCANNER_CODE_MODE}" "${SDL2_SOURCE_DIR}/wayland-protocols/${_XML}" "${_PROTL}")
704 endforeach()
705
706 if(SDL_WAYLAND_QT_TOUCH)
707 set(HAVE_WAYLAND_QT_TOUCH TRUE)
708 set(SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH 1)
709 endif()
710
711 if(SDL_WAYLAND_SHARED AND NOT HAVE_SDL_LOADSO)
712 message_warn("You must have SDL_LoadObject() support for dynamic Wayland loading")
713 endif()
714 FindLibraryAndSONAME(wayland-client LIBDIRS ${PKG_WAYLAND_LIBRARY_DIRS})
715 FindLibraryAndSONAME(wayland-egl LIBDIRS ${PKG_WAYLAND_LIBRARY_DIRS})
716 FindLibraryAndSONAME(wayland-cursor LIBDIRS ${PKG_WAYLAND_LIBRARY_DIRS})
717 FindLibraryAndSONAME(xkbcommon LIBDIRS ${PKG_WAYLAND_LIBRARY_DIRS})
718 if(SDL_WAYLAND_SHARED AND WAYLAND_CLIENT_LIB AND WAYLAND_EGL_LIB AND WAYLAND_CURSOR_LIB AND XKBCOMMON_LIB AND HAVE_SDL_LOADSO)
719 set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC "\"${WAYLAND_CLIENT_LIB_SONAME}\"")
720 set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_EGL "\"${WAYLAND_EGL_LIB_SONAME}\"")
721 set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_CURSOR "\"${WAYLAND_CURSOR_LIB_SONAME}\"")
722 set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_XKBCOMMON "\"${XKBCOMMON_LIB_SONAME}\"")
723 set(HAVE_WAYLAND_SHARED TRUE)
724 else()
725 list(APPEND EXTRA_LIBS ${PKG_WAYLAND_LIBRARIES})
726 endif()
727
728 if(SDL_WAYLAND_LIBDECOR)
729 pkg_check_modules(PKG_LIBDECOR libdecor-0)
730 if(PKG_LIBDECOR_FOUND)
731 set(HAVE_WAYLAND_LIBDECOR TRUE)
732 set(HAVE_LIBDECOR_H 1)
733 target_link_directories(sdl-build-options INTERFACE "${PKG_LIBDECOR_LIBRARY_DIRS}")
734 target_include_directories(sdl-build-options SYSTEM INTERFACE "${PKG_LIBDECOR_INCLUDE_DIRS}")
735 if(SDL_WAYLAND_LIBDECOR_SHARED AND NOT HAVE_SDL_LOADSO)
736 message_warn("You must have SDL_LoadObject() support for dynamic libdecor loading")
737 endif()
738 FindLibraryAndSONAME(decor-0 LIBDIRS ${PKG_LIBDECOR_LIBRARY_DIRS})
739 if(SDL_WAYLAND_LIBDECOR_SHARED AND DECOR_0_LIB AND HAVE_SDL_LOADSO)
740 set(HAVE_WAYLAND_LIBDECOR_SHARED TRUE)
741 set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_LIBDECOR "\"${DECOR_0_LIB_SONAME}\"")
742 else()
743 list(APPEND EXTRA_LIBS ${PKG_LIBDECOR_LIBRARIES})
744 endif()
745
746 cmake_push_check_state()
747 list(APPEND CMAKE_REQUIRED_FLAGS ${PKG_LIBDECOR_CFLAGS})
748 list(APPEND CMAKE_REQUIRED_INCLUDES ${PKG_LIBDECOR_INCLUDE_DIRS})
749 list(APPEND CMAKE_REQUIRED_LIBRARIES ${PKG_LIBDECOR_LINK_LIBRARIES})
750 check_symbol_exists(libdecor_frame_get_max_content_size "libdecor.h" HAVE_LIBDECOR_FRAME_GET_MAX_CONTENT_SIZE)
751 check_symbol_exists(libdecor_frame_get_min_content_size "libdecor.h" HAVE_LIBDECOR_FRAME_GET_MIN_CONTENT_SIZE)
752 if(HAVE_LIBDECOR_FRAME_GET_MAX_CONTENT_SIZE AND HAVE_LIBDECOR_FRAME_GET_MIN_CONTENT_SIZE)
753 set(SDL_HAVE_LIBDECOR_GET_MIN_MAX 1)
754 endif()
755 cmake_pop_check_state()
756 endif()
757 endif()
758
759 set(SDL_VIDEO_DRIVER_WAYLAND 1)
760 endif()
761 endif()
762endmacro()
763
764# Requires:
765# - n/a
766#
767macro(CheckCOCOA)
768 if(SDL_COCOA)
769 if(APPLE) # Apple always has Cocoa.
770 set(HAVE_COCOA TRUE)
771 endif()
772 if(HAVE_COCOA)
773 file(GLOB COCOA_SOURCES ${SDL2_SOURCE_DIR}/src/video/cocoa/*.m)
774 list(APPEND SOURCE_FILES ${COCOA_SOURCES})
775 set(SDL_VIDEO_DRIVER_COCOA 1)
776 set(HAVE_SDL_VIDEO TRUE)
777 endif()
778 endif()
779endmacro()
780
781# Requires:
782# - PkgCheckModules
783# Optional:
784# - DIRECTFB_SHARED opt
785# - HAVE_SDL_LOADSO opt
786macro(CheckDirectFB)
787 if(SDL_DIRECTFB)
788 pkg_check_modules(PKG_DIRECTFB directfb>=1.0.0)
789 if(PKG_DIRECTFB_FOUND)
790 set(HAVE_DIRECTFB TRUE)
791 file(GLOB DIRECTFB_SOURCES ${SDL2_SOURCE_DIR}/src/video/directfb/*.c)
792 list(APPEND SOURCE_FILES ${DIRECTFB_SOURCES})
793 set(SDL_VIDEO_DRIVER_DIRECTFB 1)
794 set(SDL_VIDEO_RENDER_DIRECTFB 1)
795 list(APPEND EXTRA_CFLAGS ${PKG_DIRECTFB_CFLAGS})
796 list(APPEND SDL_CFLAGS ${PKG_DIRECTFB_CFLAGS})
797 if(SDL_DIRECTFB_SHARED AND NOT HAVE_SDL_LOADSO)
798 message_warn("You must have SDL_LoadObject() support for dynamic DirectFB loading")
799 endif()
800 FindLibraryAndSONAME("directfb" LIBDIRS ${PKG_DIRECTFB_LIBRARY_DIRS})
801 if(SDL_DIRECTFB_SHARED AND DIRECTFB_LIB AND HAVE_SDL_LOADSO)
802 set(SDL_VIDEO_DRIVER_DIRECTFB_DYNAMIC "\"${DIRECTFB_LIB_SONAME}\"")
803 set(HAVE_DIRECTFB_SHARED TRUE)
804 else()
805 list(APPEND EXTRA_LDFLAGS ${PKG_DIRECTFB_LDFLAGS})
806 endif()
807 set(HAVE_SDL_VIDEO TRUE)
808 endif()
809 endif()
810endmacro()
811
812# Requires:
813# - n/a
814macro(CheckVivante)
815 if(SDL_VIVANTE)
816 check_c_source_compiles("
817 #include <gc_vdk.h>
818 int main(int argc, char** argv) { return 0; }" HAVE_VIVANTE_VDK)
819 check_c_source_compiles("
820 #define LINUX
821 #define EGL_API_FB
822 #include <EGL/eglvivante.h>
823 int main(int argc, char** argv) { return 0; }" HAVE_VIVANTE_EGL_FB)
824 if(HAVE_VIVANTE_VDK OR HAVE_VIVANTE_EGL_FB)
825 set(HAVE_VIVANTE TRUE)
826 set(HAVE_SDL_VIDEO TRUE)
827
828 file(GLOB VIVANTE_SOURCES ${SDL2_SOURCE_DIR}/src/video/vivante/*.c)
829 list(APPEND SOURCE_FILES ${VIVANTE_SOURCES})
830 set(SDL_VIDEO_DRIVER_VIVANTE 1)
831 if(HAVE_VIVANTE_VDK)
832 set(SDL_VIDEO_DRIVER_VIVANTE_VDK 1)
833 find_library(VIVANTE_LIBRARY REQUIRED NAMES VIVANTE vivante drm_vivante)
834 find_library(VIVANTE_VDK_LIBRARY VDK REQUIRED)
835 list(APPEND EXTRA_LIBS ${VIVANTE_LIBRARY} ${VIVANTE_VDK_LIBRARY})
836 else()
837 list(APPEND SDL_CFLAGS -DLINUX -DEGL_API_FB)
838 list(APPEND EXTRA_LIBS EGL)
839 endif(HAVE_VIVANTE_VDK)
840 endif()
841 endif()
842endmacro()
843
844# Requires:
845# - nada
846macro(CheckGLX)
847 if(SDL_OPENGL)
848 check_c_source_compiles("
849 #include <GL/glx.h>
850 int main(int argc, char** argv) { return 0; }" HAVE_OPENGL_GLX)
851 if(HAVE_OPENGL_GLX)
852 set(SDL_VIDEO_OPENGL_GLX 1)
853 endif()
854 endif()
855endmacro()
856
857# Requires:
858# - PkgCheckModules
859macro(CheckEGL)
860 if (SDL_OPENGL OR SDL_OPENGLES)
861 pkg_check_modules(EGL egl)
862 set(CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS} ${EGL_CFLAGS}")
863 check_c_source_compiles("
864 #define EGL_API_FB
865 #define MESA_EGL_NO_X11_HEADERS
866 #define EGL_NO_X11
867 #include <EGL/egl.h>
868 #include <EGL/eglext.h>
869 int main (int argc, char** argv) { return 0; }" HAVE_OPENGL_EGL)
870 if(HAVE_OPENGL_EGL)
871 set(SDL_VIDEO_OPENGL_EGL 1)
872 endif()
873 endif()
874endmacro()
875
876# Requires:
877# - nada
878macro(CheckOpenGL)
879 if(SDL_OPENGL)
880 check_c_source_compiles("
881 #include <GL/gl.h>
882 #include <GL/glext.h>
883 int main(int argc, char** argv) { return 0; }" HAVE_OPENGL)
884 if(HAVE_OPENGL)
885 set(SDL_VIDEO_OPENGL 1)
886 set(SDL_VIDEO_RENDER_OGL 1)
887 endif()
888 endif()
889endmacro()
890
891# Requires:
892# - nada
893macro(CheckOpenGLES)
894 if(SDL_OPENGLES)
895 check_c_source_compiles("
896 #include <GLES/gl.h>
897 #include <GLES/glext.h>
898 int main (int argc, char** argv) { return 0; }" HAVE_OPENGLES_V1)
899 if(HAVE_OPENGLES_V1)
900 set(HAVE_OPENGLES TRUE)
901 set(SDL_VIDEO_OPENGL_ES 1)
902 set(SDL_VIDEO_RENDER_OGL_ES 1)
903 endif()
904 check_c_source_compiles("
905 #include <GLES2/gl2.h>
906 #include <GLES2/gl2ext.h>
907 int main (int argc, char** argv) { return 0; }" HAVE_OPENGLES_V2)
908 if(HAVE_OPENGLES_V2)
909 set(HAVE_OPENGLES TRUE)
910 set(SDL_VIDEO_OPENGL_ES2 1)
911 set(SDL_VIDEO_RENDER_OGL_ES2 1)
912 endif()
913 endif()
914endmacro()
915
916# Requires:
917# - EGL
918macro(CheckQNXScreen)
919 if(QNX AND HAVE_OPENGL_EGL)
920 check_c_source_compiles("
921 #include <screen/screen.h>
922 int main (int argc, char** argv) { return 0; }" HAVE_QNX_SCREEN)
923 if(HAVE_QNX_SCREEN)
924 set(SDL_VIDEO_DRIVER_QNX 1)
925 file(GLOB QNX_VIDEO_SOURCES ${SDL2_SOURCE_DIR}/src/video/qnx/*.c)
926 list(APPEND SOURCE_FILES ${QNX_VIDEO_SOURCES})
927 list(APPEND EXTRA_LIBS screen EGL)
928 endif()
929 endif()
930endmacro()
931
932# Requires:
933# - nada
934# Optional:
935# - THREADS opt
936# Sets:
937# PTHREAD_CFLAGS
938# PTHREAD_LIBS
939macro(CheckPTHREAD)
940 if(SDL_THREADS AND SDL_PTHREADS)
941 if(ANDROID)
942 # the android libc provides built-in support for pthreads, so no
943 # additional linking or compile flags are necessary
944 elseif(LINUX)
945 set(PTHREAD_CFLAGS "-D_REENTRANT")
946 set(PTHREAD_LDFLAGS "-pthread")
947 elseif(BSDI)
948 set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
949 set(PTHREAD_LDFLAGS "")
950 elseif(DARWIN)
951 set(PTHREAD_CFLAGS "-D_THREAD_SAFE")
952 # causes Carbon.p complaints?
953 # set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
954 set(PTHREAD_LDFLAGS "")
955 elseif(FREEBSD)
956 set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
957 set(PTHREAD_LDFLAGS "-pthread")
958 elseif(NETBSD)
959 set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
960 set(PTHREAD_LDFLAGS "-lpthread")
961 elseif(OPENBSD)
962 set(PTHREAD_CFLAGS "-D_REENTRANT")
963 set(PTHREAD_LDFLAGS "-lpthread")
964 elseif(SOLARIS)
965 set(PTHREAD_CFLAGS "-D_REENTRANT")
966 set(PTHREAD_LDFLAGS "-pthread -lposix4")
967 elseif(SYSV5)
968 set(PTHREAD_CFLAGS "-D_REENTRANT -Kthread")
969 set(PTHREAD_LDFLAGS "")
970 elseif(AIX)
971 set(PTHREAD_CFLAGS "-D_REENTRANT -mthreads")
972 set(PTHREAD_LDFLAGS "-pthread")
973 elseif(HPUX)
974 set(PTHREAD_CFLAGS "-D_REENTRANT")
975 set(PTHREAD_LDFLAGS "-L/usr/lib -pthread")
976 elseif(HAIKU)
977 set(PTHREAD_CFLAGS "-D_REENTRANT")
978 set(PTHREAD_LDFLAGS "")
979 elseif(EMSCRIPTEN)
980 set(PTHREAD_CFLAGS "-D_REENTRANT -pthread")
981 set(PTHREAD_LDFLAGS "-pthread")
982 elseif(QNX)
983 # pthread support is baked in
984 else()
985 set(PTHREAD_CFLAGS "-D_REENTRANT")
986 set(PTHREAD_LDFLAGS "-lpthread")
987 endif()
988
989 # Run some tests
990 set(ORIG_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
991 set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${PTHREAD_CFLAGS} ${PTHREAD_LDFLAGS}")
992 check_c_source_compiles("
993 #include <pthread.h>
994 int main(int argc, char** argv) {
995 pthread_attr_t type;
996 pthread_attr_init(&type);
997 return 0;
998 }" HAVE_PTHREADS)
999 if(HAVE_PTHREADS)
1000 set(SDL_THREAD_PTHREAD 1)
1001 list(APPEND EXTRA_CFLAGS ${PTHREAD_CFLAGS})
1002 list(APPEND EXTRA_LDFLAGS ${PTHREAD_LDFLAGS})
1003 list(APPEND SDL_CFLAGS ${PTHREAD_CFLAGS})
1004
1005 check_c_source_compiles("
1006 #include <pthread.h>
1007 int main(int argc, char **argv) {
1008 pthread_mutexattr_t attr;
1009 pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
1010 return 0;
1011 }" HAVE_RECURSIVE_MUTEXES)
1012 if(HAVE_RECURSIVE_MUTEXES)
1013 set(SDL_THREAD_PTHREAD_RECURSIVE_MUTEX 1)
1014 else()
1015 check_c_source_compiles("
1016 #include <pthread.h>
1017 int main(int argc, char **argv) {
1018 pthread_mutexattr_t attr;
1019 pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE_NP);
1020 return 0;
1021 }" HAVE_RECURSIVE_MUTEXES_NP)
1022 if(HAVE_RECURSIVE_MUTEXES_NP)
1023 set(SDL_THREAD_PTHREAD_RECURSIVE_MUTEX_NP 1)
1024 endif()
1025 endif()
1026
1027 if(SDL_PTHREADS_SEM)
1028 check_c_source_compiles("#include <pthread.h>
1029 #include <semaphore.h>
1030 int main(int argc, char **argv) { return 0; }" HAVE_PTHREADS_SEM)
1031 if(HAVE_PTHREADS_SEM)
1032 check_c_source_compiles("
1033 #include <pthread.h>
1034 #include <semaphore.h>
1035 int main(int argc, char **argv) {
1036 sem_timedwait(NULL, NULL);
1037 return 0;
1038 }" HAVE_SEM_TIMEDWAIT)
1039 endif()
1040 endif()
1041
1042 check_include_files("pthread.h" HAVE_PTHREAD_H)
1043 check_include_files("pthread_np.h" HAVE_PTHREAD_NP_H)
1044 if (HAVE_PTHREAD_H)
1045 check_c_source_compiles("
1046 #include <pthread.h>
1047 int main(int argc, char **argv) {
1048 #ifdef __APPLE__
1049 pthread_setname_np(\"\");
1050 #else
1051 pthread_setname_np(pthread_self(),\"\");
1052 #endif
1053 return 0;
1054 }" HAVE_PTHREAD_SETNAME_NP)
1055 if (HAVE_PTHREAD_NP_H)
1056 check_symbol_exists(pthread_set_name_np "pthread.h;pthread_np.h" HAVE_PTHREAD_SET_NAME_NP)
1057 endif()
1058 endif()
1059
1060 set(SOURCE_FILES ${SOURCE_FILES}
1061 ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_systhread.c
1062 ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_sysmutex.c # Can be faked, if necessary
1063 ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_syscond.c # Can be faked, if necessary
1064 ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_systls.c
1065 )
1066 if(HAVE_PTHREADS_SEM)
1067 set(SOURCE_FILES ${SOURCE_FILES}
1068 ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_syssem.c)
1069 else()
1070 set(SOURCE_FILES ${SOURCE_FILES}
1071 ${SDL2_SOURCE_DIR}/src/thread/generic/SDL_syssem.c)
1072 endif()
1073 set(HAVE_SDL_THREADS TRUE)
1074 endif()
1075 set(CMAKE_REQUIRED_FLAGS "${ORIG_CMAKE_REQUIRED_FLAGS}")
1076 endif()
1077endmacro()
1078
1079# Requires
1080# - nada
1081# Optional:
1082# Sets:
1083# USB_LIBS
1084# USB_CFLAGS
1085macro(CheckUSBHID)
1086 check_library_exists(usbhid hid_init "" LIBUSBHID)
1087 if(LIBUSBHID)
1088 check_include_file(usbhid.h HAVE_USBHID_H)
1089 if(HAVE_USBHID_H)
1090 set(USB_CFLAGS "-DHAVE_USBHID_H")
1091 endif()
1092
1093 check_include_file(libusbhid.h HAVE_LIBUSBHID_H)
1094 if(HAVE_LIBUSBHID_H)
1095 set(USB_CFLAGS "${USB_CFLAGS} -DHAVE_LIBUSBHID_H")
1096 endif()
1097 set(USB_LIBS ${USB_LIBS} usbhid)
1098 else()
1099 check_include_file(usb.h HAVE_USB_H)
1100 if(HAVE_USB_H)
1101 set(USB_CFLAGS "-DHAVE_USB_H")
1102 endif()
1103 check_include_file(libusb.h HAVE_LIBUSB_H)
1104 if(HAVE_LIBUSB_H)
1105 set(USB_CFLAGS "${USB_CFLAGS} -DHAVE_LIBUSB_H")
1106 endif()
1107 check_library_exists(usb hid_init "" LIBUSB)
1108 if(LIBUSB)
1109 set(USB_LIBS ${USB_LIBS} usb)
1110 endif()
1111 endif()
1112
1113 set(ORIG_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
1114 set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${USB_CFLAGS}")
1115 set(CMAKE_REQUIRED_LIBRARIES "${USB_LIBS}")
1116 check_c_source_compiles("
1117 #include <sys/types.h>
1118 #if defined(HAVE_USB_H)
1119 #include <usb.h>
1120 #endif
1121 #ifdef __DragonFly__
1122 # include <bus/u4b/usb.h>
1123 # include <bus/u4b/usbhid.h>
1124 #else
1125 # include <dev/usb/usb.h>
1126 # include <dev/usb/usbhid.h>
1127 #endif
1128 #if defined(HAVE_USBHID_H)
1129 #include <usbhid.h>
1130 #elif defined(HAVE_LIBUSB_H)
1131 #include <libusb.h>
1132 #elif defined(HAVE_LIBUSBHID_H)
1133 #include <libusbhid.h>
1134 #endif
1135 int main(int argc, char **argv) {
1136 struct report_desc *repdesc;
1137 struct usb_ctl_report *repbuf;
1138 hid_kind_t hidkind;
1139 return 0;
1140 }" HAVE_USBHID)
1141 if(HAVE_USBHID)
1142 check_c_source_compiles("
1143 #include <sys/types.h>
1144 #if defined(HAVE_USB_H)
1145 #include <usb.h>
1146 #endif
1147 #ifdef __DragonFly__
1148 # include <bus/u4b/usb.h>
1149 # include <bus/u4b/usbhid.h>
1150 #else
1151 # include <dev/usb/usb.h>
1152 # include <dev/usb/usbhid.h>
1153 #endif
1154 #if defined(HAVE_USBHID_H)
1155 #include <usbhid.h>
1156 #elif defined(HAVE_LIBUSB_H)
1157 #include <libusb.h>
1158 #elif defined(HAVE_LIBUSBHID_H)
1159 #include <libusbhid.h>
1160 #endif
1161 int main(int argc, char** argv) {
1162 struct usb_ctl_report buf;
1163 if (buf.ucr_data) { }
1164 return 0;
1165 }" HAVE_USBHID_UCR_DATA)
1166 if(HAVE_USBHID_UCR_DATA)
1167 set(USB_CFLAGS "${USB_CFLAGS} -DUSBHID_UCR_DATA")
1168 endif()
1169
1170 check_c_source_compiles("
1171 #include <sys/types.h>
1172 #if defined(HAVE_USB_H)
1173 #include <usb.h>
1174 #endif
1175 #ifdef __DragonFly__
1176 #include <bus/u4b/usb.h>
1177 #include <bus/u4b/usbhid.h>
1178 #else
1179 #include <dev/usb/usb.h>
1180 #include <dev/usb/usbhid.h>
1181 #endif
1182 #if defined(HAVE_USBHID_H)
1183 #include <usbhid.h>
1184 #elif defined(HAVE_LIBUSB_H)
1185 #include <libusb.h>
1186 #elif defined(HAVE_LIBUSBHID_H)
1187 #include <libusbhid.h>
1188 #endif
1189 int main(int argc, char **argv) {
1190 report_desc_t d;
1191 hid_start_parse(d, 1, 1);
1192 return 0;
1193 }" HAVE_USBHID_NEW)
1194 if(HAVE_USBHID_NEW)
1195 set(USB_CFLAGS "${USB_CFLAGS} -DUSBHID_NEW")
1196 endif()
1197
1198 check_c_source_compiles("
1199 #include <machine/joystick.h>
1200 int main(int argc, char** argv) {
1201 struct joystick t;
1202 return 0;
1203 }" HAVE_MACHINE_JOYSTICK)
1204 if(HAVE_MACHINE_JOYSTICK)
1205 set(SDL_HAVE_MACHINE_JOYSTICK_H 1)
1206 endif()
1207 set(SDL_JOYSTICK_USBHID 1)
1208 file(GLOB BSD_JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/bsd/*.c)
1209 list(APPEND SOURCE_FILES ${BSD_JOYSTICK_SOURCES})
1210 list(APPEND EXTRA_CFLAGS ${USB_CFLAGS})
1211 list(APPEND EXTRA_LIBS ${USB_LIBS})
1212 set(HAVE_SDL_JOYSTICK TRUE)
1213
1214 set(CMAKE_REQUIRED_LIBRARIES)
1215 set(CMAKE_REQUIRED_FLAGS "${ORIG_CMAKE_REQUIRED_FLAGS}")
1216 endif()
1217endmacro()
1218
1219# Check for HIDAPI support
1220macro(CheckHIDAPI)
1221 set(HAVE_HIDAPI TRUE)
1222 if(SDL_HIDAPI)
1223 if(SDL_HIDAPI_LIBUSB)
1224 set(HAVE_LIBUSB FALSE)
1225 pkg_check_modules(PKG_LIBUSB libusb-1.0)
1226 if(PKG_LIBUSB_FOUND)
1227 check_include_file(libusb.h HAVE_LIBUSB_H ${PKG_LIBUSB_CFLAGS})
1228 if(HAVE_LIBUSB_H)
1229 set(HAVE_LIBUSB TRUE)
1230 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${PKG_LIBUSB_CFLAGS}")
1231 if(HIDAPI_ONLY_LIBUSB)
1232 list(APPEND EXTRA_LIBS ${PKG_LIBUSB_LIBRARIES})
1233 elseif(OS2)
1234 set(SDL_LIBUSB_DYNAMIC "\"usb100.dll\"")
1235 else()
1236 # libusb is loaded dynamically, so don't add it to EXTRA_LIBS
1237 FindLibraryAndSONAME("usb-1.0" LIBDIRS ${PKG_LIBUSB_LIBRARY_DIRS})
1238 if(USB_1.0_LIB)
1239 set(SDL_LIBUSB_DYNAMIC "\"${USB_1.0_LIB_SONAME}\"")
1240 endif()
1241 endif()
1242 endif()
1243 endif()
1244 if(HIDAPI_ONLY_LIBUSB AND NOT HAVE_LIBUSB)
1245 set(HAVE_HIDAPI FALSE)
1246 endif()
1247 set(HAVE_HIDAPI_LIBUSB ${HAVE_LIBUSB})
1248 endif()
1249
1250 if(HAVE_HIDAPI)
1251 if(ANDROID)
1252 list(APPEND SOURCE_FILES ${SDL2_SOURCE_DIR}/src/hidapi/android/hid.cpp)
1253 endif()
1254 if(IOS OR TVOS)
1255 list(APPEND SOURCE_FILES ${SDL2_SOURCE_DIR}/src/hidapi/ios/hid.m)
1256 set(SDL_FRAMEWORK_COREBLUETOOTH 1)
1257 endif()
1258 set(HAVE_SDL_HIDAPI TRUE)
1259
1260 if(SDL_JOYSTICK AND SDL_HIDAPI_JOYSTICK)
1261 set(SDL_JOYSTICK_HIDAPI 1)
1262 set(HAVE_SDL_JOYSTICK TRUE)
1263 set(HAVE_HIDAPI_JOYSTICK TRUE)
1264 file(GLOB HIDAPI_JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/hidapi/*.c)
1265 list(APPEND SOURCE_FILES ${HIDAPI_JOYSTICK_SOURCES})
1266 endif()
1267 else()
1268 set(SDL_HIDAPI_DISABLED 1)
1269 endif()
1270 else()
1271 set(SDL_HIDAPI_DISABLED 1)
1272 endif()
1273endmacro()
1274
1275# Requires:
1276# - n/a
1277macro(CheckRPI)
1278 if(SDL_RPI)
1279 pkg_check_modules(VIDEO_RPI bcm_host brcmegl)
1280 if (NOT VIDEO_RPI_FOUND)
1281 set(VIDEO_RPI_INCLUDE_DIRS "/opt/vc/include" "/opt/vc/include/interface/vcos/pthreads" "/opt/vc/include/interface/vmcs_host/linux/" )
1282 set(VIDEO_RPI_LIBRARY_DIRS "/opt/vc/lib" )
1283 set(VIDEO_RPI_LIBRARIES bcm_host )
1284 set(VIDEO_RPI_LDFLAGS "-Wl,-rpath,/opt/vc/lib")
1285 endif()
1286 listtostr(VIDEO_RPI_INCLUDE_DIRS VIDEO_RPI_INCLUDE_FLAGS "-I")
1287 listtostr(VIDEO_RPI_LIBRARY_DIRS VIDEO_RPI_LIBRARY_FLAGS "-L")
1288
1289 set(ORIG_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
1290 set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${VIDEO_RPI_INCLUDE_FLAGS} ${VIDEO_RPI_LIBRARY_FLAGS}")
1291 set(CMAKE_REQUIRED_LIBRARIES "${VIDEO_RPI_LIBRARIES}")
1292 check_c_source_compiles("
1293 #include <bcm_host.h>
1294 #include <EGL/eglplatform.h>
1295 int main(int argc, char **argv) {
1296 EGL_DISPMANX_WINDOW_T window;
1297 bcm_host_init();
1298 }" HAVE_RPI)
1299 set(CMAKE_REQUIRED_FLAGS "${ORIG_CMAKE_REQUIRED_FLAGS}")
1300 set(CMAKE_REQUIRED_LIBRARIES)
1301
1302 if(SDL_VIDEO AND HAVE_RPI)
1303 set(HAVE_SDL_VIDEO TRUE)
1304 set(SDL_VIDEO_DRIVER_RPI 1)
1305 file(GLOB VIDEO_RPI_SOURCES ${SDL2_SOURCE_DIR}/src/video/raspberry/*.c)
1306 list(APPEND SOURCE_FILES ${VIDEO_RPI_SOURCES})
1307 list(APPEND EXTRA_LIBS ${VIDEO_RPI_LIBRARIES})
1308 # !!! FIXME: shouldn't be using CMAKE_C_FLAGS, right?
1309 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${VIDEO_RPI_INCLUDE_FLAGS} ${VIDEO_RPI_LIBRARY_FLAGS}")
1310 list(APPEND EXTRA_LDFLAGS ${VIDEO_RPI_LDFLAGS})
1311 endif()
1312 endif()
1313endmacro()
1314
1315# Requires:
1316# - EGL
1317# - PkgCheckModules
1318# Optional:
1319# - SDL_KMSDRM_SHARED opt
1320# - HAVE_SDL_LOADSO opt
1321macro(CheckKMSDRM)
1322 if(SDL_KMSDRM)
1323 pkg_check_modules(PKG_KMSDRM libdrm gbm egl)
1324 if(PKG_KMSDRM_FOUND AND HAVE_OPENGL_EGL)
1325 target_link_directories(sdl-build-options INTERFACE ${PKG_KMSDRM_LIBRARY_DIRS})
1326 target_include_directories(sdl-build-options SYSTEM INTERFACE "${PKG_KMSDRM_INCLUDE_DIRS}")
1327 set(HAVE_KMSDRM TRUE)
1328 set(HAVE_SDL_VIDEO TRUE)
1329
1330 file(GLOB KMSDRM_SOURCES ${SDL2_SOURCE_DIR}/src/video/kmsdrm/*.c)
1331 list(APPEND SOURCE_FILES ${KMSDRM_SOURCES})
1332
1333 list(APPEND EXTRA_CFLAGS ${PKG_KMSDRM_CFLAGS})
1334
1335 set(SDL_VIDEO_DRIVER_KMSDRM 1)
1336
1337 if(SDL_KMSDRM_SHARED AND NOT HAVE_SDL_LOADSO)
1338 message_warn("You must have SDL_LoadObject() support for dynamic KMS/DRM loading")
1339 endif()
1340 if(SDL_KMSDRM_SHARED AND HAVE_SDL_LOADSO)
1341 FindLibraryAndSONAME(drm LIBDIRS ${PKG_KMSDRM_LIBRARY_DIRS})
1342 FindLibraryAndSONAME(gbm LIBDIRS ${PKG_KMSDRM_LIBRARY_DIRS})
1343 set(SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC "\"${DRM_LIB_SONAME}\"")
1344 set(SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC_GBM "\"${GBM_LIB_SONAME}\"")
1345 set(HAVE_KMSDRM_SHARED TRUE)
1346 else()
1347 list(APPEND EXTRA_LIBS ${PKG_KMSDRM_LIBRARIES})
1348 endif()
1349 endif()
1350 endif()
1351endmacro()
1352
1353macro(CheckLibUDev)
1354 if(SDL_LIBUDEV)
1355 check_include_file("libudev.h" have_libudev_header)
1356 if(have_libudev_header)
1357 set(HAVE_LIBUDEV_H TRUE)
1358 FindLibraryAndSONAME(udev)
1359 if(UDEV_LIB_SONAME)
1360 set(SDL_UDEV_DYNAMIC "\"${UDEV_LIB_SONAME}\"")
1361 endif()
1362 endif()
1363 endif()
1364endmacro()
1365
1366
1367macro(CheckLibUnwind)
1368 set(found_libunwind FALSE)
1369 set(_libunwind_src "#include <libunwind.h>\nint main() {unw_context_t context; unw_getcontext(&context); return 0;}")
1370
1371 if(NOT found_libunwind)
1372 cmake_push_check_state()
1373 check_c_source_compiles("${_libunwind_src}" LIBC_HAS_WORKING_LIBUNWIND)
1374 cmake_pop_check_state()
1375 if(LIBC_HAS_WORKING_LIBUNWIND)
1376 set(found_libunwind TRUE)
1377 endif()
1378 endif()
1379
1380 if(NOT found_libunwind)
1381 cmake_push_check_state()
1382 list(APPEND CMAKE_REQUIRED_LIBRARIES "unwind")
1383 check_c_source_compiles("${_libunwind_src}" LIBUNWIND_HAS_WORKINGLIBUNWIND)
1384 cmake_pop_check_state()
1385 if(LIBUNWIND_HAS_WORKINGLIBUNWIND)
1386 set(found_libunwind TRUE)
1387 list(APPEND EXTRA_TEST_LIBS unwind)
1388 endif()
1389 endif()
1390
1391 if(NOT found_libunwind)
1392 set(LibUnwind_PKG_CONFIG_SPEC libunwind libunwind-generic)
1393 pkg_check_modules(PC_LIBUNWIND IMPORTED_TARGET ${LibUnwind_PKG_CONFIG_SPEC})
1394 if(PC_LIBUNWIND_FOUND)
1395 cmake_push_check_state()
1396 list(APPEND CMAKE_REQUIRED_LIBRARIES ${PC_LIBUNWIND_LIBRARIES})
1397 list(APPEND CMAKE_REQUIRED_INCLUDES ${PC_LIBUNWIND_INCLUDE_DIRS})
1398 check_c_source_compiles("${_libunwind_src}" PC_LIBUNWIND_HAS_WORKING_LIBUNWIND)
1399 cmake_pop_check_state()
1400 if(PC_LIBUNWIND_HAS_WORKING_LIBUNWIND)
1401 set(found_libunwind TRUE)
1402 list(APPEND EXTRA_TEST_LIBS ${PC_LIBUNWIND_LIBRARIES})
1403 list(APPEND EXTRA_TEST_INCLUDES ${PC_LIBUNWIND_INCLUDE_DIRS})
1404 endif()
1405 endif()
1406 endif()
1407
1408 if(found_libunwind)
1409 set(HAVE_LIBUNWIND_H TRUE)
1410 endif()
1411endmacro()