sdlchecks.cmake 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078
  1. #
  2. # Simple DirectMedia Layer
  3. # Copyright (C) 1997-2016 Sam Lantinga <[email protected]>
  4. #
  5. # This software is provided 'as-is', without any express or implied
  6. # warranty. In no event will the authors be held liable for any damages
  7. # arising from the use of this software.
  8. #
  9. # Permission is granted to anyone to use this software for any purpose,
  10. # including commercial applications, and to alter it and redistribute it
  11. # freely, subject to the following restrictions:
  12. #
  13. # 1. The origin of this software must not be misrepresented; you must not
  14. # claim that you wrote the original software. If you use this software
  15. # in a product, an acknowledgment in the product documentation would be
  16. # appreciated but is not required.
  17. # 2. Altered source versions must be plainly marked as such, and must not be
  18. # misrepresented as being the original software.
  19. # 3. This notice may not be removed or altered from any source distribution.
  20. #
  21. # Modified by Yao Wei Tjong for Urho3D, the modified portion is licensed under below license
  22. #
  23. # Copyright (c) 2008-2017 the Urho3D project.
  24. #
  25. # Permission is hereby granted, free of charge, to any person obtaining a copy
  26. # of this software and associated documentation files (the "Software"), to deal
  27. # in the Software without restriction, including without limitation the rights
  28. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  29. # copies of the Software, and to permit persons to whom the Software is
  30. # furnished to do so, subject to the following conditions:
  31. #
  32. # The above copyright notice and this permission notice shall be included in
  33. # all copies or substantial portions of the Software.
  34. #
  35. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  36. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  37. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  38. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  39. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  40. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  41. # THE SOFTWARE.
  42. #
  43. # Urho3D - replaced FindLibraryAndSONAME macro with get_soname macro
  44. macro (get_soname SONAME LIB)
  45. if (${LIB})
  46. get_filename_component (REALPATH ${${LIB}} REALPATH)
  47. get_filename_component (BASENAME ${REALPATH} NAME)
  48. if (BASENAME MATCHES \\.so) # Extract soname from basename
  49. string (REGEX REPLACE "(\\.so\\.[^.]+).*$" \\1 ${SONAME} "${BASENAME}") # Stringify for string replacement
  50. else ()
  51. set (${SONAME} ${BASENAME}) # If it is not .so (e.g. .dylib) then use whatever the basename is
  52. endif ()
  53. endif ()
  54. endmacro ()
  55. macro(CheckDLOPEN)
  56. # Urho3D - bug fix - to be consistent with the rest of the check macros here, only do the check when the feature is actually wanted
  57. if (SDL_LOADSO)
  58. # Urho3D - bypass the checks for Emscripten as they don't work but assume it is supported (https://github.com/kripken/emscripten/wiki/Linking#dlopen-dynamic-linking)
  59. if (EMSCRIPTEN)
  60. set (HAVE_DLOPEN TRUE)
  61. else ()
  62. # Urho3D - bug fix - use different variables for different checks because of CMake caches the result variable
  63. # ATOMIC BEGIN
  64. # check_function_exists(dlopen DLOPEN_FOUND)
  65. # ATOMIC END
  66. if(NOT DLOPEN_FOUND)
  67. foreach(_LIBNAME dl tdl)
  68. check_library_exists("${_LIBNAME}" "dlopen" "" DLOPEN_LIB_${_LIBNAME}_FOUND)
  69. if(DLOPEN_LIB_${_LIBNAME}_FOUND)
  70. list(APPEND EXTRA_LIBS ${_LIBNAME})
  71. set(_DLLIB ${_LIBNAME})
  72. set(DLOPEN_FOUND TRUE)
  73. break()
  74. endif()
  75. endforeach()
  76. endif()
  77. # ATOMIC BEGIN
  78. # call check_function_exists() only after trying to locate dlopen in the libs. This provides lib
  79. # in _DLLIB which is required for linking when calling check_c_source_compiles().
  80. if(NOT DLOPEN_FOUND)
  81. check_function_exists(dlopen DLOPEN_FOUND)
  82. endif()
  83. # ATOMIC END
  84. if(DLOPEN_FOUND)
  85. if(_DLLIB)
  86. set(CMAKE_REQUIRED_LIBRARIES ${_DLLIB})
  87. endif()
  88. check_c_source_compiles("
  89. #include <dlfcn.h>
  90. int main(int argc, char **argv) {
  91. void *handle = dlopen(\"\", RTLD_NOW);
  92. const char *loaderror = (char *) dlerror();
  93. }" HAVE_DLOPEN)
  94. set(CMAKE_REQUIRED_LIBRARIES)
  95. endif()
  96. endif ()
  97. if(HAVE_DLOPEN)
  98. set(SDL_LOADSO_DLOPEN 1)
  99. set(HAVE_SDL_DLOPEN TRUE)
  100. file(GLOB DLOPEN_SOURCES ${SDL2_SOURCE_DIR}/src/loadso/dlopen/*.c)
  101. set(SOURCE_FILES ${SOURCE_FILES} ${DLOPEN_SOURCES})
  102. set(HAVE_SDL_LOADSO TRUE)
  103. endif()
  104. endif ()
  105. endmacro()
  106. # Requires:
  107. # - n/a
  108. macro(CheckOSS)
  109. if(OSS)
  110. # Urho3D - bug fix - should use different variables for different checks, however, we replace the whole checks with find_package() approach for consistency sake
  111. # ATOMIC BEGIN
  112. find_package (OSS QUIET) # silence warnings
  113. # ATOMIC END
  114. if(OSS_FOUND)
  115. include_directories (SYSTEM ${OSS_INCLUDE_DIRS})
  116. if (OSS_LIBRARIES)
  117. get_filename_component(NAME_WE ${OSS_LIBRARIES} NAME_WE)
  118. string (REGEX REPLACE ^lib "" NAME_WE "${NAME_WE}") # Stringify for string replacement
  119. list(APPEND EXTRA_LIBS ${NAME_WE})
  120. endif ()
  121. set(HAVE_OSS TRUE)
  122. file(GLOB OSS_SOURCES ${SDL2_SOURCE_DIR}/src/audio/dsp/*.c)
  123. if(OSS_USE_WORKAROUND_HEADER)
  124. set(SDL_AUDIO_DRIVER_OSS_SOUNDCARD_H 1)
  125. endif()
  126. set(SDL_AUDIO_DRIVER_OSS 1)
  127. set(SOURCE_FILES ${SOURCE_FILES} ${OSS_SOURCES})
  128. set(HAVE_SDL_AUDIO TRUE)
  129. endif()
  130. endif()
  131. endmacro()
  132. # Requires:
  133. # - n/a
  134. # Optional:
  135. # - ALSA_SHARED opt
  136. # - HAVE_DLOPEN opt
  137. macro(CheckALSA)
  138. if(ALSA)
  139. # Urho3D - bug fix - use the more trusted FindALSA module as it has been tested to work for both native and cross-compiling build
  140. # ATOMIC BEGIN
  141. find_package (ALSA QUIET) # silence warnings
  142. # ATOMIC END
  143. # todo: remove this fix when the minimum CMake version has been raised to higher than 2.8.7
  144. # There is a bug in older version of FindALSA.cmake module where it erroneously include 'alsa' directory component into the variable
  145. # For cross-compiling build to work correctly, this extra directory component must be removed
  146. if (ALSA_INCLUDE_DIRS MATCHES .*/alsa)
  147. get_filename_component (ALSA_INCLUDE_DIRS ${ALSA_INCLUDE_DIRS} PATH)
  148. endif ()
  149. if(ALSA_FOUND)
  150. include_directories (SYSTEM ${ALSA_INCLUDE_DIRS})
  151. set(HAVE_ALSA TRUE)
  152. file(GLOB ALSA_SOURCES ${SDL2_SOURCE_DIR}/src/audio/alsa/*.c)
  153. set(SOURCE_FILES ${SOURCE_FILES} ${ALSA_SOURCES})
  154. set(SDL_AUDIO_DRIVER_ALSA 1)
  155. if(ALSA_SHARED)
  156. if(NOT HAVE_DLOPEN)
  157. message_warn("You must have SDL_LoadObject() support for dynamic ALSA loading")
  158. else()
  159. get_soname (ASOUND_LIB_SONAME ALSA_LIBRARIES)
  160. set(SDL_AUDIO_DRIVER_ALSA_DYNAMIC "\"${ASOUND_LIB_SONAME}\"")
  161. set(HAVE_ALSA_SHARED TRUE)
  162. endif()
  163. else()
  164. list(APPEND EXTRA_LIBS asound)
  165. endif()
  166. set(HAVE_SDL_AUDIO TRUE)
  167. endif()
  168. endif()
  169. endmacro()
  170. # Requires:
  171. # - n/a
  172. # Optional:
  173. # - PULSEAUDIO_SHARED opt
  174. # - HAVE_DLOPEN opt
  175. macro(CheckPulseAudio)
  176. if(PULSEAUDIO)
  177. # Urho3D - bug fix - do not use pkg-config tool for detection as it only works for host environment and not for rooted environment when cross-compiling
  178. # ATOMIC BEGIN
  179. find_package (PulseAudio QUIET) # silence warnings
  180. # ATOMIC END
  181. if(PULSEAUDIO_FOUND)
  182. include_directories (SYSTEM ${PULSEAUDIO_INCLUDE_DIRS})
  183. set(HAVE_PULSEAUDIO TRUE)
  184. file(GLOB PULSEAUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/pulseaudio/*.c)
  185. set(SOURCE_FILES ${SOURCE_FILES} ${PULSEAUDIO_SOURCES})
  186. set(SDL_AUDIO_DRIVER_PULSEAUDIO 1)
  187. # Urho3D - commented out appending EXTRA_CFLAGS for compiling with PulseAudio, there should not be any except "-D_REENTRANT" which is also redundant for our configuration setup as we use '-pthread' compiler flags to do the right things automatically
  188. if(PULSEAUDIO_SHARED)
  189. if(NOT HAVE_DLOPEN)
  190. message_warn("You must have SDL_LoadObject() support for dynamic PulseAudio loading")
  191. else()
  192. get_soname (PULSE_SIMPLE_LIB_SONAME PULSEAUDIO_LIBRARIES)
  193. set(SDL_AUDIO_DRIVER_PULSEAUDIO_DYNAMIC "\"${PULSE_SIMPLE_LIB_SONAME}\"")
  194. set(HAVE_PULSEAUDIO_SHARED TRUE)
  195. endif()
  196. else()
  197. list (APPEND EXTRA_LIBS pulse-simple pulse)
  198. endif()
  199. set(HAVE_SDL_AUDIO TRUE)
  200. endif()
  201. endif()
  202. endmacro()
  203. # Requires:
  204. # - n/a
  205. # Optional:
  206. # - ESD_SHARED opt
  207. # - HAVE_DLOPEN opt
  208. macro(CheckESD)
  209. if(ESD)
  210. # Urho3D - bug fix - do not use pkg-config tool for detection as it only works for host environment and not for rooted environment when cross-compiling
  211. # ATOMIC BEGIN
  212. find_package (Esound QUIET) # silence warnings
  213. # ATOMIC END
  214. if(ESOUND_FOUND)
  215. include_directories (SYSTEM ${ESOUND_INCLUDE_DIRS})
  216. set(HAVE_ESD TRUE)
  217. file(GLOB ESD_SOURCES ${SDL2_SOURCE_DIR}/src/audio/esd/*.c)
  218. set(SOURCE_FILES ${SOURCE_FILES} ${ESD_SOURCES})
  219. set(SDL_AUDIO_DRIVER_ESD 1)
  220. if(ESD_SHARED)
  221. if(NOT HAVE_DLOPEN)
  222. message_warn("You must have SDL_LoadObject() support for dynamic ESD loading")
  223. else()
  224. get_soname (ESD_LIB_SONAME ESOUND_LIBRARIES)
  225. set(SDL_AUDIO_DRIVER_ESD_DYNAMIC "\"${ESD_LIB_SONAME}\"")
  226. set(HAVE_ESD_SHARED TRUE)
  227. endif()
  228. else()
  229. list (APPEND EXTRA_LIBS esd)
  230. endif()
  231. set(HAVE_SDL_AUDIO TRUE)
  232. endif()
  233. endif()
  234. endmacro()
  235. # Requires:
  236. # - n/a
  237. # Optional:
  238. # - ARTS_SHARED opt
  239. # - HAVE_DLOPEN opt
  240. macro(CheckARTS)
  241. if(ARTS)
  242. # Urho3D - bug fix - do not use (host) arts-config tool for detection as it only works for host environment and not for rooted environment when cross-compiling
  243. # ATOMIC BEGIN
  244. find_package (aRts QUIET) # silence warnings
  245. # ATOMIC END
  246. if(ARTS_FOUND)
  247. include_directories (SYSTEM ${ARTS_INCLUDE_DIRS})
  248. file(GLOB ARTS_SOURCES ${SDL2_SOURCE_DIR}/src/audio/arts/*.c)
  249. set(SOURCE_FILES ${SOURCE_FILES} ${ARTS_SOURCES})
  250. set(SDL_AUDIO_DRIVER_ARTS 1)
  251. set(HAVE_ARTS TRUE)
  252. if(ARTS_SHARED)
  253. if(NOT HAVE_DLOPEN)
  254. message_warn("You must have SDL_LoadObject() support for dynamic ARTS loading")
  255. else()
  256. get_soname (ARTSC_LIB_SONAME ARTS_LIBRARIES)
  257. set(SDL_AUDIO_DRIVER_ARTS_DYNAMIC "\"${ARTSC_LIB_SONAME}\"")
  258. set(HAVE_ARTS_SHARED TRUE)
  259. endif()
  260. else()
  261. list (APPEND EXTRA_LIBS artsc)
  262. endif()
  263. set(HAVE_SDL_AUDIO TRUE)
  264. endif()
  265. endif()
  266. endmacro()
  267. # Requires:
  268. # - n/a
  269. # Optional:
  270. # - NAS_SHARED opt
  271. # - HAVE_DLOPEN opt
  272. macro(CheckNAS)
  273. if(NAS)
  274. # Urho3D - bug fix - do not use check_include_file() for detection as it only works for host environment and not for rooted environment when cross-compiling
  275. # ATOMIC BEGIN
  276. find_package (NetworkAudioSystem QUIET) # silence warnings
  277. # ATOMIC END
  278. if(NAS_FOUND)
  279. include_directories (SYSTEM ${NAS_INCLUDE_DIRS})
  280. set(HAVE_NAS TRUE)
  281. file(GLOB NAS_SOURCES ${SDL2_SOURCE_DIR}/src/audio/nas/*.c)
  282. set(SOURCE_FILES ${SOURCE_FILES} ${NAS_SOURCES})
  283. set(SDL_AUDIO_DRIVER_NAS 1)
  284. if(NAS_SHARED)
  285. if(NOT HAVE_DLOPEN)
  286. message_warn("You must have SDL_LoadObject() support for dynamic NAS loading")
  287. else()
  288. get_soname (AUDIO_LIB_SONAME NAS_LIBRARIES)
  289. set(SDL_AUDIO_DRIVER_NAS_DYNAMIC "\"${AUDIO_LIB_SONAME}\"")
  290. set(HAVE_NAS_SHARED TRUE)
  291. endif()
  292. else()
  293. list (APPEND EXTRA_LIBS audio)
  294. endif()
  295. set(HAVE_SDL_AUDIO TRUE)
  296. endif()
  297. endif()
  298. endmacro()
  299. # Requires:
  300. # - n/a
  301. # Optional:
  302. # - SNDIO_SHARED opt
  303. # - HAVE_DLOPEN opt
  304. macro(CheckSNDIO)
  305. if(SNDIO)
  306. # Urho3D - bug fix - do not use check_include_file() for detection as it only works for host environment and not for rooted environment when cross-compiling
  307. # ATOMIC BEGIN
  308. find_package (RoarAudio QUIET) # silence warnings
  309. # ATOMIC END
  310. if(SNDIO_FOUND)
  311. include_directories (SYSTEM ${SNDIO_INCLUDE_DIRS})
  312. set(HAVE_SNDIO TRUE)
  313. file(GLOB SNDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/sndio/*.c)
  314. set(SOURCE_FILES ${SOURCE_FILES} ${SNDIO_SOURCES})
  315. set(SDL_AUDIO_DRIVER_SNDIO 1)
  316. if(SNDIO_SHARED)
  317. if(NOT HAVE_DLOPEN)
  318. message_warn("You must have SDL_LoadObject() support for dynamic sndio loading")
  319. else()
  320. get_soname (SNDIO_LIB_SONAME SNDIO_LIBRARIES)
  321. set(SDL_AUDIO_DRIVER_SNDIO_DYNAMIC "\"${SNDIO_LIB_SONAME}\"")
  322. set(HAVE_SNDIO_SHARED TRUE)
  323. endif()
  324. else()
  325. list(APPEND EXTRA_LIBS sndio)
  326. endif()
  327. set(HAVE_SDL_AUDIO TRUE)
  328. endif()
  329. endif()
  330. endmacro()
  331. # Requires:
  332. # - n/a
  333. # Optional:
  334. # - FUSIONSOUND_SHARED opt
  335. # - HAVE_DLOPEN opt
  336. macro(CheckFusionSound)
  337. if(FUSIONSOUND)
  338. # Urho3D - bug fix - do not use pkg-config tool for detection as it only works for host environment and not for rooted environment when cross-compiling
  339. # ATOMIC BEGIN
  340. find_package (FusionSound 1.0.0 QUIET) # silence warnings
  341. # ATOMIC END
  342. if(FUSIONSOUND_FOUND)
  343. include_directories (SYSTEM ${FUSIONSOUND_INCLUDE_DIRS})
  344. set(HAVE_FUSIONSOUND TRUE)
  345. file(GLOB FUSIONSOUND_SOURCES ${SDL2_SOURCE_DIR}/src/audio/fusionsound/*.c)
  346. set(SOURCE_FILES ${SOURCE_FILES} ${FUSIONSOUND_SOURCES})
  347. set(SDL_AUDIO_DRIVER_FUSIONSOUND 1)
  348. if(FUSIONSOUND_SHARED)
  349. if(NOT HAVE_DLOPEN)
  350. message_warn("You must have SDL_LoadObject() support for dynamic FusionSound loading")
  351. else()
  352. get_soname (FUSIONSOUND_LIB_SONAME FUSIONSOUND_LIBRARIES)
  353. set(SDL_AUDIO_DRIVER_FUSIONSOUND_DYNAMIC "\"${FUSIONSOUND_LIB_SONAME}\"")
  354. set(HAVE_FUSIONSOUND_SHARED TRUE)
  355. endif()
  356. else()
  357. list (APPEND EXTRA_LIBS fusionsound)
  358. endif()
  359. set(HAVE_SDL_AUDIO TRUE)
  360. endif()
  361. endif()
  362. endmacro()
  363. # Requires:
  364. # - n/a
  365. # Optional:
  366. # - X11_SHARED opt
  367. # - HAVE_DLOPEN opt
  368. macro(CheckX11)
  369. if(VIDEO_X11)
  370. # Urho3D - bug fix - in order to make these checks below work on both native and cross-compiling builds we need to add the '-shared' compiler flags to ensure the linker does not attempt to statically link against X11 shared libs which would otherwise fail the test when in cross-compiling mode
  371. set(CMAKE_REQUIRED_FLAGS "-fPIC -shared ${ORIG_CMAKE_REQUIRED_FLAGS}")
  372. foreach (NAME X11 Xext Xcursor Xinerama Xi Xrandr Xrender Xss Xxf86vm)
  373. string (TOUPPER ${NAME} UPCASE_NAME)
  374. string (REGEX REPLACE \\..+$ "" UPCASE_NAME "${UPCASE_NAME}") # Stringify for string replacement
  375. find_library (${UPCASE_NAME}_LIB ${NAME})
  376. get_soname (${UPCASE_NAME}_LIB_SONAME ${UPCASE_NAME}_LIB)
  377. endforeach ()
  378. # Urho3D - commented out setting of X_CFLAGS based on the search result for X11/Xlib.h using the default search path (if it is found then it is in default path anyway so no point to add it into compiler header search path again)
  379. # Urho3D - add check for Xdbe extension
  380. check_include_file(X11/Xcursor/Xcursor.h HAVE_XCURSOR_H)
  381. check_include_file(X11/extensions/Xinerama.h HAVE_XINERAMA_H)
  382. check_include_file(X11/extensions/XInput2.h HAVE_XINPUT_H)
  383. check_include_file(X11/extensions/Xrandr.h HAVE_XRANDR_H)
  384. check_include_file(X11/extensions/Xrender.h HAVE_XRENDER_H)
  385. check_include_file(X11/extensions/shape.h HAVE_XSHAPE_H)
  386. check_include_file(X11/extensions/scrnsaver.h HAVE_XSS_H)
  387. check_include_files("X11/Xlib.h;X11/Xproto.h;X11/extensions/Xdbe.h" HAVE_XDBE_H)
  388. check_include_files("X11/Xlib.h;X11/Xproto.h;X11/extensions/Xext.h" HAVE_XEXT_H)
  389. check_include_files("X11/Xlib.h;X11/extensions/xf86vmode.h" HAVE_XF86VM_H)
  390. if(X11_LIB)
  391. if(NOT HAVE_XEXT_H)
  392. message_error("Missing Xext.h, maybe you need to install the libxext-dev package?")
  393. endif()
  394. if (HAVE_XDBE_H)
  395. set(SDL_VIDEO_DRIVER_X11_XDBE 1)
  396. endif ()
  397. set(HAVE_VIDEO_X11 TRUE)
  398. set(HAVE_SDL_VIDEO TRUE)
  399. file(GLOB X11_SOURCES ${SDL2_SOURCE_DIR}/src/video/x11/*.c)
  400. set(SOURCE_FILES ${SOURCE_FILES} ${X11_SOURCES})
  401. set(SDL_VIDEO_DRIVER_X11 1)
  402. if(APPLE)
  403. set(X11_SHARED OFF)
  404. endif()
  405. check_function_exists("shmat" HAVE_SHMAT)
  406. if(NOT HAVE_SHMAT)
  407. # Urho3D - bug fix - use different variables for different checks because of CMake caches the result variable
  408. check_library_exists(ipc shmat "" HAVE_SHMAT_IN_IPC)
  409. if(HAVE_SHMAT_IN_IPC)
  410. list(APPEND EXTRA_LIBS ipc)
  411. set (HAVE_SHMAT TRUE)
  412. endif()
  413. if(NOT HAVE_SHMAT)
  414. add_definitions(-DNO_SHARED_MEMORY)
  415. set(X_CFLAGS "${X_CFLAGS} -DNO_SHARED_MEMORY")
  416. endif()
  417. endif()
  418. if(X11_SHARED)
  419. if(NOT HAVE_DLOPEN)
  420. message_warn("You must have SDL_LoadObject() support for dynamic X11 loading")
  421. set(HAVE_X11_SHARED FALSE)
  422. else()
  423. set(HAVE_X11_SHARED TRUE)
  424. endif()
  425. if(HAVE_X11_SHARED)
  426. set(SDL_VIDEO_DRIVER_X11_DYNAMIC "\"${X11_LIB_SONAME}\"")
  427. set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT "\"${XEXT_LIB_SONAME}\"")
  428. else()
  429. # Urho3D - bug fix - the EXTRA_LIBS is list of library names (not the fully-qualified path to the library itself)
  430. list (APPEND EXTRA_LIBS X11 Xext)
  431. endif()
  432. endif()
  433. set(SDL_CFLAGS "${SDL_CFLAGS} ${X_CFLAGS}")
  434. set(CMAKE_REQUIRED_LIBRARIES ${X11_LIB} ${X11_LIB})
  435. check_c_source_compiles("
  436. #include <X11/Xlib.h>
  437. #include <X11/Xproto.h>
  438. #include <X11/extensions/Xext.h>
  439. #include <X11/extensions/extutil.h>
  440. extern XExtDisplayInfo* XextAddDisplay(XExtensionInfo* a,Display* b,_Xconst char* c,XExtensionHooks* d,int e,XPointer f);
  441. int main(int argc, char **argv) {}" HAVE_CONST_XEXT_ADDDISPLAY)
  442. if(HAVE_CONST_XEXT_ADDDISPLAY)
  443. set(SDL_VIDEO_DRIVER_X11_CONST_PARAM_XEXTADDDISPLAY 1)
  444. endif()
  445. check_c_source_compiles("
  446. #include <X11/Xlib.h>
  447. int main(int argc, char **argv) {
  448. Display *display;
  449. XEvent event;
  450. XGenericEventCookie *cookie = &event.xcookie;
  451. XNextEvent(display, &event);
  452. XGetEventData(display, cookie);
  453. XFreeEventData(display, cookie); }" HAVE_XGENERICEVENT)
  454. if(HAVE_XGENERICEVENT)
  455. set(SDL_VIDEO_DRIVER_X11_SUPPORTS_GENERIC_EVENTS 1)
  456. endif()
  457. check_function_exists(XkbKeycodeToKeysym SDL_VIDEO_DRIVER_X11_HAS_XKBKEYCODETOKEYSYM)
  458. if(VIDEO_X11_XCURSOR AND HAVE_XCURSOR_H)
  459. set(HAVE_VIDEO_X11_XCURSOR TRUE)
  460. if(HAVE_X11_SHARED AND XCURSOR_LIB)
  461. set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XCURSOR "\"${XCURSOR_LIB_SONAME}\"")
  462. else()
  463. list (APPEND EXTRA_LIBS Xcursor)
  464. endif()
  465. set(SDL_VIDEO_DRIVER_X11_XCURSOR 1)
  466. endif()
  467. if(VIDEO_X11_XINERAMA AND HAVE_XINERAMA_H)
  468. set(HAVE_VIDEO_X11_XINERAMA TRUE)
  469. if(HAVE_X11_SHARED AND XINERAMA_LIB)
  470. set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XINERAMA "\"${XINERAMA_LIB_SONAME}\"")
  471. else()
  472. list (APPEND EXTRA_LIBS Xinerama)
  473. endif()
  474. set(SDL_VIDEO_DRIVER_X11_XINERAMA 1)
  475. endif()
  476. if(VIDEO_X11_XINPUT AND HAVE_XINPUT_H)
  477. set(HAVE_VIDEO_X11_XINPUT TRUE)
  478. if(HAVE_X11_SHARED AND XI_LIB)
  479. set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT2 "\"${XI_LIB_SONAME}\"")
  480. else()
  481. list (APPEND EXTRA_LIBS Xi)
  482. endif()
  483. set(SDL_VIDEO_DRIVER_X11_XINPUT2 1)
  484. # Check for multitouch
  485. check_c_source_compiles("
  486. #include <X11/Xlib.h>
  487. #include <X11/Xproto.h>
  488. #include <X11/extensions/XInput2.h>
  489. int event_type = XI_TouchBegin;
  490. XITouchClassInfo *t;
  491. Status XIAllowTouchEvents(Display *a,int b,unsigned int c,Window d,int f)
  492. {
  493. return (Status)0;
  494. }
  495. int main(int argc, char **argv) {}" HAVE_XINPUT2_MULTITOUCH)
  496. if(HAVE_XINPUT2_MULTITOUCH)
  497. set(SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH 1)
  498. endif()
  499. endif()
  500. if(VIDEO_X11_XRANDR AND HAVE_XRANDR_H)
  501. if(HAVE_X11_SHARED AND XRANDR_LIB)
  502. set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR "\"${XRANDR_LIB_SONAME}\"")
  503. else()
  504. list (APPEND EXTRA_LIBS Xrandr)
  505. endif()
  506. set(SDL_VIDEO_DRIVER_X11_XRANDR 1)
  507. set(HAVE_VIDEO_X11_XRANDR TRUE)
  508. endif()
  509. if(VIDEO_X11_XSCRNSAVER AND HAVE_XSS_H)
  510. if(HAVE_X11_SHARED AND XSS_LIB)
  511. set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XSS "\"${XSS_LIB_SONAME}\"")
  512. else()
  513. list (APPEND EXTRA_LIBS Xss)
  514. endif()
  515. set(SDL_VIDEO_DRIVER_X11_XSCRNSAVER 1)
  516. set(HAVE_VIDEO_X11_XSCRNSAVER TRUE)
  517. endif()
  518. if(VIDEO_X11_XSHAPE AND HAVE_XSHAPE_H)
  519. set(SDL_VIDEO_DRIVER_X11_XSHAPE 1)
  520. set(HAVE_VIDEO_X11_XSHAPE TRUE)
  521. endif()
  522. if(VIDEO_X11_XVM AND HAVE_XF86VM_H)
  523. if(HAVE_X11_SHARED AND XXF86VM_LIB)
  524. set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XVIDMODE "\"${XXF86VM_LIB_SONAME}\"")
  525. else()
  526. list (APPEND EXTRA_LIBS Xxf86vm)
  527. endif()
  528. set(SDL_VIDEO_DRIVER_X11_XVIDMODE 1)
  529. set(HAVE_VIDEO_X11_XVM TRUE)
  530. endif()
  531. set(CMAKE_REQUIRED_LIBRARIES)
  532. set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
  533. endif()
  534. endif()
  535. endmacro()
  536. # Requires:
  537. # - EGL
  538. # Optional:
  539. # - MIR_SHARED opt
  540. # - HAVE_DLOPEN opt
  541. macro(CheckMir)
  542. if(VIDEO_MIR)
  543. # Urho3D - bug fix - do not use pkg-config tool for detection as it only works for host environment and not for rooted environment when cross-compiling
  544. # ATOMIC BEGIN
  545. find_package (Mir QUIET) # silence warnings
  546. # ATOMIC END
  547. if (MIR_FOUND)
  548. include_directories (SYSTEM ${MIR_INCLUDE_DIRS})
  549. set(HAVE_VIDEO_MIR TRUE)
  550. set(HAVE_SDL_VIDEO TRUE)
  551. file(GLOB MIR_SOURCES ${SDL2_SOURCE_DIR}/src/video/mir/*.c)
  552. set(SOURCE_FILES ${SOURCE_FILES} ${MIR_SOURCES})
  553. set(SDL_VIDEO_DRIVER_MIR 1)
  554. set(SDL_VIDEO_OPENGL_EGL 1)
  555. if(MIR_SHARED)
  556. if(NOT HAVE_DLOPEN)
  557. message_warn("You must have SDL_LoadObject() support for dynamic Mir loading")
  558. else()
  559. get_soname (MIRCLIENT_LIB_SONAME MIR_CLIENT)
  560. get_soname (XKBCOMMON_LIB_SONAME XKB)
  561. set(SDL_VIDEO_DRIVER_MIR_DYNAMIC "\"${MIRCLIENT_LIB_SONAME}\"")
  562. set(SDL_VIDEO_DRIVER_MIR_DYNAMIC_XKBCOMMON "\"${XKBCOMMON_LIB_SONAME}\"")
  563. set(HAVE_MIR_SHARED TRUE)
  564. endif()
  565. else()
  566. list (APPEND EXTRA_LIBS mirclient xkbcommon)
  567. endif()
  568. endif()
  569. endif()
  570. endmacro()
  571. macro(WaylandProtocolGen _SCANNER _XML _PROTL)
  572. set(_WAYLAND_PROT_C_CODE "${CMAKE_CURRENT_BINARY_DIR}/wayland-generated-protocols/${_PROTL}-protocol.c")
  573. set(_WAYLAND_PROT_H_CODE "${CMAKE_CURRENT_BINARY_DIR}/wayland-generated-protocols/${_PROTL}-client-protocol.h")
  574. add_custom_command(
  575. OUTPUT "${_WAYLAND_PROT_H_CODE}"
  576. DEPENDS "${_XML}"
  577. COMMAND "${_SCANNER}"
  578. ARGS client-header "${_XML}" "${_WAYLAND_PROT_H_CODE}"
  579. )
  580. add_custom_command(
  581. OUTPUT "${_WAYLAND_PROT_C_CODE}"
  582. DEPENDS "${_WAYLAND_PROT_H_CODE}"
  583. COMMAND "${_SCANNER}"
  584. ARGS code "${_XML}" "${_WAYLAND_PROT_C_CODE}"
  585. )
  586. set(SOURCE_FILES ${SOURCE_FILES} "${CMAKE_CURRENT_BINARY_DIR}/wayland-generated-protocols/${_PROTL}-protocol.c")
  587. endmacro()
  588. # Requires:
  589. # - EGL
  590. # Optional:
  591. # - WAYLAND_SHARED opt
  592. # - HAVE_DLOPEN opt
  593. macro(CheckWayland)
  594. if(VIDEO_WAYLAND)
  595. # Urho3D - bug fix - do not use pkg-config tool for detection as it only works for host environment and not for rooted environment when cross-compiling
  596. # ATOMIC BEGIN
  597. find_package (Wayland QUIET) # silence warnings
  598. # ATOMIC END
  599. if(WAYLAND_FOUND)
  600. include_directories (SYSTEM ${WAYLAND_INCLUDE_DIRS})
  601. set(HAVE_VIDEO_WAYLAND TRUE)
  602. set(HAVE_SDL_VIDEO TRUE)
  603. file(GLOB WAYLAND_SOURCES ${SDL2_SOURCE_DIR}/src/video/wayland/*.c)
  604. set(SOURCE_FILES ${SOURCE_FILES} ${WAYLAND_SOURCES})
  605. # We have to generate some protocol interface code for some unstable Wayland features.
  606. file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/wayland-generated-protocols")
  607. include_directories("${CMAKE_CURRENT_BINARY_DIR}/wayland-generated-protocols")
  608. WaylandProtocolGen("${WAYLAND_SCANNER}" "${WAYLAND_CORE_PROTOCOL_DIR}/wayland.xml" "wayland")
  609. foreach(_PROTL relative-pointer-unstable-v1 pointer-constraints-unstable-v1)
  610. string(REGEX REPLACE "\\-unstable\\-.*$" "" PROTSUBDIR ${_PROTL})
  611. WaylandProtocolGen("${WAYLAND_SCANNER}" "${WAYLAND_PROTOCOLS_DIR}/unstable/${PROTSUBDIR}/${_PROTL}.xml" "${_PROTL}")
  612. endforeach()
  613. if(VIDEO_WAYLAND_QT_TOUCH)
  614. set(SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH 1)
  615. endif()
  616. if(WAYLAND_SHARED)
  617. if(NOT HAVE_DLOPEN)
  618. message_warn("You must have SDL_LoadObject() support for dynamic Wayland loading")
  619. else()
  620. get_soname (WAYLAND_CLIENT_LIB_SONAME WAYLAND_CLIENT)
  621. get_soname (WAYLAND_EGL_LIB_SONAME WAYLAND_EGL)
  622. get_soname (WAYLAND_CURSOR_LIB_SONAME WAYLAND_CURSOR)
  623. get_soname (XKBCOMMON_LIB_SONAME XKB)
  624. set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC "\"${WAYLAND_CLIENT_LIB_SONAME}\"")
  625. set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_EGL "\"${WAYLAND_EGL_LIB_SONAME}\"")
  626. set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_CURSOR "\"${WAYLAND_CURSOR_LIB_SONAME}\"")
  627. set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_XKBCOMMON "\"${XKBCOMMON_LIB_SONAME}\"")
  628. set(HAVE_WAYLAND_SHARED TRUE)
  629. endif()
  630. else()
  631. list (APPEND EXTRA_LIBS wayland-client)
  632. endif()
  633. set(SDL_VIDEO_DRIVER_WAYLAND 1)
  634. set(SDL_VIDEO_OPENGL_EGL 1)
  635. endif()
  636. endif()
  637. endmacro()
  638. # Urho3D - commented out CheckCOCOA macro as it does not perform any check at all, moved the code to SDL's CMakeLists.txt
  639. # Requires:
  640. # - n/a
  641. # Optional:
  642. # - DIRECTFB_SHARED opt
  643. # - HAVE_DLOPEN opt
  644. macro(CheckDirectFB)
  645. if(VIDEO_DIRECTFB)
  646. # Urho3D - bug fix - do not use pkg-config tool for detection as it only works for host environment and not for rooted environment when cross-compiling
  647. # ATOMIC BEGIN
  648. find_package (DirectFB 1.0.0 QUIET) # silence warnings
  649. # ATOMIC END
  650. if(DIRECTFB_FOUND)
  651. include_directories (SYSTEM ${DIRECTFB_INCLUDE_DIRS})
  652. set(HAVE_VIDEO_DIRECTFB TRUE)
  653. file(GLOB DIRECTFB_SOURCES ${SDL2_SOURCE_DIR}/src/video/directfb/*.c)
  654. set(SOURCE_FILES ${SOURCE_FILES} ${DIRECTFB_SOURCES})
  655. set(SDL_VIDEO_DRIVER_DIRECTFB 1)
  656. set(SDL_VIDEO_RENDER_DIRECTFB 1)
  657. if(DIRECTFB_SHARED)
  658. if(NOT HAVE_DLOPEN)
  659. message_warn("You must have SDL_LoadObject() support for dynamic DirectFB loading")
  660. else()
  661. get_soname (DIRECTFB_LIB_SONAME DIRECTFB_LIBRARIES)
  662. set(SDL_VIDEO_DRIVER_DIRECTFB_DYNAMIC "\"${DIRECTFB_LIB_SONAME}\"")
  663. set(HAVE_DIRECTFB_SHARED TRUE)
  664. endif()
  665. else()
  666. list(APPEND EXTRA_LIBS directfb)
  667. endif()
  668. set(HAVE_SDL_VIDEO TRUE)
  669. endif()
  670. endif()
  671. endmacro()
  672. # Requires:
  673. # - n/a
  674. macro(CheckVivante)
  675. if(VIDEO_VIVANTE)
  676. # Urho3D - bug fix - when cross-compiling the headers are rooted, either use "--sysroot" compiler flag or use CMAKE_REQUIRED_INCLUDES (e.g. on RPI) to cater for it
  677. set (CMAKE_REQUIRED_INCLUDES_VIVANTE_SAVED ${CMAKE_REQUIRED_INCLUDES})
  678. if (CMAKE_CROSSCOMPILING AND NOT "${CMAKE_C_FLAGS} ${CMAKE_REQUIRED_FLAGS}" MATCHES --sysroot)
  679. find_path (VIVANTE_INCLUDE_DIRS NAMES gc_vdk.h EGL/eglvivante.h)
  680. if (VIVANTE_INCLUDE_DIRS)
  681. # Assume the header search path has not been adjusted elsewhere yet, there is no harm anyway when a same entry is added twice into the list
  682. list (APPEND CMAKE_REQUIRED_INCLUDES ${VIVANTE_INCLUDE_DIRS})
  683. endif ()
  684. endif ()
  685. check_c_source_compiles("
  686. #include <gc_vdk.h>
  687. int main(int argc, char** argv) {}" HAVE_VIDEO_VIVANTE_VDK)
  688. check_c_source_compiles("
  689. #define LINUX
  690. #define EGL_API_FB
  691. #include <EGL/eglvivante.h>
  692. int main(int argc, char** argv) {}" HAVE_VIDEO_VIVANTE_EGL_FB)
  693. if(HAVE_VIDEO_VIVANTE_VDK OR HAVE_VIDEO_VIVANTE_EGL_FB)
  694. set(HAVE_VIDEO_VIVANTE TRUE)
  695. set(HAVE_SDL_VIDEO TRUE)
  696. file(GLOB VIVANTE_SOURCES ${SDL2_SOURCE_DIR}/src/video/vivante/*.c)
  697. set(SOURCE_FILES ${SOURCE_FILES} ${VIVANTE_SOURCES})
  698. set(SDL_VIDEO_DRIVER_VIVANTE 1)
  699. if(HAVE_VIDEO_VIVANTE_VDK)
  700. set(SDL_VIDEO_DRIVER_VIVANTE_VDK 1)
  701. list(APPEND EXTRA_LIBS VDK VIVANTE)
  702. else()
  703. set(SDL_CFLAGS "${SDL_CFLAGS} -DLINUX -DEGL_API_FB")
  704. list(APPEND EXTRA_LIBS EGL)
  705. endif(HAVE_VIDEO_VIVANTE_VDK)
  706. endif(HAVE_VIDEO_VIVANTE_VDK OR HAVE_VIDEO_VIVANTE_EGL_FB)
  707. set (CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES_VIVANTE_SAVED})
  708. endif(VIDEO_VIVANTE)
  709. endmacro(CheckVivante)
  710. # Requires:
  711. # - nada
  712. # Urho3D - rename the macro to be generic OpenGL check and make it also work for OSX platform
  713. macro(CheckOpenGL)
  714. if(VIDEO_OPENGL)
  715. if (APPLE)
  716. check_c_source_compiles ("
  717. #include <OpenGL/OpenGL.h>
  718. #include <OpenGL/CGLRenderers.h>
  719. int main(int argc, char** argv) {}" HAVE_VIDEO_OPENGL)
  720. else ()
  721. check_c_source_compiles("
  722. #include <GL/gl.h>
  723. #include <GL/glx.h>
  724. int main(int argc, char** argv) {}" HAVE_VIDEO_OPENGL)
  725. endif ()
  726. if(HAVE_VIDEO_OPENGL)
  727. set(HAVE_VIDEO_OPENGL TRUE)
  728. set(SDL_VIDEO_OPENGL 1)
  729. if (APPLE)
  730. set (SDL_VIDEO_OPENGL_CGL 1)
  731. else ()
  732. set(SDL_VIDEO_OPENGL_GLX 1)
  733. endif ()
  734. set(SDL_VIDEO_RENDER_OGL 1)
  735. endif()
  736. endif()
  737. endmacro()
  738. # Requires:
  739. # - nada
  740. # Urho3D - rename the macro to be generic OpenGLES check and make it also work for iOS/tvOS platform
  741. macro(CheckOpenGLES)
  742. if(VIDEO_OPENGLES)
  743. check_c_source_compiles("
  744. #define EGL_API_FB
  745. #include <EGL/egl.h>
  746. int main (int argc, char** argv) {}" HAVE_VIDEO_OPENGL_EGL)
  747. if(HAVE_VIDEO_OPENGL_EGL)
  748. set(SDL_VIDEO_OPENGL_EGL 1)
  749. endif()
  750. check_c_source_compiles("
  751. #include <GLES/gl.h>
  752. #include <GLES/glext.h>
  753. int main (int argc, char** argv) {}" HAVE_VIDEO_OPENGLES_V1)
  754. if(HAVE_VIDEO_OPENGLES_V1)
  755. set(HAVE_VIDEO_OPENGLES TRUE)
  756. set(SDL_VIDEO_OPENGL_ES 1)
  757. set(SDL_VIDEO_RENDER_OGL_ES 1)
  758. endif()
  759. check_c_source_compiles("
  760. #include <GLES2/gl2.h>
  761. #include <GLES2/gl2ext.h>
  762. int main (int argc, char** argv) {}" HAVE_VIDEO_OPENGLES_V2)
  763. if(HAVE_VIDEO_OPENGLES_V2)
  764. set(HAVE_VIDEO_OPENGLES TRUE)
  765. set(SDL_VIDEO_OPENGL_ES2 1)
  766. set(SDL_VIDEO_RENDER_OGL_ES2 1)
  767. endif()
  768. endif()
  769. endmacro()
  770. # Requires:
  771. # - nada
  772. # Optional:
  773. # - THREADS opt
  774. macro(CheckPTHREAD)
  775. if(PTHREADS)
  776. # Urho3D - remove hardcoding of pthread-related compiler and linker flags for each platform
  777. set(CMAKE_REQUIRED_FLAGS "-pthread ${ORIG_CMAKE_REQUIRED_FLAGS}") # Android does not need this flag but it does no harm (i.e. appears to be no-op on Android)
  778. if(CMAKE_CROSSCOMPILING)
  779. check_c_source_compiles("
  780. #include <pthread.h>
  781. int main(int argc, char** argv) {
  782. pthread_attr_t type;
  783. pthread_attr_init(&type);
  784. return 0;
  785. }" HAVE_PTHREADS)
  786. else()
  787. check_c_source_runs("
  788. #include <pthread.h>
  789. int main(int argc, char** argv) {
  790. pthread_attr_t type;
  791. pthread_attr_init(&type);
  792. return 0;
  793. }" HAVE_PTHREADS)
  794. endif()
  795. if(HAVE_PTHREADS)
  796. set(SDL_THREAD_PTHREAD 1)
  797. # Urho3D - we configure to use "-pthread" compiler flags globally and expect the respective compiler toolchain to do the right things automatically
  798. set(SDL_CFLAGS "${SDL_CFLAGS} -pthread")
  799. check_c_source_compiles("
  800. #include <pthread.h>
  801. int main(int argc, char **argv) {
  802. pthread_mutexattr_t attr;
  803. pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
  804. return 0;
  805. }" HAVE_RECURSIVE_MUTEXES)
  806. if(HAVE_RECURSIVE_MUTEXES)
  807. set(SDL_THREAD_PTHREAD_RECURSIVE_MUTEX 1)
  808. else()
  809. check_c_source_compiles("
  810. #include <pthread.h>
  811. int main(int argc, char **argv) {
  812. pthread_mutexattr_t attr;
  813. pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
  814. return 0;
  815. }" HAVE_RECURSIVE_MUTEXES_NP)
  816. if(HAVE_RECURSIVE_MUTEXES_NP)
  817. set(SDL_THREAD_PTHREAD_RECURSIVE_MUTEX_NP 1)
  818. endif()
  819. endif()
  820. if(PTHREADS_SEM)
  821. check_c_source_compiles("#include <pthread.h>
  822. #include <semaphore.h>
  823. int main(int argc, char **argv) { return 0; }" HAVE_PTHREADS_SEM)
  824. if(HAVE_PTHREADS_SEM)
  825. check_c_source_compiles("
  826. #include <pthread.h>
  827. #include <semaphore.h>
  828. int main(int argc, char **argv) {
  829. sem_timedwait(NULL, NULL);
  830. return 0;
  831. }" HAVE_SEM_TIMEDWAIT)
  832. endif()
  833. endif()
  834. check_c_source_compiles("
  835. #include <pthread.h>
  836. #include <pthread_np.h>
  837. int main(int argc, char** argv) { return 0; }" HAVE_PTHREAD_NP_H)
  838. check_function_exists(pthread_setname_np HAVE_PTHREAD_SETNAME_NP)
  839. check_function_exists(pthread_set_name_np HAVE_PTHREAD_SET_NAME_NP)
  840. set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
  841. set(SOURCE_FILES ${SOURCE_FILES}
  842. ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_systhread.c
  843. ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_sysmutex.c # Can be faked, if necessary
  844. ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_syscond.c # Can be faked, if necessary
  845. ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_systls.c
  846. )
  847. if(HAVE_PTHREADS_SEM)
  848. set(SOURCE_FILES ${SOURCE_FILES}
  849. ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_syssem.c)
  850. else()
  851. set(SOURCE_FILES ${SOURCE_FILES}
  852. ${SDL2_SOURCE_DIR}/src/thread/generic/SDL_syssem.c)
  853. endif()
  854. set(HAVE_SDL_THREADS TRUE)
  855. endif()
  856. endif()
  857. endmacro()
  858. # Requires
  859. # - nada
  860. # Optional:
  861. # Sets:
  862. # USB_LIBS
  863. # USB_CFLAGS
  864. macro(CheckUSBHID)
  865. # Urho3D - no fix required - all these checks appear to be for BSD only, assume only native build
  866. # Cannot fix them for X-compiling anyway as we/I don't have the necessary means to verify the changes
  867. check_library_exists(usbhid hid_init "" LIBUSBHID)
  868. if(LIBUSBHID)
  869. check_include_file(usbhid.h HAVE_USBHID_H)
  870. if(HAVE_USBHID_H)
  871. set(USB_CFLAGS "-DHAVE_USBHID_H")
  872. endif()
  873. check_include_file(libusbhid.h HAVE_LIBUSBHID_H)
  874. if(HAVE_LIBUSBHID_H)
  875. set(USB_CFLAGS "${USB_CFLAGS} -DHAVE_LIBUSBHID_H")
  876. endif()
  877. set(USB_LIBS ${USB_LIBS} usbhid)
  878. else()
  879. check_include_file(usb.h HAVE_USB_H)
  880. if(HAVE_USB_H)
  881. set(USB_CFLAGS "-DHAVE_USB_H")
  882. endif()
  883. check_include_file(libusb.h HAVE_LIBUSB_H)
  884. if(HAVE_LIBUSB_H)
  885. set(USB_CFLAGS "${USB_CFLAGS} -DHAVE_LIBUSB_H")
  886. endif()
  887. check_library_exists(usb hid_init "" LIBUSB)
  888. if(LIBUSB)
  889. set(USB_LIBS ${USB_LIBS} usb)
  890. endif()
  891. endif()
  892. set(CMAKE_REQUIRED_FLAGS "${USB_CFLAGS} ${ORIG_CMAKE_REQUIRED_FLAGS}")
  893. set(CMAKE_REQUIRED_LIBRARIES "${USB_LIBS}")
  894. check_c_source_compiles("
  895. #include <sys/types.h>
  896. #if defined(HAVE_USB_H)
  897. #include <usb.h>
  898. #endif
  899. #ifdef __DragonFly__
  900. # include <bus/usb/usb.h>
  901. # include <bus/usb/usbhid.h>
  902. #else
  903. # include <dev/usb/usb.h>
  904. # include <dev/usb/usbhid.h>
  905. #endif
  906. #if defined(HAVE_USBHID_H)
  907. #include <usbhid.h>
  908. #elif defined(HAVE_LIBUSB_H)
  909. #include <libusb.h>
  910. #elif defined(HAVE_LIBUSBHID_H)
  911. #include <libusbhid.h>
  912. #endif
  913. int main(int argc, char **argv) {
  914. struct report_desc *repdesc;
  915. struct usb_ctl_report *repbuf;
  916. hid_kind_t hidkind;
  917. return 0;
  918. }" HAVE_USBHID)
  919. if(HAVE_USBHID)
  920. check_c_source_compiles("
  921. #include <sys/types.h>
  922. #if defined(HAVE_USB_H)
  923. #include <usb.h>
  924. #endif
  925. #ifdef __DragonFly__
  926. # include <bus/usb/usb.h>
  927. # include <bus/usb/usbhid.h>
  928. #else
  929. # include <dev/usb/usb.h>
  930. # include <dev/usb/usbhid.h>
  931. #endif
  932. #if defined(HAVE_USBHID_H)
  933. #include <usbhid.h>
  934. #elif defined(HAVE_LIBUSB_H)
  935. #include <libusb.h>
  936. #elif defined(HAVE_LIBUSBHID_H)
  937. #include <libusbhid.h>
  938. #endif
  939. int main(int argc, char** argv) {
  940. struct usb_ctl_report buf;
  941. if (buf.ucr_data) { }
  942. return 0;
  943. }" HAVE_USBHID_UCR_DATA)
  944. if(HAVE_USBHID_UCR_DATA)
  945. set(USB_CFLAGS "${USB_CFLAGS} -DUSBHID_UCR_DATA")
  946. endif()
  947. check_c_source_compiles("
  948. #include <sys/types.h>
  949. #if defined(HAVE_USB_H)
  950. #include <usb.h>
  951. #endif
  952. #ifdef __DragonFly__
  953. #include <bus/usb/usb.h>
  954. #include <bus/usb/usbhid.h>
  955. #else
  956. #include <dev/usb/usb.h>
  957. #include <dev/usb/usbhid.h>
  958. #endif
  959. #if defined(HAVE_USBHID_H)
  960. #include <usbhid.h>
  961. #elif defined(HAVE_LIBUSB_H)
  962. #include <libusb.h>
  963. #elif defined(HAVE_LIBUSBHID_H)
  964. #include <libusbhid.h>
  965. #endif
  966. int main(int argc, char **argv) {
  967. report_desc_t d;
  968. hid_start_parse(d, 1, 1);
  969. return 0;
  970. }" HAVE_USBHID_NEW)
  971. if(HAVE_USBHID_NEW)
  972. set(USB_CFLAGS "${USB_CFLAGS} -DUSBHID_NEW")
  973. endif()
  974. check_c_source_compiles("
  975. #include <machine/joystick.h>
  976. int main(int argc, char** argv) {
  977. struct joystick t;
  978. return 0;
  979. }" HAVE_MACHINE_JOYSTICK)
  980. if(HAVE_MACHINE_JOYSTICK)
  981. set(SDL_JOYSTICK_USBHID_MACHINE_JOYSTICK_H 1)
  982. endif()
  983. set(SDL_JOYSTICK_USBHID 1)
  984. file(GLOB BSD_JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/bsd/*.c)
  985. set(SOURCE_FILES ${SOURCE_FILES} ${BSD_JOYSTICK_SOURCES})
  986. list(APPEND EXTRA_CFLAGS ${USB_CFLAGS})
  987. list(APPEND EXTRA_LIBS ${USB_LIBS})
  988. set(HAVE_SDL_JOYSTICK TRUE)
  989. set(CMAKE_REQUIRED_LIBRARIES)
  990. set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
  991. endif()
  992. endmacro()
  993. # Requires:
  994. # - n/a
  995. macro(CheckRPI)
  996. if(VIDEO_RPI)
  997. # Urho3D - bug fix - commented out CMAKE_REQUIRED_LIBRARIES as it actually causes the detection to fail
  998. check_c_source_compiles("
  999. #include <bcm_host.h>
  1000. int main(int argc, char **argv) {}" HAVE_VIDEO_RPI)
  1001. if(SDL_VIDEO AND HAVE_VIDEO_RPI)
  1002. set(HAVE_SDL_VIDEO TRUE)
  1003. set(SDL_VIDEO_DRIVER_RPI 1)
  1004. file(GLOB VIDEO_RPI_SOURCES ${SDL2_SOURCE_DIR}/src/video/raspberry/*.c)
  1005. set(SOURCE_FILES ${SOURCE_FILES} ${VIDEO_RPI_SOURCES})
  1006. list (APPEND EXTRA_LIBS bcm_host)
  1007. endif(SDL_VIDEO AND HAVE_VIDEO_RPI)
  1008. endif(VIDEO_RPI)
  1009. endmacro(CheckRPI)