sdlchecks.cmake 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069
  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-2016 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 (${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 (${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 (${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. # - ESD_SHARED opt
  192. # - HAVE_DLOPEN opt
  193. macro(CheckESD)
  194. if(ESD)
  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 (Esound)
  197. if(ESOUND_FOUND)
  198. include_directories (${ESOUND_INCLUDE_DIRS})
  199. set(HAVE_ESD TRUE)
  200. file(GLOB ESD_SOURCES ${SDL2_SOURCE_DIR}/src/audio/esd/*.c)
  201. set(SOURCE_FILES ${SOURCE_FILES} ${ESD_SOURCES})
  202. set(SDL_AUDIO_DRIVER_ESD 1)
  203. if(ESD_SHARED)
  204. if(NOT HAVE_DLOPEN)
  205. message_warn("You must have SDL_LoadObject() support for dynamic ESD loading")
  206. else()
  207. get_soname (ESD_LIB_SONAME ESOUND_LIBRARIES)
  208. set(SDL_AUDIO_DRIVER_ESD_DYNAMIC "\"${ESD_LIB_SONAME}\"")
  209. set(HAVE_ESD_SHARED TRUE)
  210. endif()
  211. else()
  212. list (APPEND EXTRA_LIBS esd)
  213. endif()
  214. set(HAVE_SDL_AUDIO TRUE)
  215. endif()
  216. endif()
  217. endmacro()
  218. # Requires:
  219. # - n/a
  220. # Optional:
  221. # - ARTS_SHARED opt
  222. # - HAVE_DLOPEN opt
  223. macro(CheckARTS)
  224. if(ARTS)
  225. # 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
  226. find_package (aRts)
  227. if(ARTS_FOUND)
  228. include_directories (${ARTS_INCLUDE_DIRS})
  229. file(GLOB ARTS_SOURCES ${SDL2_SOURCE_DIR}/src/audio/arts/*.c)
  230. set(SOURCE_FILES ${SOURCE_FILES} ${ARTS_SOURCES})
  231. set(SDL_AUDIO_DRIVER_ARTS 1)
  232. set(HAVE_ARTS TRUE)
  233. if(ARTS_SHARED)
  234. if(NOT HAVE_DLOPEN)
  235. message_warn("You must have SDL_LoadObject() support for dynamic ARTS loading")
  236. else()
  237. get_soname (ARTSC_LIB_SONAME ARTS_LIBRARIES)
  238. set(SDL_AUDIO_DRIVER_ARTS_DYNAMIC "\"${ARTSC_LIB_SONAME}\"")
  239. set(HAVE_ARTS_SHARED TRUE)
  240. endif()
  241. else()
  242. list (APPEND EXTRA_LIBS artsc)
  243. endif()
  244. set(HAVE_SDL_AUDIO TRUE)
  245. endif()
  246. endif()
  247. endmacro()
  248. # Requires:
  249. # - n/a
  250. # Optional:
  251. # - NAS_SHARED opt
  252. # - HAVE_DLOPEN opt
  253. macro(CheckNAS)
  254. if(NAS)
  255. # 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
  256. find_package (NetworkAudioSystem)
  257. if(NAS_FOUND)
  258. include_directories (${NAS_INCLUDE_DIRS})
  259. set(HAVE_NAS TRUE)
  260. file(GLOB NAS_SOURCES ${SDL2_SOURCE_DIR}/src/audio/nas/*.c)
  261. set(SOURCE_FILES ${SOURCE_FILES} ${NAS_SOURCES})
  262. set(SDL_AUDIO_DRIVER_NAS 1)
  263. if(NAS_SHARED)
  264. if(NOT HAVE_DLOPEN)
  265. message_warn("You must have SDL_LoadObject() support for dynamic NAS loading")
  266. else()
  267. get_soname (AUDIO_LIB_SONAME NAS_LIBRARIES)
  268. set(SDL_AUDIO_DRIVER_NAS_DYNAMIC "\"${AUDIO_LIB_SONAME}\"")
  269. set(HAVE_NAS_SHARED TRUE)
  270. endif()
  271. else()
  272. list (APPEND EXTRA_LIBS audio)
  273. endif()
  274. set(HAVE_SDL_AUDIO TRUE)
  275. endif()
  276. endif()
  277. endmacro()
  278. # Requires:
  279. # - n/a
  280. # Optional:
  281. # - SNDIO_SHARED opt
  282. # - HAVE_DLOPEN opt
  283. macro(CheckSNDIO)
  284. if(SNDIO)
  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 (RoarAudio)
  287. if(SNDIO_FOUND)
  288. include_directories (${SNDIO_INCLUDE_DIRS})
  289. set(HAVE_SNDIO TRUE)
  290. file(GLOB SNDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/sndio/*.c)
  291. set(SOURCE_FILES ${SOURCE_FILES} ${SNDIO_SOURCES})
  292. set(SDL_AUDIO_DRIVER_SNDIO 1)
  293. if(SNDIO_SHARED)
  294. if(NOT HAVE_DLOPEN)
  295. message_warn("You must have SDL_LoadObject() support for dynamic sndio loading")
  296. else()
  297. get_soname (SNDIO_LIB_SONAME SNDIO_LIBRARIES)
  298. set(SDL_AUDIO_DRIVER_SNDIO_DYNAMIC "\"${SNDIO_LIB_SONAME}\"")
  299. set(HAVE_SNDIO_SHARED TRUE)
  300. endif()
  301. else()
  302. list(APPEND EXTRA_LIBS sndio)
  303. endif()
  304. set(HAVE_SDL_AUDIO TRUE)
  305. endif()
  306. endif()
  307. endmacro()
  308. # Requires:
  309. # - n/a
  310. # Optional:
  311. # - FUSIONSOUND_SHARED opt
  312. # - HAVE_DLOPEN opt
  313. macro(CheckFusionSound)
  314. if(FUSIONSOUND)
  315. # 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
  316. find_package (FusionSound 1.0.0)
  317. if(FUSIONSOUND_FOUND)
  318. include_directories (${FUSIONSOUND_INCLUDE_DIRS})
  319. set(HAVE_FUSIONSOUND TRUE)
  320. file(GLOB FUSIONSOUND_SOURCES ${SDL2_SOURCE_DIR}/src/audio/fusionsound/*.c)
  321. set(SOURCE_FILES ${SOURCE_FILES} ${FUSIONSOUND_SOURCES})
  322. set(SDL_AUDIO_DRIVER_FUSIONSOUND 1)
  323. if(FUSIONSOUND_SHARED)
  324. if(NOT HAVE_DLOPEN)
  325. message_warn("You must have SDL_LoadObject() support for dynamic FusionSound loading")
  326. else()
  327. get_soname (FUSIONSOUND_LIB_SONAME FUSIONSOUND_LIBRARIES)
  328. set(SDL_AUDIO_DRIVER_FUSIONSOUND_DYNAMIC "\"${FUSIONSOUND_LIB_SONAME}\"")
  329. set(HAVE_FUSIONSOUND_SHARED TRUE)
  330. endif()
  331. else()
  332. list (APPEND EXTRA_LIBS fusionsound)
  333. endif()
  334. set(HAVE_SDL_AUDIO TRUE)
  335. endif()
  336. endif()
  337. endmacro()
  338. # Requires:
  339. # - n/a
  340. # Optional:
  341. # - X11_SHARED opt
  342. # - HAVE_DLOPEN opt
  343. macro(CheckX11)
  344. if(VIDEO_X11)
  345. # Urho3D - no fix required - all these checks below work on native Linux build only, e.g. they would not work on RPI (native or X-compile) which is fortunately a good thing
  346. foreach (NAME X11 Xext Xcursor Xinerama Xi Xrandr Xrender Xss Xxf86vm)
  347. string (TOUPPER ${NAME} UPCASE_NAME)
  348. string (REGEX REPLACE \\..+$ "" UPCASE_NAME "${UPCASE_NAME}") # Stringify for string replacement
  349. find_library (${UPCASE_NAME}_LIB ${NAME})
  350. get_soname (${UPCASE_NAME}_LIB_SONAME ${UPCASE_NAME}_LIB)
  351. endforeach ()
  352. # 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)
  353. check_include_file(X11/Xcursor/Xcursor.h HAVE_XCURSOR_H)
  354. check_include_file(X11/extensions/Xinerama.h HAVE_XINERAMA_H)
  355. check_include_file(X11/extensions/XInput2.h HAVE_XINPUT_H)
  356. check_include_file(X11/extensions/Xrandr.h HAVE_XRANDR_H)
  357. check_include_file(X11/extensions/Xrender.h HAVE_XRENDER_H)
  358. check_include_file(X11/extensions/scrnsaver.h HAVE_XSS_H)
  359. check_include_file(X11/extensions/shape.h HAVE_XSHAPE_H)
  360. check_include_files("X11/Xlib.h;X11/extensions/xf86vmode.h" HAVE_XF86VM_H)
  361. check_include_files("X11/Xlib.h;X11/Xproto.h;X11/extensions/Xext.h" HAVE_XEXT_H)
  362. if(X11_LIB)
  363. if(NOT HAVE_XEXT_H)
  364. message_error("Missing Xext.h, maybe you need to install the libxext-dev package?")
  365. endif()
  366. set(HAVE_VIDEO_X11 TRUE)
  367. set(HAVE_SDL_VIDEO TRUE)
  368. file(GLOB X11_SOURCES ${SDL2_SOURCE_DIR}/src/video/x11/*.c)
  369. set(SOURCE_FILES ${SOURCE_FILES} ${X11_SOURCES})
  370. set(SDL_VIDEO_DRIVER_X11 1)
  371. if(APPLE)
  372. set(X11_SHARED OFF)
  373. endif()
  374. check_function_exists("shmat" HAVE_SHMAT)
  375. if(NOT HAVE_SHMAT)
  376. # Urho3D - bug fix - use different variables for different checks because of CMake caches the result variable
  377. check_library_exists(ipc shmat "" HAVE_SHMAT_IN_IPC)
  378. if(HAVE_SHMAT_IN_IPC)
  379. list(APPEND EXTRA_LIBS ipc)
  380. set (HAVE_SHMAT TRUE)
  381. endif()
  382. if(NOT HAVE_SHMAT)
  383. add_definitions(-DNO_SHARED_MEMORY)
  384. set(X_CFLAGS "${X_CFLAGS} -DNO_SHARED_MEMORY")
  385. endif()
  386. endif()
  387. if(X11_SHARED)
  388. if(NOT HAVE_DLOPEN)
  389. message_warn("You must have SDL_LoadObject() support for dynamic X11 loading")
  390. set(HAVE_X11_SHARED FALSE)
  391. else()
  392. set(HAVE_X11_SHARED TRUE)
  393. endif()
  394. if(HAVE_X11_SHARED)
  395. set(SDL_VIDEO_DRIVER_X11_DYNAMIC "\"${X11_LIB_SONAME}\"")
  396. set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT "\"${XEXT_LIB_SONAME}\"")
  397. else()
  398. # Urho3D - bug fix - the EXTRA_LIBS is list of library names (not the fully-qualified path to the library itself)
  399. list (APPEND EXTRA_LIBS X11 Xext)
  400. endif()
  401. endif()
  402. set(SDL_CFLAGS "${SDL_CFLAGS} ${X_CFLAGS}")
  403. set(CMAKE_REQUIRED_LIBRARIES ${X11_LIB} ${X11_LIB})
  404. check_c_source_compiles("
  405. #include <X11/Xlib.h>
  406. #include <X11/Xproto.h>
  407. #include <X11/extensions/Xext.h>
  408. #include <X11/extensions/extutil.h>
  409. extern XExtDisplayInfo* XextAddDisplay(XExtensionInfo* a,Display* b,_Xconst char* c,XExtensionHooks* d,int e,XPointer f);
  410. int main(int argc, char **argv) {}" HAVE_CONST_XEXT_ADDDISPLAY)
  411. if(HAVE_CONST_XEXT_ADDDISPLAY)
  412. set(SDL_VIDEO_DRIVER_X11_CONST_PARAM_XEXTADDDISPLAY 1)
  413. endif()
  414. check_c_source_compiles("
  415. #include <X11/Xlib.h>
  416. int main(int argc, char **argv) {
  417. Display *display;
  418. XEvent event;
  419. XGenericEventCookie *cookie = &event.xcookie;
  420. XNextEvent(display, &event);
  421. XGetEventData(display, cookie);
  422. XFreeEventData(display, cookie); }" HAVE_XGENERICEVENT)
  423. if(HAVE_XGENERICEVENT)
  424. set(SDL_VIDEO_DRIVER_X11_SUPPORTS_GENERIC_EVENTS 1)
  425. endif()
  426. check_function_exists(XkbKeycodeToKeysym SDL_VIDEO_DRIVER_X11_HAS_XKBKEYCODETOKEYSYM)
  427. if(VIDEO_X11_XCURSOR AND HAVE_XCURSOR_H)
  428. set(HAVE_VIDEO_X11_XCURSOR TRUE)
  429. if(HAVE_X11_SHARED AND XCURSOR_LIB)
  430. set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XCURSOR "\"${XCURSOR_LIB_SONAME}\"")
  431. else()
  432. list (APPEND EXTRA_LIBS Xcursor)
  433. endif()
  434. set(SDL_VIDEO_DRIVER_X11_XCURSOR 1)
  435. endif()
  436. if(VIDEO_X11_XINERAMA AND HAVE_XINERAMA_H)
  437. set(HAVE_VIDEO_X11_XINERAMA TRUE)
  438. if(HAVE_X11_SHARED AND XINERAMA_LIB)
  439. set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XINERAMA "\"${XINERAMA_LIB_SONAME}\"")
  440. else()
  441. list (APPEND EXTRA_LIBS Xinerama)
  442. endif()
  443. set(SDL_VIDEO_DRIVER_X11_XINERAMA 1)
  444. endif()
  445. if(VIDEO_X11_XINPUT AND HAVE_XINPUT_H)
  446. set(HAVE_VIDEO_X11_XINPUT TRUE)
  447. if(HAVE_X11_SHARED AND XI_LIB)
  448. set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT2 "\"${XI_LIB_SONAME}\"")
  449. else()
  450. list (APPEND EXTRA_LIBS Xi)
  451. endif()
  452. set(SDL_VIDEO_DRIVER_X11_XINPUT2 1)
  453. # Check for multitouch
  454. check_c_source_compiles("
  455. #include <X11/Xlib.h>
  456. #include <X11/Xproto.h>
  457. #include <X11/extensions/XInput2.h>
  458. int event_type = XI_TouchBegin;
  459. XITouchClassInfo *t;
  460. Status XIAllowTouchEvents(Display *a,int b,unsigned int c,Window d,int f)
  461. {
  462. return (Status)0;
  463. }
  464. int main(int argc, char **argv) {}" HAVE_XINPUT2_MULTITOUCH)
  465. if(HAVE_XINPUT2_MULTITOUCH)
  466. set(SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH 1)
  467. endif()
  468. endif()
  469. if(VIDEO_X11_XRANDR AND HAVE_XRANDR_H)
  470. if(HAVE_X11_SHARED AND XRANDR_LIB)
  471. set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR "\"${XRANDR_LIB_SONAME}\"")
  472. else()
  473. list (APPEND EXTRA_LIBS Xrandr)
  474. endif()
  475. set(SDL_VIDEO_DRIVER_X11_XRANDR 1)
  476. set(HAVE_VIDEO_X11_XRANDR TRUE)
  477. endif()
  478. if(VIDEO_X11_XSCRNSAVER AND HAVE_XSS_H)
  479. if(HAVE_X11_SHARED AND XSS_LIB)
  480. set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XSS "\"${XSS_LIB_SONAME}\"")
  481. else()
  482. list (APPEND EXTRA_LIBS Xss)
  483. endif()
  484. set(SDL_VIDEO_DRIVER_X11_XSCRNSAVER 1)
  485. set(HAVE_VIDEO_X11_XSCRNSAVER TRUE)
  486. endif()
  487. if(VIDEO_X11_XSHAPE AND HAVE_XSHAPE_H)
  488. set(SDL_VIDEO_DRIVER_X11_XSHAPE 1)
  489. set(HAVE_VIDEO_X11_XSHAPE TRUE)
  490. endif()
  491. if(VIDEO_X11_XVM AND HAVE_XF86VM_H)
  492. if(HAVE_X11_SHARED AND XXF86VM_LIB)
  493. set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XVIDMODE "\"${XXF86VM_LIB_SONAME}\"")
  494. else()
  495. list (APPEND EXTRA_LIBS Xxf86vm)
  496. endif()
  497. set(SDL_VIDEO_DRIVER_X11_XVIDMODE 1)
  498. set(HAVE_VIDEO_X11_XVM TRUE)
  499. endif()
  500. set(CMAKE_REQUIRED_LIBRARIES)
  501. endif()
  502. endif()
  503. endmacro()
  504. # Requires:
  505. # - EGL
  506. # Optional:
  507. # - MIR_SHARED opt
  508. # - HAVE_DLOPEN opt
  509. macro(CheckMir)
  510. if(VIDEO_MIR)
  511. # 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
  512. find_package (Mir)
  513. if (MIR_FOUND)
  514. include_directories (${MIR_INCLUDE_DIRS})
  515. set(HAVE_VIDEO_MIR TRUE)
  516. set(HAVE_SDL_VIDEO TRUE)
  517. file(GLOB MIR_SOURCES ${SDL2_SOURCE_DIR}/src/video/mir/*.c)
  518. set(SOURCE_FILES ${SOURCE_FILES} ${MIR_SOURCES})
  519. set(SDL_VIDEO_DRIVER_MIR 1)
  520. if(MIR_SHARED)
  521. if(NOT HAVE_DLOPEN)
  522. message_warn("You must have SDL_LoadObject() support for dynamic Mir loading")
  523. else()
  524. get_soname (MIRCLIENT_LIB_SONAME MIR_CLIENT)
  525. get_soname (XKBCOMMON_LIB_SONAME XKB)
  526. set(SDL_VIDEO_DRIVER_MIR_DYNAMIC "\"${MIRCLIENT_LIB_SONAME}\"")
  527. set(SDL_VIDEO_DRIVER_MIR_DYNAMIC_XKBCOMMON "\"${XKBCOMMON_LIB_SONAME}\"")
  528. set(HAVE_MIR_SHARED TRUE)
  529. endif()
  530. else()
  531. list (APPEND EXTRA_LIBS mirclient xkbcommon)
  532. endif()
  533. endif()
  534. endif()
  535. endmacro()
  536. # Requires:
  537. # - EGL
  538. # Optional:
  539. # - WAYLAND_SHARED opt
  540. # - HAVE_DLOPEN opt
  541. macro(CheckWayland)
  542. if(VIDEO_WAYLAND)
  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. find_package (Wayland)
  545. if(WAYLAND_FOUND)
  546. include_directories (${WAYLAND_INCLUDE_DIRS})
  547. set(HAVE_VIDEO_WAYLAND TRUE)
  548. set(HAVE_SDL_VIDEO TRUE)
  549. file(GLOB WAYLAND_SOURCES ${SDL2_SOURCE_DIR}/src/video/wayland/*.c)
  550. set(SOURCE_FILES ${SOURCE_FILES} ${WAYLAND_SOURCES})
  551. if(VIDEO_WAYLAND_QT_TOUCH)
  552. set(SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH 1)
  553. endif()
  554. if(WAYLAND_SHARED)
  555. if(NOT HAVE_DLOPEN)
  556. message_warn("You must have SDL_LoadObject() support for dynamic Wayland loading")
  557. else()
  558. get_soname (WAYLAND_CLIENT_LIB_SONAME WAYLAND_CLIENT)
  559. get_soname (WAYLAND_EGL_LIB_SONAME WAYLAND_EGL)
  560. get_soname (WAYLAND_CURSOR_LIB_SONAME WAYLAND_CURSOR)
  561. get_soname (XKBCOMMON_LIB_SONAME XKB)
  562. set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC "\"${WAYLAND_CLIENT_LIB_SONAME}\"")
  563. set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_EGL "\"${WAYLAND_EGL_LIB_SONAME}\"")
  564. set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_CURSOR "\"${WAYLAND_CURSOR_LIB_SONAME}\"")
  565. set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_XKBCOMMON "\"${XKBCOMMON_LIB_SONAME}\"")
  566. set(HAVE_WAYLAND_SHARED TRUE)
  567. endif()
  568. else()
  569. list (APPEND EXTRA_LIBS wayland-client)
  570. endif()
  571. set(SDL_VIDEO_DRIVER_WAYLAND 1)
  572. endif()
  573. endif()
  574. endmacro()
  575. # Urho3D - commented out CheckCOCOA macro as it does not perform any check at all, moved the code to SDL's CMakeLists.txt
  576. # Requires:
  577. # - n/a
  578. # Optional:
  579. # - DIRECTFB_SHARED opt
  580. # - HAVE_DLOPEN opt
  581. macro(CheckDirectFB)
  582. if(VIDEO_DIRECTFB)
  583. # 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
  584. find_package (DirectFB 1.0.0)
  585. if(DIRECTFB_FOUND)
  586. include_directories (${DIRECTFB_INCLUDE_DIRS})
  587. set(HAVE_VIDEO_DIRECTFB TRUE)
  588. file(GLOB DIRECTFB_SOURCES ${SDL2_SOURCE_DIR}/src/video/directfb/*.c)
  589. set(SOURCE_FILES ${SOURCE_FILES} ${DIRECTFB_SOURCES})
  590. set(SDL_VIDEO_DRIVER_DIRECTFB 1)
  591. set(SDL_VIDEO_RENDER_DIRECTFB 1)
  592. if(DIRECTFB_SHARED)
  593. if(NOT HAVE_DLOPEN)
  594. message_warn("You must have SDL_LoadObject() support for dynamic DirectFB loading")
  595. else()
  596. get_soname (DIRECTFB_LIB_SONAME DIRECTFB_LIBRARIES)
  597. set(SDL_VIDEO_DRIVER_DIRECTFB_DYNAMIC "\"${DIRECTFB_LIB_SONAME}\"")
  598. set(HAVE_DIRECTFB_SHARED TRUE)
  599. endif()
  600. else()
  601. list(APPEND EXTRA_LIBS directfb)
  602. endif()
  603. set(HAVE_SDL_VIDEO TRUE)
  604. endif()
  605. endif()
  606. endmacro()
  607. # Requires:
  608. # - n/a
  609. macro(CheckVivante)
  610. if(VIDEO_VIVANTE)
  611. # 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
  612. set (CMAKE_REQUIRED_INCLUDES_VIVANTE_SAVED ${CMAKE_REQUIRED_INCLUDES})
  613. if (CMAKE_CROSSCOMPILING AND NOT "${CMAKE_C_FLAGS} ${CMAKE_REQUIRED_FLAGS}" MATCHES sysroot)
  614. find_path (VIVANTE_INCLUDE_DIRS NAMES gc_vdk.h EGL/eglvivante.h)
  615. if (VIVANTE_INCLUDE_DIRS)
  616. # 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
  617. list (APPEND CMAKE_REQUIRED_INCLUDES ${VIVANTE_INCLUDE_DIRS})
  618. endif ()
  619. endif ()
  620. check_c_source_compiles("
  621. #include <gc_vdk.h>
  622. int main(int argc, char** argv) {}" HAVE_VIDEO_VIVANTE_VDK)
  623. check_c_source_compiles("
  624. #define LINUX
  625. #define EGL_API_FB
  626. #include <EGL/eglvivante.h>
  627. int main(int argc, char** argv) {}" HAVE_VIDEO_VIVANTE_EGL_FB)
  628. if(HAVE_VIDEO_VIVANTE_VDK OR HAVE_VIDEO_VIVANTE_EGL_FB)
  629. set(HAVE_VIDEO_VIVANTE TRUE)
  630. set(HAVE_SDL_VIDEO TRUE)
  631. file(GLOB VIVANTE_SOURCES ${SDL2_SOURCE_DIR}/src/video/vivante/*.c)
  632. set(SOURCE_FILES ${SOURCE_FILES} ${VIVANTE_SOURCES})
  633. set(SDL_VIDEO_DRIVER_VIVANTE 1)
  634. if(HAVE_VIDEO_VIVANTE_VDK)
  635. set(SDL_VIDEO_DRIVER_VIVANTE_VDK 1)
  636. list(APPEND EXTRA_LIBS VDK VIVANTE)
  637. else()
  638. set(SDL_CFLAGS "${SDL_CFLAGS} -DLINUX -DEGL_API_FB")
  639. list(APPEND EXTRA_LIBS EGL)
  640. endif(HAVE_VIDEO_VIVANTE_VDK)
  641. endif(HAVE_VIDEO_VIVANTE_VDK OR HAVE_VIDEO_VIVANTE_EGL_FB)
  642. set (CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES_VIVANTE_SAVED})
  643. endif(VIDEO_VIVANTE)
  644. endmacro(CheckVivante)
  645. # Requires:
  646. # - nada
  647. # Urho3D - rename the macro to be generic OpenGL check and make it also work for OSX platform
  648. macro(CheckOpenGL)
  649. if(VIDEO_OPENGL)
  650. # Urho3D - bug fix - when cross-compiling the headers are rooted, either use "--sysroot" option or use CMAKE_REQUIRED_INCLUDES (e.g. on RPI) to cater for it
  651. if (CMAKE_CROSSCOMPILING AND SYSROOT AND NOT CMAKE_REQUIRED_INCLUDES)
  652. set (CMAKE_REQUIRED_FLAGS "--sysroot=${SYSROOT} ${ORIG_CMAKE_REQUIRED_FLAGS}")
  653. endif ()
  654. if (APPLE)
  655. check_c_source_compiles ("
  656. #include <OpenGL/OpenGL.h>
  657. #include <OpenGL/CGLRenderers.h>
  658. int main(int argc, char** argv) {}" HAVE_VIDEO_OPENGL)
  659. else ()
  660. check_c_source_compiles("
  661. #include <GL/gl.h>
  662. #include <GL/glx.h>
  663. int main(int argc, char** argv) {}" HAVE_VIDEO_OPENGL)
  664. endif ()
  665. if(HAVE_VIDEO_OPENGL)
  666. set(HAVE_VIDEO_OPENGL TRUE)
  667. set(SDL_VIDEO_OPENGL 1)
  668. if (APPLE)
  669. set (SDL_VIDEO_OPENGL_CGL 1)
  670. else ()
  671. set(SDL_VIDEO_OPENGL_GLX 1)
  672. endif ()
  673. set(SDL_VIDEO_RENDER_OGL 1)
  674. list(APPEND EXTRA_LIBS GL)
  675. endif()
  676. set (CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
  677. endif()
  678. endmacro()
  679. # Requires:
  680. # - nada
  681. # Urho3D - rename the macro to be generic OpenGLES check and make it also work for iOS platform
  682. macro(CheckOpenGLES)
  683. if(VIDEO_OPENGLES)
  684. # Urho3D - bug fix - when cross-compiling the headers are rooted, either use "--sysroot" option or use CMAKE_REQUIRED_INCLUDES (e.g. on RPI) to cater for it
  685. if (CMAKE_CROSSCOMPILING AND SYSROOT AND NOT CMAKE_REQUIRED_INCLUDES)
  686. set (CMAKE_REQUIRED_FLAGS "--sysroot=${SYSROOT} ${ORIG_CMAKE_REQUIRED_FLAGS}")
  687. endif ()
  688. check_c_source_compiles("
  689. #define EGL_API_FB
  690. #include <EGL/egl.h>
  691. int main (int argc, char** argv) {}" HAVE_VIDEO_OPENGL_EGL)
  692. if(HAVE_VIDEO_OPENGL_EGL)
  693. set(SDL_VIDEO_OPENGL_EGL 1)
  694. endif()
  695. check_c_source_compiles("
  696. #include <GLES/gl.h>
  697. #include <GLES/glext.h>
  698. int main (int argc, char** argv) {}" HAVE_VIDEO_OPENGLES_V1)
  699. if(HAVE_VIDEO_OPENGLES_V1)
  700. set(HAVE_VIDEO_OPENGLES TRUE)
  701. set(SDL_VIDEO_OPENGL_ES 1)
  702. set(SDL_VIDEO_RENDER_OGL_ES 1)
  703. endif()
  704. check_c_source_compiles("
  705. #include <GLES2/gl2.h>
  706. #include <GLES2/gl2ext.h>
  707. int main (int argc, char** argv) {}" HAVE_VIDEO_OPENGLES_V2)
  708. if(HAVE_VIDEO_OPENGLES_V2)
  709. set(HAVE_VIDEO_OPENGLES TRUE)
  710. set(SDL_VIDEO_OPENGL_ES2 1)
  711. set(SDL_VIDEO_RENDER_OGL_ES2 1)
  712. endif()
  713. set (CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
  714. endif()
  715. endmacro()
  716. # Requires:
  717. # - nada
  718. # Optional:
  719. # - THREADS opt
  720. # Sets:
  721. # PTHREAD_CFLAGS
  722. # PTHREAD_LIBS
  723. macro(CheckPTHREAD)
  724. if(PTHREADS)
  725. # Urho3D - TODO - below hardcoding is ugly and should be refactored/removed, however, we/I don't have all the necessary means to verify the changes
  726. if(LINUX)
  727. set(PTHREAD_CFLAGS "-D_REENTRANT")
  728. set(PTHREAD_LDFLAGS "-pthread")
  729. elseif(BSDI)
  730. set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
  731. set(PTHREAD_LDFLAGS "")
  732. elseif(DARWIN)
  733. set(PTHREAD_CFLAGS "-D_THREAD_SAFE")
  734. # causes Carbon.p complaints?
  735. # set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
  736. set(PTHREAD_LDFLAGS "")
  737. elseif(FREEBSD)
  738. set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
  739. set(PTHREAD_LDFLAGS "-pthread")
  740. elseif(NETBSD)
  741. set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
  742. set(PTHREAD_LDFLAGS "-lpthread")
  743. elseif(OPENBSD)
  744. set(PTHREAD_CFLAGS "-D_REENTRANT")
  745. set(PTHREAD_LDFLAGS "-pthread")
  746. elseif(SOLARIS)
  747. set(PTHREAD_CFLAGS "-D_REENTRANT")
  748. set(PTHREAD_LDFLAGS "-pthread -lposix4")
  749. elseif(SYSV5)
  750. set(PTHREAD_CFLAGS "-D_REENTRANT -Kthread")
  751. set(PTHREAD_LDFLAGS "")
  752. elseif(AIX)
  753. set(PTHREAD_CFLAGS "-D_REENTRANT -mthreads")
  754. set(PTHREAD_LDFLAGS "-pthread")
  755. elseif(HPUX)
  756. set(PTHREAD_CFLAGS "-D_REENTRANT")
  757. set(PTHREAD_LDFLAGS "-L/usr/lib -pthread")
  758. elseif(HAIKU)
  759. set(PTHREAD_CFLAGS "-D_REENTRANT")
  760. set(PTHREAD_LDFLAGS "")
  761. else()
  762. set(PTHREAD_CFLAGS "-D_REENTRANT")
  763. set(PTHREAD_LDFLAGS "-lpthread")
  764. endif()
  765. # Run some tests
  766. set(CMAKE_REQUIRED_FLAGS "${PTHREAD_CFLAGS} ${PTHREAD_LDFLAGS} ${ORIG_CMAKE_REQUIRED_FLAGS}")
  767. # Urho3D - bug fix - when cross-compiling the headers are rooted, either use "--sysroot" option or use CMAKE_REQUIRED_INCLUDES (e.g. on RPI) to cater for it
  768. if(CMAKE_CROSSCOMPILING)
  769. if (SYSROOT AND NOT CMAKE_REQUIRED_INCLUDES)
  770. set (CMAKE_REQUIRED_FLAGS "--sysroot=${SYSROOT} ${ORIG_CMAKE_REQUIRED_FLAGS}")
  771. endif ()
  772. check_c_source_compiles("
  773. #include <pthread.h>
  774. int main(int argc, char** argv) {
  775. pthread_attr_t type;
  776. pthread_attr_init(&type);
  777. return 0;
  778. }" HAVE_PTHREADS)
  779. else()
  780. check_c_source_runs("
  781. #include <pthread.h>
  782. int main(int argc, char** argv) {
  783. pthread_attr_t type;
  784. pthread_attr_init(&type);
  785. return 0;
  786. }" HAVE_PTHREADS)
  787. endif()
  788. if(HAVE_PTHREADS)
  789. set(SDL_THREAD_PTHREAD 1)
  790. # Urho3D - we configure to use "-pthread" compiler flags globally (when it is supported) and expect the respective compiler toolchain to do the right things automatically
  791. set(SDL_CFLAGS "${SDL_CFLAGS} ${PTHREAD_CFLAGS}")
  792. list(APPEND SDL_LIBS ${PTHREAD_LDFLAGS})
  793. check_c_source_compiles("
  794. #include <pthread.h>
  795. int main(int argc, char **argv) {
  796. pthread_mutexattr_t attr;
  797. pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
  798. return 0;
  799. }" HAVE_RECURSIVE_MUTEXES)
  800. if(HAVE_RECURSIVE_MUTEXES)
  801. set(SDL_THREAD_PTHREAD_RECURSIVE_MUTEX 1)
  802. else()
  803. check_c_source_compiles("
  804. #include <pthread.h>
  805. int main(int argc, char **argv) {
  806. pthread_mutexattr_t attr;
  807. pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
  808. return 0;
  809. }" HAVE_RECURSIVE_MUTEXES_NP)
  810. if(HAVE_RECURSIVE_MUTEXES_NP)
  811. set(SDL_THREAD_PTHREAD_RECURSIVE_MUTEX_NP 1)
  812. endif()
  813. endif()
  814. if(PTHREADS_SEM)
  815. check_c_source_compiles("#include <pthread.h>
  816. #include <semaphore.h>
  817. int main(int argc, char **argv) { return 0; }" HAVE_PTHREADS_SEM)
  818. if(HAVE_PTHREADS_SEM)
  819. check_c_source_compiles("
  820. #include <pthread.h>
  821. #include <semaphore.h>
  822. int main(int argc, char **argv) {
  823. sem_timedwait(NULL, NULL);
  824. return 0;
  825. }" HAVE_SEM_TIMEDWAIT)
  826. endif()
  827. endif()
  828. check_c_source_compiles("
  829. #include <pthread.h>
  830. #include <pthread_np.h>
  831. int main(int argc, char** argv) { return 0; }" HAVE_PTHREAD_NP_H)
  832. check_function_exists(pthread_setname_np HAVE_PTHREAD_SETNAME_NP)
  833. check_function_exists(pthread_set_name_np HAVE_PTHREAD_SET_NAME_NP)
  834. set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
  835. set(SOURCE_FILES ${SOURCE_FILES}
  836. ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_systhread.c
  837. ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_sysmutex.c # Can be faked, if necessary
  838. ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_syscond.c # Can be faked, if necessary
  839. ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_systls.c
  840. )
  841. if(HAVE_PTHREADS_SEM)
  842. set(SOURCE_FILES ${SOURCE_FILES}
  843. ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_syssem.c)
  844. else()
  845. set(SOURCE_FILES ${SOURCE_FILES}
  846. ${SDL2_SOURCE_DIR}/src/thread/generic/SDL_syssem.c)
  847. endif()
  848. set(HAVE_SDL_THREADS TRUE)
  849. endif()
  850. endif()
  851. endmacro()
  852. # Requires
  853. # - nada
  854. # Optional:
  855. # Sets:
  856. # USB_LIBS
  857. # USB_CFLAGS
  858. macro(CheckUSBHID)
  859. # Urho3D - no fix required - all these checks appear to be for BSD only, assume only native build
  860. # Cannot fix them for X-compiling anyway as we/I don't have the necessary means to verify the changes
  861. check_library_exists(usbhid hid_init "" LIBUSBHID)
  862. if(LIBUSBHID)
  863. check_include_file(usbhid.h HAVE_USBHID_H)
  864. if(HAVE_USBHID_H)
  865. set(USB_CFLAGS "-DHAVE_USBHID_H")
  866. endif()
  867. check_include_file(libusbhid.h HAVE_LIBUSBHID_H)
  868. if(HAVE_LIBUSBHID_H)
  869. set(USB_CFLAGS "${USB_CFLAGS} -DHAVE_LIBUSBHID_H")
  870. endif()
  871. set(USB_LIBS ${USB_LIBS} usbhid)
  872. else()
  873. check_include_file(usb.h HAVE_USB_H)
  874. if(HAVE_USB_H)
  875. set(USB_CFLAGS "-DHAVE_USB_H")
  876. endif()
  877. check_include_file(libusb.h HAVE_LIBUSB_H)
  878. if(HAVE_LIBUSB_H)
  879. set(USB_CFLAGS "${USB_CFLAGS} -DHAVE_LIBUSB_H")
  880. endif()
  881. check_library_exists(usb hid_init "" LIBUSB)
  882. if(LIBUSB)
  883. set(USB_LIBS ${USB_LIBS} usb)
  884. endif()
  885. endif()
  886. set(CMAKE_REQUIRED_FLAGS "${USB_CFLAGS} ${ORIG_CMAKE_REQUIRED_FLAGS}")
  887. set(CMAKE_REQUIRED_LIBRARIES "${USB_LIBS}")
  888. check_c_source_compiles("
  889. #include <sys/types.h>
  890. #if defined(HAVE_USB_H)
  891. #include <usb.h>
  892. #endif
  893. #ifdef __DragonFly__
  894. # include <bus/usb/usb.h>
  895. # include <bus/usb/usbhid.h>
  896. #else
  897. # include <dev/usb/usb.h>
  898. # include <dev/usb/usbhid.h>
  899. #endif
  900. #if defined(HAVE_USBHID_H)
  901. #include <usbhid.h>
  902. #elif defined(HAVE_LIBUSB_H)
  903. #include <libusb.h>
  904. #elif defined(HAVE_LIBUSBHID_H)
  905. #include <libusbhid.h>
  906. #endif
  907. int main(int argc, char **argv) {
  908. struct report_desc *repdesc;
  909. struct usb_ctl_report *repbuf;
  910. hid_kind_t hidkind;
  911. return 0;
  912. }" HAVE_USBHID)
  913. if(HAVE_USBHID)
  914. check_c_source_compiles("
  915. #include <sys/types.h>
  916. #if defined(HAVE_USB_H)
  917. #include <usb.h>
  918. #endif
  919. #ifdef __DragonFly__
  920. # include <bus/usb/usb.h>
  921. # include <bus/usb/usbhid.h>
  922. #else
  923. # include <dev/usb/usb.h>
  924. # include <dev/usb/usbhid.h>
  925. #endif
  926. #if defined(HAVE_USBHID_H)
  927. #include <usbhid.h>
  928. #elif defined(HAVE_LIBUSB_H)
  929. #include <libusb.h>
  930. #elif defined(HAVE_LIBUSBHID_H)
  931. #include <libusbhid.h>
  932. #endif
  933. int main(int argc, char** argv) {
  934. struct usb_ctl_report buf;
  935. if (buf.ucr_data) { }
  936. return 0;
  937. }" HAVE_USBHID_UCR_DATA)
  938. if(HAVE_USBHID_UCR_DATA)
  939. set(USB_CFLAGS "${USB_CFLAGS} -DUSBHID_UCR_DATA")
  940. endif()
  941. check_c_source_compiles("
  942. #include <sys/types.h>
  943. #if defined(HAVE_USB_H)
  944. #include <usb.h>
  945. #endif
  946. #ifdef __DragonFly__
  947. #include <bus/usb/usb.h>
  948. #include <bus/usb/usbhid.h>
  949. #else
  950. #include <dev/usb/usb.h>
  951. #include <dev/usb/usbhid.h>
  952. #endif
  953. #if defined(HAVE_USBHID_H)
  954. #include <usbhid.h>
  955. #elif defined(HAVE_LIBUSB_H)
  956. #include <libusb.h>
  957. #elif defined(HAVE_LIBUSBHID_H)
  958. #include <libusbhid.h>
  959. #endif
  960. int main(int argc, char **argv) {
  961. report_desc_t d;
  962. hid_start_parse(d, 1, 1);
  963. return 0;
  964. }" HAVE_USBHID_NEW)
  965. if(HAVE_USBHID_NEW)
  966. set(USB_CFLAGS "${USB_CFLAGS} -DUSBHID_NEW")
  967. endif()
  968. check_c_source_compiles("
  969. #include <machine/joystick.h>
  970. int main(int argc, char** argv) {
  971. struct joystick t;
  972. return 0;
  973. }" HAVE_MACHINE_JOYSTICK)
  974. if(HAVE_MACHINE_JOYSTICK)
  975. set(SDL_JOYSTICK_USBHID_MACHINE_JOYSTICK_H 1)
  976. endif()
  977. set(SDL_JOYSTICK_USBHID 1)
  978. file(GLOB BSD_JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/bsd/*.c)
  979. set(SOURCE_FILES ${SOURCE_FILES} ${BSD_JOYSTICK_SOURCES})
  980. list(APPEND EXTRA_CFLAGS ${USB_CFLAGS})
  981. list(APPEND EXTRA_LIBS ${USB_LIBS})
  982. set(HAVE_SDL_JOYSTICK TRUE)
  983. set(CMAKE_REQUIRED_LIBRARIES)
  984. set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
  985. endif()
  986. endmacro()
  987. # Requires:
  988. # - n/a
  989. macro(CheckRPI)
  990. if(VIDEO_RPI)
  991. # Urho3D - bug fix - when cross-compiling the headers are rooted
  992. set(CMAKE_REQUIRED_FLAGS "${VIDEO_RPI_INCLUDE_FLAGS} ${ORIG_CMAKE_REQUIRED_FLAGS}")
  993. # Urho3D - bug fix - commented out CMAKE_REQUIRED_LIBRARIES as it actually causes the detection to fail
  994. check_c_source_compiles("
  995. #include <bcm_host.h>
  996. int main(int argc, char **argv) {}" HAVE_VIDEO_RPI)
  997. set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
  998. if(SDL_VIDEO AND HAVE_VIDEO_RPI)
  999. set(HAVE_SDL_VIDEO TRUE)
  1000. set(SDL_VIDEO_DRIVER_RPI 1)
  1001. file(GLOB VIDEO_RPI_SOURCES ${SDL2_SOURCE_DIR}/src/video/raspberry/*.c)
  1002. set(SOURCE_FILES ${SOURCE_FILES} ${VIDEO_RPI_SOURCES})
  1003. list (APPEND EXTRA_LIBS bcm_host)
  1004. endif(SDL_VIDEO AND HAVE_VIDEO_RPI)
  1005. endif(VIDEO_RPI)
  1006. endmacro(CheckRPI)