sdlchecks.cmake 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135
  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-2020 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. check_function_exists(dlopen DLOPEN_FOUND)
  64. if(NOT DLOPEN_FOUND)
  65. foreach(_LIBNAME dl tdl)
  66. check_library_exists("${_LIBNAME}" "dlopen" "" DLOPEN_LIB_${_LIBNAME}_FOUND)
  67. if(DLOPEN_LIB_${_LIBNAME}_FOUND)
  68. list(APPEND EXTRA_LIBS ${_LIBNAME})
  69. set(_DLLIB ${_LIBNAME})
  70. set(DLOPEN_FOUND TRUE)
  71. break()
  72. endif()
  73. endforeach()
  74. endif()
  75. if(DLOPEN_FOUND)
  76. if(_DLLIB)
  77. set(CMAKE_REQUIRED_LIBRARIES ${_DLLIB})
  78. endif()
  79. check_c_source_compiles("
  80. #include <dlfcn.h>
  81. int main(int argc, char **argv) {
  82. void *handle = dlopen(\"\", RTLD_NOW);
  83. const char *loaderror = (char *) dlerror();
  84. }" HAVE_DLOPEN)
  85. set(CMAKE_REQUIRED_LIBRARIES)
  86. endif()
  87. endif ()
  88. if(HAVE_DLOPEN)
  89. set(SDL_LOADSO_DLOPEN 1)
  90. set(HAVE_SDL_DLOPEN TRUE)
  91. file(GLOB DLOPEN_SOURCES ${SDL2_SOURCE_DIR}/src/loadso/dlopen/*.c)
  92. set(SOURCE_FILES ${SOURCE_FILES} ${DLOPEN_SOURCES})
  93. set(HAVE_SDL_LOADSO TRUE)
  94. endif()
  95. endif ()
  96. endmacro()
  97. # Requires:
  98. # - n/a
  99. macro(CheckOSS)
  100. if(OSS)
  101. # Urho3D - bug fix - should use different variables for different checks, however, we replace the whole checks with find_package() approach for consistency sake
  102. find_package (OSS)
  103. if(OSS_FOUND)
  104. include_directories (SYSTEM ${OSS_INCLUDE_DIRS})
  105. if (OSS_LIBRARIES)
  106. get_filename_component(NAME_WE ${OSS_LIBRARIES} NAME_WE)
  107. string (REGEX REPLACE ^lib "" NAME_WE "${NAME_WE}") # Stringify for string replacement
  108. list(APPEND EXTRA_LIBS ${NAME_WE})
  109. endif ()
  110. set(HAVE_OSS TRUE)
  111. file(GLOB OSS_SOURCES ${SDL2_SOURCE_DIR}/src/audio/dsp/*.c)
  112. if(OSS_USE_WORKAROUND_HEADER)
  113. set(SDL_AUDIO_DRIVER_OSS_SOUNDCARD_H 1)
  114. endif()
  115. set(SDL_AUDIO_DRIVER_OSS 1)
  116. set(SOURCE_FILES ${SOURCE_FILES} ${OSS_SOURCES})
  117. set(HAVE_SDL_AUDIO TRUE)
  118. endif()
  119. endif()
  120. endmacro()
  121. # Requires:
  122. # - n/a
  123. # Optional:
  124. # - ALSA_SHARED opt
  125. # - HAVE_DLOPEN opt
  126. macro(CheckALSA)
  127. if(ALSA)
  128. # Urho3D - bug fix - use the more trusted FindALSA module as it has been tested to work for both native and cross-compiling build
  129. find_package (ALSA)
  130. # todo: remove this fix when the minimum CMake version has been raised to higher than 2.8.7
  131. # There is a bug in older version of FindALSA.cmake module where it erroneously include 'alsa' directory component into the variable
  132. # For cross-compiling build to work correctly, this extra directory component must be removed
  133. if (ALSA_INCLUDE_DIRS MATCHES .*/alsa)
  134. get_filename_component (ALSA_INCLUDE_DIRS ${ALSA_INCLUDE_DIRS} PATH)
  135. endif ()
  136. if(ALSA_FOUND)
  137. include_directories (SYSTEM ${ALSA_INCLUDE_DIRS})
  138. set(HAVE_ALSA TRUE)
  139. file(GLOB ALSA_SOURCES ${SDL2_SOURCE_DIR}/src/audio/alsa/*.c)
  140. set(SOURCE_FILES ${SOURCE_FILES} ${ALSA_SOURCES})
  141. set(SDL_AUDIO_DRIVER_ALSA 1)
  142. if(ALSA_SHARED)
  143. if(NOT HAVE_DLOPEN)
  144. message_warn("You must have SDL_LoadObject() support for dynamic ALSA loading")
  145. else()
  146. get_soname (ASOUND_LIB_SONAME ALSA_LIBRARIES)
  147. set(SDL_AUDIO_DRIVER_ALSA_DYNAMIC "\"${ASOUND_LIB_SONAME}\"")
  148. set(HAVE_ALSA_SHARED TRUE)
  149. endif()
  150. else()
  151. list(APPEND EXTRA_LIBS asound)
  152. endif()
  153. set(HAVE_SDL_AUDIO TRUE)
  154. endif()
  155. endif()
  156. endmacro()
  157. # Requires:
  158. # - n/a
  159. # Optional:
  160. # - PULSEAUDIO_SHARED opt
  161. # - HAVE_DLOPEN opt
  162. macro(CheckPulseAudio)
  163. if(PULSEAUDIO)
  164. # 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
  165. find_package (PulseAudio)
  166. if(PULSEAUDIO_FOUND)
  167. include_directories (SYSTEM ${PULSEAUDIO_INCLUDE_DIRS})
  168. set(HAVE_PULSEAUDIO TRUE)
  169. file(GLOB PULSEAUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/pulseaudio/*.c)
  170. set(SOURCE_FILES ${SOURCE_FILES} ${PULSEAUDIO_SOURCES})
  171. set(SDL_AUDIO_DRIVER_PULSEAUDIO 1)
  172. # 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
  173. if(PULSEAUDIO_SHARED)
  174. if(NOT HAVE_DLOPEN)
  175. message_warn("You must have SDL_LoadObject() support for dynamic PulseAudio loading")
  176. else()
  177. get_soname (PULSE_SIMPLE_LIB_SONAME PULSEAUDIO_LIBRARIES)
  178. set(SDL_AUDIO_DRIVER_PULSEAUDIO_DYNAMIC "\"${PULSE_SIMPLE_LIB_SONAME}\"")
  179. set(HAVE_PULSEAUDIO_SHARED TRUE)
  180. endif()
  181. else()
  182. list (APPEND EXTRA_LIBS pulse-simple pulse)
  183. endif()
  184. set(HAVE_SDL_AUDIO TRUE)
  185. endif()
  186. endif()
  187. endmacro()
  188. # Requires:
  189. # - n/a
  190. # Optional:
  191. # - JACK_SHARED opt
  192. # - HAVE_DLOPEN opt
  193. macro(CheckJACK)
  194. if(JACK)
  195. # 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
  196. find_package (Jack)
  197. if(JACK_FOUND)
  198. include_directories (SYSTEM ${JACK_INCLUDE_DIRS})
  199. set(HAVE_JACK TRUE)
  200. file(GLOB JACK_SOURCES ${SDL2_SOURCE_DIR}/src/audio/jack/*.c)
  201. set(SOURCE_FILES ${SOURCE_FILES} ${JACK_SOURCES})
  202. set(SDL_AUDIO_DRIVER_JACK 1)
  203. if(JACK_SHARED)
  204. if(NOT HAVE_DLOPEN)
  205. message_warn("You must have SDL_LoadObject() support for dynamic JACK audio loading")
  206. else()
  207. get_soname (JACK_LIB_SONAME JACK_LIBRARIES)
  208. set(SDL_AUDIO_DRIVER_JACK_DYNAMIC "\"${JACK_LIB_SONAME}\"")
  209. set(HAVE_JACK_SHARED TRUE)
  210. endif()
  211. else()
  212. list (APPEND EXTRA_LIBS jack)
  213. endif()
  214. set(HAVE_SDL_AUDIO TRUE)
  215. endif()
  216. endif()
  217. endmacro()
  218. # Requires:
  219. # - PkgCheckModules
  220. # Optional:
  221. # - ESD_SHARED opt
  222. # - HAVE_DLOPEN opt
  223. macro(CheckESD)
  224. if(ESD)
  225. # 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
  226. find_package (Esound)
  227. if(ESOUND_FOUND)
  228. include_directories (SYSTEM ${ESOUND_INCLUDE_DIRS})
  229. set(HAVE_ESD TRUE)
  230. file(GLOB ESD_SOURCES ${SDL2_SOURCE_DIR}/src/audio/esd/*.c)
  231. set(SOURCE_FILES ${SOURCE_FILES} ${ESD_SOURCES})
  232. set(SDL_AUDIO_DRIVER_ESD 1)
  233. if(ESD_SHARED)
  234. if(NOT HAVE_DLOPEN)
  235. message_warn("You must have SDL_LoadObject() support for dynamic ESD loading")
  236. else()
  237. get_soname (ESD_LIB_SONAME ESOUND_LIBRARIES)
  238. set(SDL_AUDIO_DRIVER_ESD_DYNAMIC "\"${ESD_LIB_SONAME}\"")
  239. set(HAVE_ESD_SHARED TRUE)
  240. endif()
  241. else()
  242. list (APPEND EXTRA_LIBS esd)
  243. endif()
  244. set(HAVE_SDL_AUDIO TRUE)
  245. endif()
  246. endif()
  247. endmacro()
  248. # Requires:
  249. # - n/a
  250. # Optional:
  251. # - ARTS_SHARED opt
  252. # - HAVE_DLOPEN opt
  253. macro(CheckARTS)
  254. if(ARTS)
  255. # 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
  256. find_package (aRts)
  257. if(ARTS_FOUND)
  258. include_directories (SYSTEM ${ARTS_INCLUDE_DIRS})
  259. file(GLOB ARTS_SOURCES ${SDL2_SOURCE_DIR}/src/audio/arts/*.c)
  260. set(SOURCE_FILES ${SOURCE_FILES} ${ARTS_SOURCES})
  261. set(SDL_AUDIO_DRIVER_ARTS 1)
  262. set(HAVE_ARTS TRUE)
  263. if(ARTS_SHARED)
  264. if(NOT HAVE_DLOPEN)
  265. message_warn("You must have SDL_LoadObject() support for dynamic ARTS loading")
  266. else()
  267. get_soname (ARTSC_LIB_SONAME ARTS_LIBRARIES)
  268. set(SDL_AUDIO_DRIVER_ARTS_DYNAMIC "\"${ARTSC_LIB_SONAME}\"")
  269. set(HAVE_ARTS_SHARED TRUE)
  270. endif()
  271. else()
  272. list (APPEND EXTRA_LIBS artsc)
  273. endif()
  274. set(HAVE_SDL_AUDIO TRUE)
  275. endif()
  276. endif()
  277. endmacro()
  278. # Requires:
  279. # - n/a
  280. # Optional:
  281. # - NAS_SHARED opt
  282. # - HAVE_DLOPEN opt
  283. macro(CheckNAS)
  284. if(NAS)
  285. # 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
  286. find_package (NAS)
  287. if(NAS_FOUND)
  288. include_directories (SYSTEM ${NAS_INCLUDE_DIRS})
  289. set(HAVE_NAS TRUE)
  290. file(GLOB NAS_SOURCES ${SDL2_SOURCE_DIR}/src/audio/nas/*.c)
  291. set(SOURCE_FILES ${SOURCE_FILES} ${NAS_SOURCES})
  292. set(SDL_AUDIO_DRIVER_NAS 1)
  293. if(NAS_SHARED)
  294. if(NOT HAVE_DLOPEN)
  295. message_warn("You must have SDL_LoadObject() support for dynamic NAS loading")
  296. else()
  297. get_soname (AUDIO_LIB_SONAME NAS_LIBRARIES)
  298. set(SDL_AUDIO_DRIVER_NAS_DYNAMIC "\"${AUDIO_LIB_SONAME}\"")
  299. set(HAVE_NAS_SHARED TRUE)
  300. endif()
  301. else()
  302. list (APPEND EXTRA_LIBS audio)
  303. endif()
  304. set(HAVE_SDL_AUDIO TRUE)
  305. endif()
  306. endif()
  307. endmacro()
  308. # Requires:
  309. # - n/a
  310. # Optional:
  311. # - SNDIO_SHARED opt
  312. # - HAVE_DLOPEN opt
  313. macro(CheckSNDIO)
  314. if(SNDIO)
  315. # 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
  316. find_package (SNDIO)
  317. if(SNDIO_FOUND)
  318. include_directories (SYSTEM ${SNDIO_INCLUDE_DIRS})
  319. set(HAVE_SNDIO TRUE)
  320. file(GLOB SNDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/sndio/*.c)
  321. set(SOURCE_FILES ${SOURCE_FILES} ${SNDIO_SOURCES})
  322. set(SDL_AUDIO_DRIVER_SNDIO 1)
  323. if(SNDIO_SHARED)
  324. if(NOT HAVE_DLOPEN)
  325. message_warn("You must have SDL_LoadObject() support for dynamic sndio loading")
  326. else()
  327. get_soname (SNDIO_LIB_SONAME SNDIO_LIBRARIES)
  328. set(SDL_AUDIO_DRIVER_SNDIO_DYNAMIC "\"${SNDIO_LIB_SONAME}\"")
  329. set(HAVE_SNDIO_SHARED TRUE)
  330. endif()
  331. else()
  332. list(APPEND EXTRA_LIBS sndio)
  333. endif()
  334. set(HAVE_SDL_AUDIO TRUE)
  335. endif()
  336. endif()
  337. endmacro()
  338. # Requires:
  339. # - n/a
  340. # Optional:
  341. # - FUSIONSOUND_SHARED opt
  342. # - HAVE_DLOPEN opt
  343. macro(CheckFusionSound)
  344. if(FUSIONSOUND)
  345. # 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
  346. find_package (FusionSound 1.0.0)
  347. if(FUSIONSOUND_FOUND)
  348. include_directories (SYSTEM ${FUSIONSOUND_INCLUDE_DIRS})
  349. set(HAVE_FUSIONSOUND TRUE)
  350. file(GLOB FUSIONSOUND_SOURCES ${SDL2_SOURCE_DIR}/src/audio/fusionsound/*.c)
  351. set(SOURCE_FILES ${SOURCE_FILES} ${FUSIONSOUND_SOURCES})
  352. set(SDL_AUDIO_DRIVER_FUSIONSOUND 1)
  353. if(FUSIONSOUND_SHARED)
  354. if(NOT HAVE_DLOPEN)
  355. message_warn("You must have SDL_LoadObject() support for dynamic FusionSound loading")
  356. else()
  357. get_soname (FUSIONSOUND_LIB_SONAME FUSIONSOUND_LIBRARIES)
  358. set(SDL_AUDIO_DRIVER_FUSIONSOUND_DYNAMIC "\"${FUSIONSOUND_LIB_SONAME}\"")
  359. set(HAVE_FUSIONSOUND_SHARED TRUE)
  360. endif()
  361. else()
  362. list (APPEND EXTRA_LIBS fusionsound)
  363. endif()
  364. set(HAVE_SDL_AUDIO TRUE)
  365. endif()
  366. endif()
  367. endmacro()
  368. # Requires:
  369. # - LIBSAMPLERATE
  370. # Optional:
  371. # - LIBSAMPLERATE_SHARED opt
  372. # - HAVE_DLOPEN opt
  373. macro(CheckLibSampleRate)
  374. if(LIBSAMPLERATE)
  375. # Urho3D - use custom CMake module to find the audio driver like the rest for consistency sake
  376. find_package (SecretRabbitCode)
  377. if(SECRETRABBITCODE_FOUND)
  378. include_directories (SYSTEM ${SECRETRABBITCODE_INCLUDE_DIRS})
  379. set (HAVE_LIBSAMPLERATE_H TRUE)
  380. if(LIBSAMPLERATE_SHARED)
  381. if(NOT HAVE_DLOPEN)
  382. message_warn("You must have SDL_LoadObject() support for dynamic libsamplerate loading")
  383. else()
  384. get_soname (SAMPLERATE_LIB_SONAME SECRETRABBITCODE_LIBRARIES)
  385. set(SDL_LIBSAMPLERATE_DYNAMIC "\"${SAMPLERATE_LIB_SONAME}\"")
  386. set(HAVE_LIBSAMPLERATE_SHARED TRUE)
  387. endif()
  388. else()
  389. list (APPEND EXTRA_LIBS samplerate)
  390. endif()
  391. endif()
  392. endif()
  393. endmacro()
  394. # Requires:
  395. # - n/a
  396. # Optional:
  397. # - X11_SHARED opt
  398. # - HAVE_DLOPEN opt
  399. macro(CheckX11)
  400. if(VIDEO_X11)
  401. # 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
  402. set(CMAKE_REQUIRED_FLAGS "-fPIC -shared ${ORIG_CMAKE_REQUIRED_FLAGS}")
  403. foreach (NAME X11 Xext Xcursor Xinerama Xi Xrandr Xrender Xss Xxf86vm)
  404. string (TOUPPER ${NAME} UPCASE_NAME)
  405. string (REGEX REPLACE \\..+$ "" UPCASE_NAME "${UPCASE_NAME}") # Stringify for string replacement
  406. find_library (${UPCASE_NAME}_LIB ${NAME})
  407. get_soname (${UPCASE_NAME}_LIB_SONAME ${UPCASE_NAME}_LIB)
  408. endforeach ()
  409. # Urho3D - commented out setting of EXTRA_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)
  410. # Urho3D - add check for Xdbe extension
  411. check_include_file(X11/Xcursor/Xcursor.h HAVE_XCURSOR_H)
  412. check_include_file(X11/extensions/Xinerama.h HAVE_XINERAMA_H)
  413. check_include_file(X11/extensions/XInput2.h HAVE_XINPUT_H)
  414. check_include_file(X11/extensions/Xrandr.h HAVE_XRANDR_H)
  415. check_include_file(X11/extensions/Xrender.h HAVE_XRENDER_H)
  416. check_include_file(X11/extensions/shape.h HAVE_XSHAPE_H)
  417. check_include_file(X11/extensions/scrnsaver.h HAVE_XSS_H)
  418. check_include_files("X11/Xlib.h;X11/Xproto.h;X11/extensions/Xdbe.h" HAVE_XDBE_H)
  419. check_include_files("X11/Xlib.h;X11/Xproto.h;X11/extensions/Xext.h" HAVE_XEXT_H)
  420. check_include_files("X11/Xlib.h;X11/extensions/xf86vmode.h" HAVE_XF86VM_H)
  421. if(X11_LIB)
  422. if(NOT HAVE_XEXT_H)
  423. message_error("Missing Xext.h, maybe you need to install the libxext-dev package?")
  424. endif()
  425. if (HAVE_XDBE_H)
  426. set(SDL_VIDEO_DRIVER_X11_XDBE 1)
  427. endif ()
  428. set(HAVE_VIDEO_X11 TRUE)
  429. set(HAVE_SDL_VIDEO TRUE)
  430. file(GLOB X11_SOURCES ${SDL2_SOURCE_DIR}/src/video/x11/*.c)
  431. set(SOURCE_FILES ${SOURCE_FILES} ${X11_SOURCES})
  432. set(SDL_VIDEO_DRIVER_X11 1)
  433. if(APPLE)
  434. set(X11_SHARED OFF)
  435. endif()
  436. check_function_exists("shmat" HAVE_SHMAT)
  437. if(NOT HAVE_SHMAT)
  438. # Urho3D - bug fix - use different variables for different checks because of CMake caches the result variable
  439. check_library_exists(ipc shmat "" HAVE_SHMAT_IN_IPC)
  440. if(HAVE_SHMAT_IN_IPC)
  441. list(APPEND EXTRA_LIBS ipc)
  442. set (HAVE_SHMAT TRUE)
  443. endif()
  444. if(NOT HAVE_SHMAT)
  445. add_definitions(-DNO_SHARED_MEMORY)
  446. list(APPEND EXTRA_CFLAGS "-DNO_SHARED_MEMORY")
  447. endif()
  448. endif()
  449. if(X11_SHARED)
  450. if(NOT HAVE_DLOPEN)
  451. message_warn("You must have SDL_LoadObject() support for dynamic X11 loading")
  452. set(HAVE_X11_SHARED FALSE)
  453. else()
  454. set(HAVE_X11_SHARED TRUE)
  455. endif()
  456. if(HAVE_X11_SHARED)
  457. set(SDL_VIDEO_DRIVER_X11_DYNAMIC "\"${X11_LIB_SONAME}\"")
  458. set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT "\"${XEXT_LIB_SONAME}\"")
  459. else()
  460. # Urho3D - bug fix - the EXTRA_LIBS is list of library names (not the fully-qualified path to the library itself)
  461. list (APPEND EXTRA_LIBS X11 Xext)
  462. endif()
  463. endif()
  464. set(CMAKE_REQUIRED_LIBRARIES ${X11_LIB} ${X11_LIB})
  465. check_c_source_compiles("
  466. #include <X11/Xlib.h>
  467. #include <X11/Xproto.h>
  468. #include <X11/extensions/Xext.h>
  469. #include <X11/extensions/extutil.h>
  470. extern XExtDisplayInfo* XextAddDisplay(XExtensionInfo* a,Display* b,_Xconst char* c,XExtensionHooks* d,int e,XPointer f);
  471. int main(int argc, char **argv) {}" HAVE_CONST_XEXT_ADDDISPLAY)
  472. if(HAVE_CONST_XEXT_ADDDISPLAY)
  473. set(SDL_VIDEO_DRIVER_X11_CONST_PARAM_XEXTADDDISPLAY 1)
  474. endif()
  475. check_c_source_compiles("
  476. #include <X11/Xlib.h>
  477. int main(int argc, char **argv) {
  478. Display *display;
  479. XEvent event;
  480. XGenericEventCookie *cookie = &event.xcookie;
  481. XNextEvent(display, &event);
  482. XGetEventData(display, cookie);
  483. XFreeEventData(display, cookie); }" HAVE_XGENERICEVENT)
  484. if(HAVE_XGENERICEVENT)
  485. set(SDL_VIDEO_DRIVER_X11_SUPPORTS_GENERIC_EVENTS 1)
  486. endif()
  487. check_function_exists(XkbKeycodeToKeysym SDL_VIDEO_DRIVER_X11_HAS_XKBKEYCODETOKEYSYM)
  488. if(VIDEO_X11_XCURSOR AND HAVE_XCURSOR_H)
  489. set(HAVE_VIDEO_X11_XCURSOR TRUE)
  490. if(HAVE_X11_SHARED AND XCURSOR_LIB)
  491. set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XCURSOR "\"${XCURSOR_LIB_SONAME}\"")
  492. else()
  493. list (APPEND EXTRA_LIBS Xcursor)
  494. endif()
  495. set(SDL_VIDEO_DRIVER_X11_XCURSOR 1)
  496. endif()
  497. if(VIDEO_X11_XINERAMA AND HAVE_XINERAMA_H)
  498. set(HAVE_VIDEO_X11_XINERAMA TRUE)
  499. if(HAVE_X11_SHARED AND XINERAMA_LIB)
  500. set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XINERAMA "\"${XINERAMA_LIB_SONAME}\"")
  501. else()
  502. list (APPEND EXTRA_LIBS Xinerama)
  503. endif()
  504. set(SDL_VIDEO_DRIVER_X11_XINERAMA 1)
  505. endif()
  506. if(VIDEO_X11_XINPUT AND HAVE_XINPUT_H)
  507. set(HAVE_VIDEO_X11_XINPUT TRUE)
  508. if(HAVE_X11_SHARED AND XI_LIB)
  509. set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT2 "\"${XI_LIB_SONAME}\"")
  510. else()
  511. list (APPEND EXTRA_LIBS Xi)
  512. endif()
  513. set(SDL_VIDEO_DRIVER_X11_XINPUT2 1)
  514. # Check for multitouch
  515. check_c_source_compiles("
  516. #include <X11/Xlib.h>
  517. #include <X11/Xproto.h>
  518. #include <X11/extensions/XInput2.h>
  519. int event_type = XI_TouchBegin;
  520. XITouchClassInfo *t;
  521. Status XIAllowTouchEvents(Display *a,int b,unsigned int c,Window d,int f)
  522. {
  523. return (Status)0;
  524. }
  525. int main(int argc, char **argv) {}" HAVE_XINPUT2_MULTITOUCH)
  526. if(HAVE_XINPUT2_MULTITOUCH)
  527. set(SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH 1)
  528. endif()
  529. endif()
  530. if(VIDEO_X11_XRANDR AND HAVE_XRANDR_H)
  531. if(HAVE_X11_SHARED AND XRANDR_LIB)
  532. set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR "\"${XRANDR_LIB_SONAME}\"")
  533. else()
  534. list (APPEND EXTRA_LIBS Xrandr)
  535. endif()
  536. set(SDL_VIDEO_DRIVER_X11_XRANDR 1)
  537. set(HAVE_VIDEO_X11_XRANDR TRUE)
  538. endif()
  539. if(VIDEO_X11_XSCRNSAVER AND HAVE_XSS_H)
  540. if(HAVE_X11_SHARED AND XSS_LIB)
  541. set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XSS "\"${XSS_LIB_SONAME}\"")
  542. else()
  543. list (APPEND EXTRA_LIBS Xss)
  544. endif()
  545. set(SDL_VIDEO_DRIVER_X11_XSCRNSAVER 1)
  546. set(HAVE_VIDEO_X11_XSCRNSAVER TRUE)
  547. endif()
  548. if(VIDEO_X11_XSHAPE AND HAVE_XSHAPE_H)
  549. set(SDL_VIDEO_DRIVER_X11_XSHAPE 1)
  550. set(HAVE_VIDEO_X11_XSHAPE TRUE)
  551. endif()
  552. if(VIDEO_X11_XVM AND HAVE_XF86VM_H)
  553. if(HAVE_X11_SHARED AND XXF86VM_LIB)
  554. set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XVIDMODE "\"${XXF86VM_LIB_SONAME}\"")
  555. else()
  556. list (APPEND EXTRA_LIBS Xxf86vm)
  557. endif()
  558. set(SDL_VIDEO_DRIVER_X11_XVIDMODE 1)
  559. set(HAVE_VIDEO_X11_XVM TRUE)
  560. endif()
  561. set(CMAKE_REQUIRED_LIBRARIES)
  562. set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
  563. endif()
  564. endif()
  565. endmacro()
  566. macro(WaylandProtocolGen _SCANNER _XML _PROTL)
  567. set(_WAYLAND_PROT_C_CODE "${CMAKE_CURRENT_BINARY_DIR}/wayland-generated-protocols/${_PROTL}-protocol.c")
  568. set(_WAYLAND_PROT_H_CODE "${CMAKE_CURRENT_BINARY_DIR}/wayland-generated-protocols/${_PROTL}-client-protocol.h")
  569. add_custom_command(
  570. OUTPUT "${_WAYLAND_PROT_H_CODE}"
  571. DEPENDS "${_XML}"
  572. COMMAND "${_SCANNER}"
  573. ARGS client-header "${_XML}" "${_WAYLAND_PROT_H_CODE}"
  574. )
  575. add_custom_command(
  576. OUTPUT "${_WAYLAND_PROT_C_CODE}"
  577. DEPENDS "${_WAYLAND_PROT_H_CODE}"
  578. COMMAND "${_SCANNER}"
  579. ARGS code "${_XML}" "${_WAYLAND_PROT_C_CODE}"
  580. )
  581. set(SOURCE_FILES ${SOURCE_FILES} "${_WAYLAND_PROT_C_CODE}")
  582. endmacro()
  583. # Requires:
  584. # - EGL
  585. # Optional:
  586. # - WAYLAND_SHARED opt
  587. # - HAVE_DLOPEN opt
  588. macro(CheckWayland)
  589. if(VIDEO_WAYLAND)
  590. # 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
  591. find_package (Wayland)
  592. if(WAYLAND_FOUND)
  593. include_directories (SYSTEM ${WAYLAND_INCLUDE_DIRS})
  594. set(HAVE_VIDEO_WAYLAND TRUE)
  595. set(HAVE_SDL_VIDEO TRUE)
  596. file(GLOB WAYLAND_SOURCES ${SDL2_SOURCE_DIR}/src/video/wayland/*.c)
  597. set(SOURCE_FILES ${SOURCE_FILES} ${WAYLAND_SOURCES})
  598. # We have to generate some protocol interface code for some unstable Wayland features.
  599. file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/wayland-generated-protocols")
  600. include_directories("${CMAKE_CURRENT_BINARY_DIR}/wayland-generated-protocols")
  601. file(GLOB WAYLAND_PROTOCOLS_XML RELATIVE "${SDL2_SOURCE_DIR}/wayland-protocols/" "${SDL2_SOURCE_DIR}/wayland-protocols/*.xml")
  602. foreach(_XML ${WAYLAND_PROTOCOLS_XML})
  603. string(REGEX REPLACE "\\.xml$" "" _PROTL "${_XML}")
  604. WaylandProtocolGen("${WAYLAND_SCANNER}" "${SDL2_SOURCE_DIR}/wayland-protocols/${_XML}" "${_PROTL}")
  605. endforeach()
  606. if(VIDEO_WAYLAND_QT_TOUCH)
  607. set(SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH 1)
  608. endif()
  609. if(WAYLAND_SHARED)
  610. if(NOT HAVE_DLOPEN)
  611. message_warn("You must have SDL_LoadObject() support for dynamic Wayland loading")
  612. else()
  613. get_soname (WAYLAND_CLIENT_LIB_SONAME WAYLAND_CLIENT)
  614. get_soname (WAYLAND_EGL_LIB_SONAME WAYLAND_EGL)
  615. get_soname (WAYLAND_CURSOR_LIB_SONAME WAYLAND_CURSOR)
  616. get_soname (XKBCOMMON_LIB_SONAME XKB)
  617. set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC "\"${WAYLAND_CLIENT_LIB_SONAME}\"")
  618. set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_EGL "\"${WAYLAND_EGL_LIB_SONAME}\"")
  619. set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_CURSOR "\"${WAYLAND_CURSOR_LIB_SONAME}\"")
  620. set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_XKBCOMMON "\"${XKBCOMMON_LIB_SONAME}\"")
  621. set(HAVE_WAYLAND_SHARED TRUE)
  622. endif()
  623. else()
  624. list (APPEND EXTRA_LIBS wayland-client)
  625. endif()
  626. set(SDL_VIDEO_DRIVER_WAYLAND 1)
  627. set(SDL_VIDEO_OPENGL_EGL 1)
  628. endif()
  629. endif()
  630. endmacro()
  631. # Urho3D - commented out CheckCOCOA macro as it does not perform any check at all, moved the code to SDL's CMakeLists.txt
  632. # Requires:
  633. # - n/a
  634. # Optional:
  635. # - DIRECTFB_SHARED opt
  636. # - HAVE_DLOPEN opt
  637. macro(CheckDirectFB)
  638. if(VIDEO_DIRECTFB)
  639. # 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
  640. find_package (DirectFB 1.0.0)
  641. if(DIRECTFB_FOUND)
  642. include_directories (SYSTEM ${DIRECTFB_INCLUDE_DIRS})
  643. set(HAVE_VIDEO_DIRECTFB TRUE)
  644. file(GLOB DIRECTFB_SOURCES ${SDL2_SOURCE_DIR}/src/video/directfb/*.c)
  645. set(SOURCE_FILES ${SOURCE_FILES} ${DIRECTFB_SOURCES})
  646. set(SDL_VIDEO_DRIVER_DIRECTFB 1)
  647. set(SDL_VIDEO_RENDER_DIRECTFB 1)
  648. if(DIRECTFB_SHARED)
  649. if(NOT HAVE_DLOPEN)
  650. message_warn("You must have SDL_LoadObject() support for dynamic DirectFB loading")
  651. else()
  652. get_soname (DIRECTFB_LIB_SONAME DIRECTFB_LIBRARIES)
  653. set(SDL_VIDEO_DRIVER_DIRECTFB_DYNAMIC "\"${DIRECTFB_LIB_SONAME}\"")
  654. set(HAVE_DIRECTFB_SHARED TRUE)
  655. endif()
  656. else()
  657. list(APPEND EXTRA_LIBS directfb)
  658. endif()
  659. set(HAVE_SDL_VIDEO TRUE)
  660. endif()
  661. endif()
  662. endmacro()
  663. # Requires:
  664. # - n/a
  665. macro(CheckVivante)
  666. if(VIDEO_VIVANTE)
  667. # 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
  668. set (CMAKE_REQUIRED_INCLUDES_VIVANTE_SAVED ${CMAKE_REQUIRED_INCLUDES})
  669. if (CMAKE_CROSSCOMPILING AND NOT "${CMAKE_C_FLAGS} ${CMAKE_REQUIRED_FLAGS}" MATCHES --sysroot)
  670. find_path (VIVANTE_INCLUDE_DIRS NAMES gc_vdk.h EGL/eglvivante.h)
  671. if (VIVANTE_INCLUDE_DIRS)
  672. # 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
  673. list (APPEND CMAKE_REQUIRED_INCLUDES ${VIVANTE_INCLUDE_DIRS})
  674. endif ()
  675. endif ()
  676. check_c_source_compiles("
  677. #include <gc_vdk.h>
  678. int main(int argc, char** argv) {}" HAVE_VIDEO_VIVANTE_VDK)
  679. check_c_source_compiles("
  680. #define LINUX
  681. #define EGL_API_FB
  682. #include <EGL/eglvivante.h>
  683. int main(int argc, char** argv) {}" HAVE_VIDEO_VIVANTE_EGL_FB)
  684. if(HAVE_VIDEO_VIVANTE_VDK OR HAVE_VIDEO_VIVANTE_EGL_FB)
  685. set(HAVE_VIDEO_VIVANTE TRUE)
  686. set(HAVE_SDL_VIDEO TRUE)
  687. file(GLOB VIVANTE_SOURCES ${SDL2_SOURCE_DIR}/src/video/vivante/*.c)
  688. set(SOURCE_FILES ${SOURCE_FILES} ${VIVANTE_SOURCES})
  689. set(SDL_VIDEO_DRIVER_VIVANTE 1)
  690. if(HAVE_VIDEO_VIVANTE_VDK)
  691. set(SDL_VIDEO_DRIVER_VIVANTE_VDK 1)
  692. list(APPEND EXTRA_LIBS VDK VIVANTE)
  693. else()
  694. set(SDL_CFLAGS "${SDL_CFLAGS} -DLINUX -DEGL_API_FB")
  695. list(APPEND EXTRA_LIBS EGL)
  696. endif(HAVE_VIDEO_VIVANTE_VDK)
  697. endif(HAVE_VIDEO_VIVANTE_VDK OR HAVE_VIDEO_VIVANTE_EGL_FB)
  698. set (CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES_VIVANTE_SAVED})
  699. endif(VIDEO_VIVANTE)
  700. endmacro(CheckVivante)
  701. # Requires:
  702. # - nada
  703. # Urho3D - rename the macro to be generic OpenGL check and make it also work for OSX platform
  704. macro(CheckOpenGL)
  705. if(VIDEO_OPENGL)
  706. if (APPLE)
  707. check_c_source_compiles ("
  708. #include <OpenGL/OpenGL.h>
  709. #include <OpenGL/CGLRenderers.h>
  710. int main(int argc, char** argv) {}" HAVE_VIDEO_OPENGL)
  711. else ()
  712. check_c_source_compiles("
  713. #include <GL/gl.h>
  714. #include <GL/glx.h>
  715. int main(int argc, char** argv) {}" HAVE_VIDEO_OPENGL)
  716. endif ()
  717. if(HAVE_VIDEO_OPENGL)
  718. set(HAVE_VIDEO_OPENGL TRUE)
  719. set(SDL_VIDEO_OPENGL 1)
  720. if (APPLE)
  721. set (SDL_VIDEO_OPENGL_CGL 1)
  722. else ()
  723. set(SDL_VIDEO_OPENGL_GLX 1)
  724. endif ()
  725. set(SDL_VIDEO_RENDER_OGL 1)
  726. endif()
  727. endif()
  728. endmacro()
  729. # Requires:
  730. # - nada
  731. # Urho3D - rename the macro to be generic OpenGLES check and make it also work for iOS/tvOS platform
  732. macro(CheckOpenGLES)
  733. if(VIDEO_OPENGLES)
  734. check_c_source_compiles("
  735. #define EGL_API_FB
  736. #include <EGL/egl.h>
  737. int main (int argc, char** argv) {}" HAVE_VIDEO_OPENGL_EGL)
  738. if(HAVE_VIDEO_OPENGL_EGL)
  739. set(SDL_VIDEO_OPENGL_EGL 1)
  740. endif()
  741. check_c_source_compiles("
  742. #include <GLES/gl.h>
  743. #include <GLES/glext.h>
  744. int main (int argc, char** argv) {}" HAVE_VIDEO_OPENGLES_V1)
  745. if(HAVE_VIDEO_OPENGLES_V1)
  746. set(HAVE_VIDEO_OPENGLES TRUE)
  747. set(SDL_VIDEO_OPENGL_ES 1)
  748. set(SDL_VIDEO_RENDER_OGL_ES 1)
  749. endif()
  750. check_c_source_compiles("
  751. #include <GLES2/gl2.h>
  752. #include <GLES2/gl2ext.h>
  753. int main (int argc, char** argv) {}" HAVE_VIDEO_OPENGLES_V2)
  754. if(HAVE_VIDEO_OPENGLES_V2)
  755. set(HAVE_VIDEO_OPENGLES TRUE)
  756. set(SDL_VIDEO_OPENGL_ES2 1)
  757. set(SDL_VIDEO_RENDER_OGL_ES2 1)
  758. endif()
  759. endif()
  760. endmacro()
  761. # Requires:
  762. # - nada
  763. # Optional:
  764. # - THREADS opt
  765. macro(CheckPTHREAD)
  766. if(PTHREADS)
  767. # Urho3D - remove hardcoding of pthread-related compiler and linker flags for each platform
  768. 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)
  769. if(CMAKE_CROSSCOMPILING)
  770. check_c_source_compiles("
  771. #include <pthread.h>
  772. int main(int argc, char** argv) {
  773. pthread_attr_t type;
  774. pthread_attr_init(&type);
  775. return 0;
  776. }" HAVE_PTHREADS)
  777. else()
  778. check_c_source_runs("
  779. #include <pthread.h>
  780. int main(int argc, char** argv) {
  781. pthread_attr_t type;
  782. pthread_attr_init(&type);
  783. return 0;
  784. }" HAVE_PTHREADS)
  785. endif()
  786. if(HAVE_PTHREADS)
  787. set(SDL_THREAD_PTHREAD 1)
  788. # Urho3D - we configure to use "-pthread" compiler flags globally and expect the respective compiler toolchain to do the right things automatically
  789. set(SDL_CFLAGS "${SDL_CFLAGS} -pthread")
  790. check_c_source_compiles("
  791. #include <pthread.h>
  792. int main(int argc, char **argv) {
  793. pthread_mutexattr_t attr;
  794. pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
  795. return 0;
  796. }" HAVE_RECURSIVE_MUTEXES)
  797. if(HAVE_RECURSIVE_MUTEXES)
  798. set(SDL_THREAD_PTHREAD_RECURSIVE_MUTEX 1)
  799. else()
  800. check_c_source_compiles("
  801. #include <pthread.h>
  802. int main(int argc, char **argv) {
  803. pthread_mutexattr_t attr;
  804. pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE_NP);
  805. return 0;
  806. }" HAVE_RECURSIVE_MUTEXES_NP)
  807. if(HAVE_RECURSIVE_MUTEXES_NP)
  808. set(SDL_THREAD_PTHREAD_RECURSIVE_MUTEX_NP 1)
  809. endif()
  810. endif()
  811. if(PTHREADS_SEM)
  812. check_c_source_compiles("#include <pthread.h>
  813. #include <semaphore.h>
  814. int main(int argc, char **argv) { return 0; }" HAVE_PTHREADS_SEM)
  815. if(HAVE_PTHREADS_SEM)
  816. check_c_source_compiles("
  817. #include <pthread.h>
  818. #include <semaphore.h>
  819. int main(int argc, char **argv) {
  820. sem_timedwait(NULL, NULL);
  821. return 0;
  822. }" HAVE_SEM_TIMEDWAIT)
  823. endif()
  824. endif()
  825. check_c_source_compiles("
  826. #include <pthread.h>
  827. #include <pthread_np.h>
  828. int main(int argc, char** argv) { return 0; }" HAVE_PTHREAD_NP_H)
  829. check_function_exists(pthread_setname_np HAVE_PTHREAD_SETNAME_NP)
  830. check_function_exists(pthread_set_name_np HAVE_PTHREAD_SET_NAME_NP)
  831. set(SOURCE_FILES ${SOURCE_FILES}
  832. ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_systhread.c
  833. ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_sysmutex.c # Can be faked, if necessary
  834. ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_syscond.c # Can be faked, if necessary
  835. ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_systls.c
  836. )
  837. if(HAVE_PTHREADS_SEM)
  838. set(SOURCE_FILES ${SOURCE_FILES}
  839. ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_syssem.c)
  840. else()
  841. set(SOURCE_FILES ${SOURCE_FILES}
  842. ${SDL2_SOURCE_DIR}/src/thread/generic/SDL_syssem.c)
  843. endif()
  844. set(HAVE_SDL_THREADS TRUE)
  845. endif()
  846. set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
  847. endif()
  848. endmacro()
  849. # Requires
  850. # - nada
  851. # Optional:
  852. # Sets:
  853. # USB_LIBS
  854. # USB_CFLAGS
  855. macro(CheckUSBHID)
  856. # Urho3D - no fix required - all these checks appear to be for BSD only, assume only native build
  857. # Cannot fix them for X-compiling anyway as we/I don't have the necessary means to verify the changes
  858. check_library_exists(usbhid hid_init "" LIBUSBHID)
  859. if(LIBUSBHID)
  860. check_include_file(usbhid.h HAVE_USBHID_H)
  861. if(HAVE_USBHID_H)
  862. set(USB_CFLAGS "-DHAVE_USBHID_H")
  863. endif()
  864. check_include_file(libusbhid.h HAVE_LIBUSBHID_H)
  865. if(HAVE_LIBUSBHID_H)
  866. set(USB_CFLAGS "${USB_CFLAGS} -DHAVE_LIBUSBHID_H")
  867. endif()
  868. set(USB_LIBS ${USB_LIBS} usbhid)
  869. else()
  870. check_include_file(usb.h HAVE_USB_H)
  871. if(HAVE_USB_H)
  872. set(USB_CFLAGS "-DHAVE_USB_H")
  873. endif()
  874. check_include_file(libusb.h HAVE_LIBUSB_H)
  875. if(HAVE_LIBUSB_H)
  876. set(USB_CFLAGS "${USB_CFLAGS} -DHAVE_LIBUSB_H")
  877. endif()
  878. check_library_exists(usb hid_init "" LIBUSB)
  879. if(LIBUSB)
  880. set(USB_LIBS ${USB_LIBS} usb)
  881. endif()
  882. endif()
  883. set(CMAKE_REQUIRED_FLAGS "${USB_CFLAGS} ${ORIG_CMAKE_REQUIRED_FLAGS}")
  884. set(CMAKE_REQUIRED_LIBRARIES "${USB_LIBS}")
  885. check_c_source_compiles("
  886. #include <sys/types.h>
  887. #if defined(HAVE_USB_H)
  888. #include <usb.h>
  889. #endif
  890. #ifdef __DragonFly__
  891. # include <bus/usb/usb.h>
  892. # include <bus/usb/usbhid.h>
  893. #else
  894. # include <dev/usb/usb.h>
  895. # include <dev/usb/usbhid.h>
  896. #endif
  897. #if defined(HAVE_USBHID_H)
  898. #include <usbhid.h>
  899. #elif defined(HAVE_LIBUSB_H)
  900. #include <libusb.h>
  901. #elif defined(HAVE_LIBUSBHID_H)
  902. #include <libusbhid.h>
  903. #endif
  904. int main(int argc, char **argv) {
  905. struct report_desc *repdesc;
  906. struct usb_ctl_report *repbuf;
  907. hid_kind_t hidkind;
  908. return 0;
  909. }" HAVE_USBHID)
  910. if(HAVE_USBHID)
  911. check_c_source_compiles("
  912. #include <sys/types.h>
  913. #if defined(HAVE_USB_H)
  914. #include <usb.h>
  915. #endif
  916. #ifdef __DragonFly__
  917. # include <bus/usb/usb.h>
  918. # include <bus/usb/usbhid.h>
  919. #else
  920. # include <dev/usb/usb.h>
  921. # include <dev/usb/usbhid.h>
  922. #endif
  923. #if defined(HAVE_USBHID_H)
  924. #include <usbhid.h>
  925. #elif defined(HAVE_LIBUSB_H)
  926. #include <libusb.h>
  927. #elif defined(HAVE_LIBUSBHID_H)
  928. #include <libusbhid.h>
  929. #endif
  930. int main(int argc, char** argv) {
  931. struct usb_ctl_report buf;
  932. if (buf.ucr_data) { }
  933. return 0;
  934. }" HAVE_USBHID_UCR_DATA)
  935. if(HAVE_USBHID_UCR_DATA)
  936. set(USB_CFLAGS "${USB_CFLAGS} -DUSBHID_UCR_DATA")
  937. endif()
  938. check_c_source_compiles("
  939. #include <sys/types.h>
  940. #if defined(HAVE_USB_H)
  941. #include <usb.h>
  942. #endif
  943. #ifdef __DragonFly__
  944. #include <bus/usb/usb.h>
  945. #include <bus/usb/usbhid.h>
  946. #else
  947. #include <dev/usb/usb.h>
  948. #include <dev/usb/usbhid.h>
  949. #endif
  950. #if defined(HAVE_USBHID_H)
  951. #include <usbhid.h>
  952. #elif defined(HAVE_LIBUSB_H)
  953. #include <libusb.h>
  954. #elif defined(HAVE_LIBUSBHID_H)
  955. #include <libusbhid.h>
  956. #endif
  957. int main(int argc, char **argv) {
  958. report_desc_t d;
  959. hid_start_parse(d, 1, 1);
  960. return 0;
  961. }" HAVE_USBHID_NEW)
  962. if(HAVE_USBHID_NEW)
  963. set(USB_CFLAGS "${USB_CFLAGS} -DUSBHID_NEW")
  964. endif()
  965. check_c_source_compiles("
  966. #include <machine/joystick.h>
  967. int main(int argc, char** argv) {
  968. struct joystick t;
  969. return 0;
  970. }" HAVE_MACHINE_JOYSTICK)
  971. if(HAVE_MACHINE_JOYSTICK)
  972. set(SDL_JOYSTICK_USBHID_MACHINE_JOYSTICK_H 1)
  973. endif()
  974. set(SDL_JOYSTICK_USBHID 1)
  975. file(GLOB BSD_JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/bsd/*.c)
  976. set(SOURCE_FILES ${SOURCE_FILES} ${BSD_JOYSTICK_SOURCES})
  977. list(APPEND EXTRA_CFLAGS ${USB_CFLAGS})
  978. list(APPEND EXTRA_LIBS ${USB_LIBS})
  979. set(HAVE_SDL_JOYSTICK TRUE)
  980. set(CMAKE_REQUIRED_LIBRARIES)
  981. set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
  982. endif()
  983. endmacro()
  984. # Check for HIDAPI joystick drivers. This is currently a Unix thing, not Windows or macOS!
  985. macro(CheckHIDAPI)
  986. if(HIDAPI)
  987. if(HIDAPI_SKIP_LIBUSB)
  988. set(HAVE_HIDAPI TRUE)
  989. else()
  990. set(HAVE_HIDAPI FALSE)
  991. pkg_check_modules(LIBUSB libusb)
  992. if (LIBUSB_FOUND)
  993. check_include_file(libusb.h HAVE_LIBUSB_H)
  994. if (HAVE_LIBUSB_H)
  995. set(HAVE_HIDAPI TRUE)
  996. endif()
  997. endif()
  998. endif()
  999. if(HAVE_HIDAPI)
  1000. set(SDL_JOYSTICK_HIDAPI 1)
  1001. set(HAVE_SDL_JOYSTICK TRUE)
  1002. file(GLOB HIDAPI_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/hidapi/*.c)
  1003. set(SOURCE_FILES ${SOURCE_FILES} ${HIDAPI_SOURCES})
  1004. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${LIBUSB_CFLAGS} -I${SDL2_SOURCE_DIR}/src/hidapi/hidapi")
  1005. if(NOT HIDAPI_SKIP_LIBUSB)
  1006. set(SOURCE_FILES ${SOURCE_FILES} ${SDL2_SOURCE_DIR}/src/hidapi/libusb/hid.c)
  1007. list(APPEND EXTRA_LIBS ${LIBUSB_LIBS})
  1008. endif()
  1009. endif()
  1010. endif()
  1011. endmacro()
  1012. # Requires:
  1013. # - n/a
  1014. macro(CheckRPI)
  1015. if(VIDEO_RPI)
  1016. # Urho3D - bug fix - commented out CMAKE_REQUIRED_LIBRARIES as it actually causes the detection to fail
  1017. check_c_source_compiles("
  1018. #include <bcm_host.h>
  1019. int main(int argc, char **argv) {}" HAVE_VIDEO_RPI)
  1020. if(SDL_VIDEO AND HAVE_VIDEO_RPI)
  1021. set(HAVE_SDL_VIDEO TRUE)
  1022. set(SDL_VIDEO_DRIVER_RPI 1)
  1023. file(GLOB VIDEO_RPI_SOURCES ${SDL2_SOURCE_DIR}/src/video/raspberry/*.c)
  1024. set(SOURCE_FILES ${SOURCE_FILES} ${VIDEO_RPI_SOURCES})
  1025. list (APPEND EXTRA_LIBS bcm_host)
  1026. endif(SDL_VIDEO AND HAVE_VIDEO_RPI)
  1027. endif(VIDEO_RPI)
  1028. endmacro(CheckRPI)
  1029. # Requires:
  1030. # - EGL
  1031. # - PkgCheckModules
  1032. # Optional:
  1033. # - KMSDRM_SHARED opt
  1034. # - HAVE_DLOPEN opt
  1035. macro(CheckKMSDRM)
  1036. if(VIDEO_KMSDRM)
  1037. # 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
  1038. find_package (DRM)
  1039. find_package (GBM)
  1040. if(DRM_FOUND AND GBM_FOUND)
  1041. include_directories (SYSTEM ${DRM_INCLUDE_DIRS} ${GBM_INCLUDE_DIRS})
  1042. set(HAVE_VIDEO_KMSDRM TRUE)
  1043. set(HAVE_SDL_VIDEO TRUE)
  1044. file(GLOB KMSDRM_SOURCES ${SDL2_SOURCE_DIR}/src/video/kmsdrm/*.c)
  1045. set(SOURCE_FILES ${SOURCE_FILES} ${KMSDRM_SOURCES})
  1046. set(SDL_VIDEO_DRIVER_KMSDRM 1)
  1047. if(KMSDRM_SHARED)
  1048. if(NOT HAVE_DLOPEN)
  1049. message_warn("You must have SDL_LoadObject() support for dynamic KMS/DRM loading")
  1050. else()
  1051. get_soname (DRM_LIB_SONAME DRM_LIBRARIES)
  1052. get_soname (GBM_LIB_SONAME GBM_LIBRARIES)
  1053. set(SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC "\"${DRM_LIB_SONAME}\"")
  1054. set(SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC_GBM "\"${GBM_LIB_SONAME}\"")
  1055. set(HAVE_KMSDRM_SHARED TRUE)
  1056. endif()
  1057. else()
  1058. list (APPEND EXTRA_LIBS drm gbm)
  1059. endif()
  1060. endif()
  1061. endif()
  1062. endmacro()