sdlchecks.cmake 40 KB

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