sdlchecks.cmake 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047
  1. #
  2. # Simple DirectMedia Layer
  3. # Copyright (C) 1997-2016 Sam Lantinga <[email protected]>
  4. #
  5. # This software is provided 'as-is', without any express or implied
  6. # warranty. In no event will the authors be held liable for any damages
  7. # arising from the use of this software.
  8. #
  9. # Permission is granted to anyone to use this software for any purpose,
  10. # including commercial applications, and to alter it and redistribute it
  11. # freely, subject to the following restrictions:
  12. #
  13. # 1. The origin of this software must not be misrepresented; you must not
  14. # claim that you wrote the original software. If you use this software
  15. # in a product, an acknowledgment in the product documentation would be
  16. # appreciated but is not required.
  17. # 2. Altered source versions must be plainly marked as such, and must not be
  18. # misrepresented as being the original software.
  19. # 3. This notice may not be removed or altered from any source distribution.
  20. #
  21. # Modified by Yao Wei Tjong for Urho3D, the modified portion is licensed under below license
  22. #
  23. # Copyright (c) 2008-2017 the Urho3D project.
  24. #
  25. # Permission is hereby granted, free of charge, to any person obtaining a copy
  26. # of this software and associated documentation files (the "Software"), to deal
  27. # in the Software without restriction, including without limitation the rights
  28. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  29. # copies of the Software, and to permit persons to whom the Software is
  30. # furnished to do so, subject to the following conditions:
  31. #
  32. # The above copyright notice and this permission notice shall be included in
  33. # all copies or substantial portions of the Software.
  34. #
  35. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  36. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  37. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  38. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  39. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  40. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  41. # THE SOFTWARE.
  42. #
  43. # Urho3D - replaced FindLibraryAndSONAME macro with get_soname macro
  44. macro (get_soname SONAME LIB)
  45. if (${LIB})
  46. get_filename_component (REALPATH ${${LIB}} REALPATH)
  47. get_filename_component (BASENAME ${REALPATH} NAME)
  48. if (BASENAME MATCHES \\.so) # Extract soname from basename
  49. string (REGEX REPLACE "(\\.so\\.[^.]+).*$" \\1 ${SONAME} "${BASENAME}") # Stringify for string replacement
  50. else ()
  51. set (${SONAME} ${BASENAME}) # If it is not .so (e.g. .dylib) then use whatever the basename is
  52. endif ()
  53. endif ()
  54. endmacro ()
  55. macro(CheckDLOPEN)
  56. # Urho3D - bug fix - to be consistent with the rest of the check macros here, only do the check when the feature is actually wanted
  57. if (SDL_LOADSO)
  58. # Urho3D - bypass the checks for Emscripten as they don't work but assume it is supported (https://github.com/kripken/emscripten/wiki/Linking#dlopen-dynamic-linking)
  59. if (EMSCRIPTEN)
  60. set (HAVE_DLOPEN TRUE)
  61. else ()
  62. # Urho3D - bug fix - use different variables for different checks because of CMake caches the result variable
  63. 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. # - 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 (SYSTEM ${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 (SYSTEM ${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 (SYSTEM ${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 (SYSTEM ${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 (SYSTEM ${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 - 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
  346. set(CMAKE_REQUIRED_FLAGS "-fPIC -shared ${ORIG_CMAKE_REQUIRED_FLAGS}")
  347. foreach (NAME X11 Xext Xcursor Xinerama Xi Xrandr Xrender Xss Xxf86vm)
  348. string (TOUPPER ${NAME} UPCASE_NAME)
  349. string (REGEX REPLACE \\..+$ "" UPCASE_NAME "${UPCASE_NAME}") # Stringify for string replacement
  350. find_library (${UPCASE_NAME}_LIB ${NAME})
  351. get_soname (${UPCASE_NAME}_LIB_SONAME ${UPCASE_NAME}_LIB)
  352. endforeach ()
  353. # 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)
  354. # Urho3D - add check for Xdbe extension
  355. check_include_file(X11/Xcursor/Xcursor.h HAVE_XCURSOR_H)
  356. check_include_file(X11/extensions/Xinerama.h HAVE_XINERAMA_H)
  357. check_include_file(X11/extensions/XInput2.h HAVE_XINPUT_H)
  358. check_include_file(X11/extensions/Xrandr.h HAVE_XRANDR_H)
  359. check_include_file(X11/extensions/Xrender.h HAVE_XRENDER_H)
  360. check_include_file(X11/extensions/shape.h HAVE_XSHAPE_H)
  361. check_include_file(X11/extensions/scrnsaver.h HAVE_XSS_H)
  362. check_include_files("X11/Xlib.h;X11/Xproto.h;X11/extensions/Xdbe.h" HAVE_XDBE_H)
  363. check_include_files("X11/Xlib.h;X11/Xproto.h;X11/extensions/Xext.h" HAVE_XEXT_H)
  364. check_include_files("X11/Xlib.h;X11/extensions/xf86vmode.h" HAVE_XF86VM_H)
  365. if(X11_LIB)
  366. if(NOT HAVE_XEXT_H)
  367. message_error("Missing Xext.h, maybe you need to install the libxext-dev package?")
  368. endif()
  369. if (HAVE_XDBE_H)
  370. set(SDL_VIDEO_DRIVER_X11_XDBE 1)
  371. endif ()
  372. set(HAVE_VIDEO_X11 TRUE)
  373. set(HAVE_SDL_VIDEO TRUE)
  374. file(GLOB X11_SOURCES ${SDL2_SOURCE_DIR}/src/video/x11/*.c)
  375. set(SOURCE_FILES ${SOURCE_FILES} ${X11_SOURCES})
  376. set(SDL_VIDEO_DRIVER_X11 1)
  377. if(APPLE)
  378. set(X11_SHARED OFF)
  379. endif()
  380. check_function_exists("shmat" HAVE_SHMAT)
  381. if(NOT HAVE_SHMAT)
  382. # Urho3D - bug fix - use different variables for different checks because of CMake caches the result variable
  383. check_library_exists(ipc shmat "" HAVE_SHMAT_IN_IPC)
  384. if(HAVE_SHMAT_IN_IPC)
  385. list(APPEND EXTRA_LIBS ipc)
  386. set (HAVE_SHMAT TRUE)
  387. endif()
  388. if(NOT HAVE_SHMAT)
  389. add_definitions(-DNO_SHARED_MEMORY)
  390. set(X_CFLAGS "${X_CFLAGS} -DNO_SHARED_MEMORY")
  391. endif()
  392. endif()
  393. if(X11_SHARED)
  394. if(NOT HAVE_DLOPEN)
  395. message_warn("You must have SDL_LoadObject() support for dynamic X11 loading")
  396. set(HAVE_X11_SHARED FALSE)
  397. else()
  398. set(HAVE_X11_SHARED TRUE)
  399. endif()
  400. if(HAVE_X11_SHARED)
  401. set(SDL_VIDEO_DRIVER_X11_DYNAMIC "\"${X11_LIB_SONAME}\"")
  402. set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT "\"${XEXT_LIB_SONAME}\"")
  403. else()
  404. # Urho3D - bug fix - the EXTRA_LIBS is list of library names (not the fully-qualified path to the library itself)
  405. list (APPEND EXTRA_LIBS X11 Xext)
  406. endif()
  407. endif()
  408. set(SDL_CFLAGS "${SDL_CFLAGS} ${X_CFLAGS}")
  409. set(CMAKE_REQUIRED_LIBRARIES ${X11_LIB} ${X11_LIB})
  410. check_c_source_compiles("
  411. #include <X11/Xlib.h>
  412. #include <X11/Xproto.h>
  413. #include <X11/extensions/Xext.h>
  414. #include <X11/extensions/extutil.h>
  415. extern XExtDisplayInfo* XextAddDisplay(XExtensionInfo* a,Display* b,_Xconst char* c,XExtensionHooks* d,int e,XPointer f);
  416. int main(int argc, char **argv) {}" HAVE_CONST_XEXT_ADDDISPLAY)
  417. if(HAVE_CONST_XEXT_ADDDISPLAY)
  418. set(SDL_VIDEO_DRIVER_X11_CONST_PARAM_XEXTADDDISPLAY 1)
  419. endif()
  420. check_c_source_compiles("
  421. #include <X11/Xlib.h>
  422. int main(int argc, char **argv) {
  423. Display *display;
  424. XEvent event;
  425. XGenericEventCookie *cookie = &event.xcookie;
  426. XNextEvent(display, &event);
  427. XGetEventData(display, cookie);
  428. XFreeEventData(display, cookie); }" HAVE_XGENERICEVENT)
  429. if(HAVE_XGENERICEVENT)
  430. set(SDL_VIDEO_DRIVER_X11_SUPPORTS_GENERIC_EVENTS 1)
  431. endif()
  432. check_function_exists(XkbKeycodeToKeysym SDL_VIDEO_DRIVER_X11_HAS_XKBKEYCODETOKEYSYM)
  433. if(VIDEO_X11_XCURSOR AND HAVE_XCURSOR_H)
  434. set(HAVE_VIDEO_X11_XCURSOR TRUE)
  435. if(HAVE_X11_SHARED AND XCURSOR_LIB)
  436. set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XCURSOR "\"${XCURSOR_LIB_SONAME}\"")
  437. else()
  438. list (APPEND EXTRA_LIBS Xcursor)
  439. endif()
  440. set(SDL_VIDEO_DRIVER_X11_XCURSOR 1)
  441. endif()
  442. if(VIDEO_X11_XINERAMA AND HAVE_XINERAMA_H)
  443. set(HAVE_VIDEO_X11_XINERAMA TRUE)
  444. if(HAVE_X11_SHARED AND XINERAMA_LIB)
  445. set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XINERAMA "\"${XINERAMA_LIB_SONAME}\"")
  446. else()
  447. list (APPEND EXTRA_LIBS Xinerama)
  448. endif()
  449. set(SDL_VIDEO_DRIVER_X11_XINERAMA 1)
  450. endif()
  451. if(VIDEO_X11_XINPUT AND HAVE_XINPUT_H)
  452. set(HAVE_VIDEO_X11_XINPUT TRUE)
  453. if(HAVE_X11_SHARED AND XI_LIB)
  454. set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT2 "\"${XI_LIB_SONAME}\"")
  455. else()
  456. list (APPEND EXTRA_LIBS Xi)
  457. endif()
  458. set(SDL_VIDEO_DRIVER_X11_XINPUT2 1)
  459. # Check for multitouch
  460. check_c_source_compiles("
  461. #include <X11/Xlib.h>
  462. #include <X11/Xproto.h>
  463. #include <X11/extensions/XInput2.h>
  464. int event_type = XI_TouchBegin;
  465. XITouchClassInfo *t;
  466. Status XIAllowTouchEvents(Display *a,int b,unsigned int c,Window d,int f)
  467. {
  468. return (Status)0;
  469. }
  470. int main(int argc, char **argv) {}" HAVE_XINPUT2_MULTITOUCH)
  471. if(HAVE_XINPUT2_MULTITOUCH)
  472. set(SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH 1)
  473. endif()
  474. endif()
  475. if(VIDEO_X11_XRANDR AND HAVE_XRANDR_H)
  476. if(HAVE_X11_SHARED AND XRANDR_LIB)
  477. set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR "\"${XRANDR_LIB_SONAME}\"")
  478. else()
  479. list (APPEND EXTRA_LIBS Xrandr)
  480. endif()
  481. set(SDL_VIDEO_DRIVER_X11_XRANDR 1)
  482. set(HAVE_VIDEO_X11_XRANDR TRUE)
  483. endif()
  484. if(VIDEO_X11_XSCRNSAVER AND HAVE_XSS_H)
  485. if(HAVE_X11_SHARED AND XSS_LIB)
  486. set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XSS "\"${XSS_LIB_SONAME}\"")
  487. else()
  488. list (APPEND EXTRA_LIBS Xss)
  489. endif()
  490. set(SDL_VIDEO_DRIVER_X11_XSCRNSAVER 1)
  491. set(HAVE_VIDEO_X11_XSCRNSAVER TRUE)
  492. endif()
  493. if(VIDEO_X11_XSHAPE AND HAVE_XSHAPE_H)
  494. set(SDL_VIDEO_DRIVER_X11_XSHAPE 1)
  495. set(HAVE_VIDEO_X11_XSHAPE TRUE)
  496. endif()
  497. if(VIDEO_X11_XVM AND HAVE_XF86VM_H)
  498. if(HAVE_X11_SHARED AND XXF86VM_LIB)
  499. set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XVIDMODE "\"${XXF86VM_LIB_SONAME}\"")
  500. else()
  501. list (APPEND EXTRA_LIBS Xxf86vm)
  502. endif()
  503. set(SDL_VIDEO_DRIVER_X11_XVIDMODE 1)
  504. set(HAVE_VIDEO_X11_XVM TRUE)
  505. endif()
  506. set(CMAKE_REQUIRED_LIBRARIES)
  507. set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
  508. endif()
  509. endif()
  510. endmacro()
  511. # Requires:
  512. # - EGL
  513. # Optional:
  514. # - MIR_SHARED opt
  515. # - HAVE_DLOPEN opt
  516. macro(CheckMir)
  517. if(VIDEO_MIR)
  518. # 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
  519. find_package (Mir)
  520. if (MIR_FOUND)
  521. include_directories (SYSTEM ${MIR_INCLUDE_DIRS})
  522. set(HAVE_VIDEO_MIR TRUE)
  523. set(HAVE_SDL_VIDEO TRUE)
  524. file(GLOB MIR_SOURCES ${SDL2_SOURCE_DIR}/src/video/mir/*.c)
  525. set(SOURCE_FILES ${SOURCE_FILES} ${MIR_SOURCES})
  526. set(SDL_VIDEO_DRIVER_MIR 1)
  527. set(SDL_VIDEO_OPENGL_EGL 1)
  528. if(MIR_SHARED)
  529. if(NOT HAVE_DLOPEN)
  530. message_warn("You must have SDL_LoadObject() support for dynamic Mir loading")
  531. else()
  532. get_soname (MIRCLIENT_LIB_SONAME MIR_CLIENT)
  533. get_soname (XKBCOMMON_LIB_SONAME XKB)
  534. set(SDL_VIDEO_DRIVER_MIR_DYNAMIC "\"${MIRCLIENT_LIB_SONAME}\"")
  535. set(SDL_VIDEO_DRIVER_MIR_DYNAMIC_XKBCOMMON "\"${XKBCOMMON_LIB_SONAME}\"")
  536. set(HAVE_MIR_SHARED TRUE)
  537. endif()
  538. else()
  539. list (APPEND EXTRA_LIBS mirclient xkbcommon)
  540. endif()
  541. endif()
  542. endif()
  543. endmacro()
  544. macro(WaylandProtocolGen _SCANNER _XML _PROTL)
  545. set(_WAYLAND_PROT_C_CODE "${CMAKE_CURRENT_BINARY_DIR}/wayland-generated-protocols/${_PROTL}-protocol.c")
  546. set(_WAYLAND_PROT_H_CODE "${CMAKE_CURRENT_BINARY_DIR}/wayland-generated-protocols/${_PROTL}-client-protocol.h")
  547. add_custom_command(
  548. OUTPUT "${_WAYLAND_PROT_H_CODE}"
  549. DEPENDS "${_XML}"
  550. COMMAND "${_SCANNER}"
  551. ARGS client-header "${_XML}" "${_WAYLAND_PROT_H_CODE}"
  552. )
  553. add_custom_command(
  554. OUTPUT "${_WAYLAND_PROT_C_CODE}"
  555. DEPENDS "${_WAYLAND_PROT_H_CODE}"
  556. COMMAND "${_SCANNER}"
  557. ARGS code "${_XML}" "${_WAYLAND_PROT_C_CODE}"
  558. )
  559. set(SOURCE_FILES ${SOURCE_FILES} "${CMAKE_CURRENT_BINARY_DIR}/wayland-generated-protocols/${_PROTL}-protocol.c")
  560. endmacro()
  561. # Requires:
  562. # - EGL
  563. # Optional:
  564. # - WAYLAND_SHARED opt
  565. # - HAVE_DLOPEN opt
  566. macro(CheckWayland)
  567. if(VIDEO_WAYLAND)
  568. # 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
  569. find_package (Wayland)
  570. if(WAYLAND_FOUND)
  571. include_directories (SYSTEM ${WAYLAND_INCLUDE_DIRS})
  572. set(HAVE_VIDEO_WAYLAND TRUE)
  573. set(HAVE_SDL_VIDEO TRUE)
  574. file(GLOB WAYLAND_SOURCES ${SDL2_SOURCE_DIR}/src/video/wayland/*.c)
  575. set(SOURCE_FILES ${SOURCE_FILES} ${WAYLAND_SOURCES})
  576. # We have to generate some protocol interface code for some unstable Wayland features.
  577. file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/wayland-generated-protocols")
  578. include_directories("${CMAKE_CURRENT_BINARY_DIR}/wayland-generated-protocols")
  579. WaylandProtocolGen("${WAYLAND_SCANNER}" "${WAYLAND_CORE_PROTOCOL_DIR}/wayland.xml" "wayland")
  580. foreach(_PROTL relative-pointer-unstable-v1 pointer-constraints-unstable-v1)
  581. string(REGEX REPLACE "\\-unstable\\-.*$" "" PROTSUBDIR ${_PROTL})
  582. WaylandProtocolGen("${WAYLAND_SCANNER}" "${WAYLAND_PROTOCOLS_DIR}/unstable/${PROTSUBDIR}/${_PROTL}.xml" "${_PROTL}")
  583. endforeach()
  584. if(VIDEO_WAYLAND_QT_TOUCH)
  585. set(SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH 1)
  586. endif()
  587. if(WAYLAND_SHARED)
  588. if(NOT HAVE_DLOPEN)
  589. message_warn("You must have SDL_LoadObject() support for dynamic Wayland loading")
  590. else()
  591. get_soname (WAYLAND_CLIENT_LIB_SONAME WAYLAND_CLIENT)
  592. get_soname (WAYLAND_EGL_LIB_SONAME WAYLAND_EGL)
  593. get_soname (WAYLAND_CURSOR_LIB_SONAME WAYLAND_CURSOR)
  594. get_soname (XKBCOMMON_LIB_SONAME XKB)
  595. set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC "\"${WAYLAND_CLIENT_LIB_SONAME}\"")
  596. set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_EGL "\"${WAYLAND_EGL_LIB_SONAME}\"")
  597. set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_CURSOR "\"${WAYLAND_CURSOR_LIB_SONAME}\"")
  598. set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_XKBCOMMON "\"${XKBCOMMON_LIB_SONAME}\"")
  599. set(HAVE_WAYLAND_SHARED TRUE)
  600. endif()
  601. else()
  602. list (APPEND EXTRA_LIBS wayland-client)
  603. endif()
  604. set(SDL_VIDEO_DRIVER_WAYLAND 1)
  605. set(SDL_VIDEO_OPENGL_EGL 1)
  606. endif()
  607. endif()
  608. endmacro()
  609. # Urho3D - commented out CheckCOCOA macro as it does not perform any check at all, moved the code to SDL's CMakeLists.txt
  610. # Requires:
  611. # - n/a
  612. # Optional:
  613. # - DIRECTFB_SHARED opt
  614. # - HAVE_DLOPEN opt
  615. macro(CheckDirectFB)
  616. if(VIDEO_DIRECTFB)
  617. # 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
  618. find_package (DirectFB 1.0.0)
  619. if(DIRECTFB_FOUND)
  620. include_directories (SYSTEM ${DIRECTFB_INCLUDE_DIRS})
  621. set(HAVE_VIDEO_DIRECTFB TRUE)
  622. file(GLOB DIRECTFB_SOURCES ${SDL2_SOURCE_DIR}/src/video/directfb/*.c)
  623. set(SOURCE_FILES ${SOURCE_FILES} ${DIRECTFB_SOURCES})
  624. set(SDL_VIDEO_DRIVER_DIRECTFB 1)
  625. set(SDL_VIDEO_RENDER_DIRECTFB 1)
  626. if(DIRECTFB_SHARED)
  627. if(NOT HAVE_DLOPEN)
  628. message_warn("You must have SDL_LoadObject() support for dynamic DirectFB loading")
  629. else()
  630. get_soname (DIRECTFB_LIB_SONAME DIRECTFB_LIBRARIES)
  631. set(SDL_VIDEO_DRIVER_DIRECTFB_DYNAMIC "\"${DIRECTFB_LIB_SONAME}\"")
  632. set(HAVE_DIRECTFB_SHARED TRUE)
  633. endif()
  634. else()
  635. list(APPEND EXTRA_LIBS directfb)
  636. endif()
  637. set(HAVE_SDL_VIDEO TRUE)
  638. endif()
  639. endif()
  640. endmacro()
  641. # Requires:
  642. # - n/a
  643. macro(CheckVivante)
  644. if(VIDEO_VIVANTE)
  645. # 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
  646. set (CMAKE_REQUIRED_INCLUDES_VIVANTE_SAVED ${CMAKE_REQUIRED_INCLUDES})
  647. if (CMAKE_CROSSCOMPILING AND NOT "${CMAKE_C_FLAGS} ${CMAKE_REQUIRED_FLAGS}" MATCHES --sysroot)
  648. find_path (VIVANTE_INCLUDE_DIRS NAMES gc_vdk.h EGL/eglvivante.h)
  649. if (VIVANTE_INCLUDE_DIRS)
  650. # 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
  651. list (APPEND CMAKE_REQUIRED_INCLUDES ${VIVANTE_INCLUDE_DIRS})
  652. endif ()
  653. endif ()
  654. check_c_source_compiles("
  655. #include <gc_vdk.h>
  656. int main(int argc, char** argv) {}" HAVE_VIDEO_VIVANTE_VDK)
  657. check_c_source_compiles("
  658. #define LINUX
  659. #define EGL_API_FB
  660. #include <EGL/eglvivante.h>
  661. int main(int argc, char** argv) {}" HAVE_VIDEO_VIVANTE_EGL_FB)
  662. if(HAVE_VIDEO_VIVANTE_VDK OR HAVE_VIDEO_VIVANTE_EGL_FB)
  663. set(HAVE_VIDEO_VIVANTE TRUE)
  664. set(HAVE_SDL_VIDEO TRUE)
  665. file(GLOB VIVANTE_SOURCES ${SDL2_SOURCE_DIR}/src/video/vivante/*.c)
  666. set(SOURCE_FILES ${SOURCE_FILES} ${VIVANTE_SOURCES})
  667. set(SDL_VIDEO_DRIVER_VIVANTE 1)
  668. if(HAVE_VIDEO_VIVANTE_VDK)
  669. set(SDL_VIDEO_DRIVER_VIVANTE_VDK 1)
  670. list(APPEND EXTRA_LIBS VDK VIVANTE)
  671. else()
  672. set(SDL_CFLAGS "${SDL_CFLAGS} -DLINUX -DEGL_API_FB")
  673. list(APPEND EXTRA_LIBS EGL)
  674. endif(HAVE_VIDEO_VIVANTE_VDK)
  675. endif(HAVE_VIDEO_VIVANTE_VDK OR HAVE_VIDEO_VIVANTE_EGL_FB)
  676. set (CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES_VIVANTE_SAVED})
  677. endif(VIDEO_VIVANTE)
  678. endmacro(CheckVivante)
  679. # Requires:
  680. # - nada
  681. # Urho3D - rename the macro to be generic OpenGL check and make it also work for OSX platform
  682. macro(CheckOpenGL)
  683. if(VIDEO_OPENGL)
  684. if (APPLE)
  685. check_c_source_compiles ("
  686. #include <OpenGL/OpenGL.h>
  687. #include <OpenGL/CGLRenderers.h>
  688. int main(int argc, char** argv) {}" HAVE_VIDEO_OPENGL)
  689. else ()
  690. check_c_source_compiles("
  691. #include <GL/gl.h>
  692. #include <GL/glx.h>
  693. int main(int argc, char** argv) {}" HAVE_VIDEO_OPENGL)
  694. endif ()
  695. if(HAVE_VIDEO_OPENGL)
  696. set(HAVE_VIDEO_OPENGL TRUE)
  697. set(SDL_VIDEO_OPENGL 1)
  698. if (APPLE)
  699. set (SDL_VIDEO_OPENGL_CGL 1)
  700. else ()
  701. set(SDL_VIDEO_OPENGL_GLX 1)
  702. endif ()
  703. set(SDL_VIDEO_RENDER_OGL 1)
  704. endif()
  705. endif()
  706. endmacro()
  707. # Requires:
  708. # - nada
  709. # Urho3D - rename the macro to be generic OpenGLES check and make it also work for iOS/tvOS platform
  710. macro(CheckOpenGLES)
  711. if(VIDEO_OPENGLES)
  712. check_c_source_compiles("
  713. #define EGL_API_FB
  714. #include <EGL/egl.h>
  715. int main (int argc, char** argv) {}" HAVE_VIDEO_OPENGL_EGL)
  716. if(HAVE_VIDEO_OPENGL_EGL)
  717. set(SDL_VIDEO_OPENGL_EGL 1)
  718. endif()
  719. check_c_source_compiles("
  720. #include <GLES/gl.h>
  721. #include <GLES/glext.h>
  722. int main (int argc, char** argv) {}" HAVE_VIDEO_OPENGLES_V1)
  723. if(HAVE_VIDEO_OPENGLES_V1)
  724. set(HAVE_VIDEO_OPENGLES TRUE)
  725. set(SDL_VIDEO_OPENGL_ES 1)
  726. set(SDL_VIDEO_RENDER_OGL_ES 1)
  727. endif()
  728. check_c_source_compiles("
  729. #include <GLES2/gl2.h>
  730. #include <GLES2/gl2ext.h>
  731. int main (int argc, char** argv) {}" HAVE_VIDEO_OPENGLES_V2)
  732. if(HAVE_VIDEO_OPENGLES_V2)
  733. set(HAVE_VIDEO_OPENGLES TRUE)
  734. set(SDL_VIDEO_OPENGL_ES2 1)
  735. set(SDL_VIDEO_RENDER_OGL_ES2 1)
  736. endif()
  737. endif()
  738. endmacro()
  739. # Requires:
  740. # - nada
  741. # Optional:
  742. # - THREADS opt
  743. macro(CheckPTHREAD)
  744. if(PTHREADS)
  745. # Urho3D - remove hardcoding of pthread-related compiler and linker flags for each platform
  746. 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)
  747. if(CMAKE_CROSSCOMPILING)
  748. check_c_source_compiles("
  749. #include <pthread.h>
  750. int main(int argc, char** argv) {
  751. pthread_attr_t type;
  752. pthread_attr_init(&type);
  753. return 0;
  754. }" HAVE_PTHREADS)
  755. else()
  756. check_c_source_runs("
  757. #include <pthread.h>
  758. int main(int argc, char** argv) {
  759. pthread_attr_t type;
  760. pthread_attr_init(&type);
  761. return 0;
  762. }" HAVE_PTHREADS)
  763. endif()
  764. if(HAVE_PTHREADS)
  765. set(SDL_THREAD_PTHREAD 1)
  766. # Urho3D - we configure to use "-pthread" compiler flags globally and expect the respective compiler toolchain to do the right things automatically
  767. set(SDL_CFLAGS "${SDL_CFLAGS} -pthread")
  768. check_c_source_compiles("
  769. #include <pthread.h>
  770. int main(int argc, char **argv) {
  771. pthread_mutexattr_t attr;
  772. pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
  773. return 0;
  774. }" HAVE_RECURSIVE_MUTEXES)
  775. if(HAVE_RECURSIVE_MUTEXES)
  776. set(SDL_THREAD_PTHREAD_RECURSIVE_MUTEX 1)
  777. else()
  778. check_c_source_compiles("
  779. #include <pthread.h>
  780. int main(int argc, char **argv) {
  781. pthread_mutexattr_t attr;
  782. pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
  783. return 0;
  784. }" HAVE_RECURSIVE_MUTEXES_NP)
  785. if(HAVE_RECURSIVE_MUTEXES_NP)
  786. set(SDL_THREAD_PTHREAD_RECURSIVE_MUTEX_NP 1)
  787. endif()
  788. endif()
  789. if(PTHREADS_SEM)
  790. check_c_source_compiles("#include <pthread.h>
  791. #include <semaphore.h>
  792. int main(int argc, char **argv) { return 0; }" HAVE_PTHREADS_SEM)
  793. if(HAVE_PTHREADS_SEM)
  794. check_c_source_compiles("
  795. #include <pthread.h>
  796. #include <semaphore.h>
  797. int main(int argc, char **argv) {
  798. sem_timedwait(NULL, NULL);
  799. return 0;
  800. }" HAVE_SEM_TIMEDWAIT)
  801. endif()
  802. endif()
  803. check_c_source_compiles("
  804. #include <pthread.h>
  805. #include <pthread_np.h>
  806. int main(int argc, char** argv) { return 0; }" HAVE_PTHREAD_NP_H)
  807. check_function_exists(pthread_setname_np HAVE_PTHREAD_SETNAME_NP)
  808. check_function_exists(pthread_set_name_np HAVE_PTHREAD_SET_NAME_NP)
  809. set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
  810. set(SOURCE_FILES ${SOURCE_FILES}
  811. ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_systhread.c
  812. ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_sysmutex.c # Can be faked, if necessary
  813. ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_syscond.c # Can be faked, if necessary
  814. ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_systls.c
  815. )
  816. if(HAVE_PTHREADS_SEM)
  817. set(SOURCE_FILES ${SOURCE_FILES}
  818. ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_syssem.c)
  819. else()
  820. set(SOURCE_FILES ${SOURCE_FILES}
  821. ${SDL2_SOURCE_DIR}/src/thread/generic/SDL_syssem.c)
  822. endif()
  823. set(HAVE_SDL_THREADS TRUE)
  824. endif()
  825. endif()
  826. endmacro()
  827. # Requires
  828. # - nada
  829. # Optional:
  830. # Sets:
  831. # USB_LIBS
  832. # USB_CFLAGS
  833. macro(CheckUSBHID)
  834. # Urho3D - no fix required - all these checks appear to be for BSD only, assume only native build
  835. # Cannot fix them for X-compiling anyway as we/I don't have the necessary means to verify the changes
  836. check_library_exists(usbhid hid_init "" LIBUSBHID)
  837. if(LIBUSBHID)
  838. check_include_file(usbhid.h HAVE_USBHID_H)
  839. if(HAVE_USBHID_H)
  840. set(USB_CFLAGS "-DHAVE_USBHID_H")
  841. endif()
  842. check_include_file(libusbhid.h HAVE_LIBUSBHID_H)
  843. if(HAVE_LIBUSBHID_H)
  844. set(USB_CFLAGS "${USB_CFLAGS} -DHAVE_LIBUSBHID_H")
  845. endif()
  846. set(USB_LIBS ${USB_LIBS} usbhid)
  847. else()
  848. check_include_file(usb.h HAVE_USB_H)
  849. if(HAVE_USB_H)
  850. set(USB_CFLAGS "-DHAVE_USB_H")
  851. endif()
  852. check_include_file(libusb.h HAVE_LIBUSB_H)
  853. if(HAVE_LIBUSB_H)
  854. set(USB_CFLAGS "${USB_CFLAGS} -DHAVE_LIBUSB_H")
  855. endif()
  856. check_library_exists(usb hid_init "" LIBUSB)
  857. if(LIBUSB)
  858. set(USB_LIBS ${USB_LIBS} usb)
  859. endif()
  860. endif()
  861. set(CMAKE_REQUIRED_FLAGS "${USB_CFLAGS} ${ORIG_CMAKE_REQUIRED_FLAGS}")
  862. set(CMAKE_REQUIRED_LIBRARIES "${USB_LIBS}")
  863. check_c_source_compiles("
  864. #include <sys/types.h>
  865. #if defined(HAVE_USB_H)
  866. #include <usb.h>
  867. #endif
  868. #ifdef __DragonFly__
  869. # include <bus/usb/usb.h>
  870. # include <bus/usb/usbhid.h>
  871. #else
  872. # include <dev/usb/usb.h>
  873. # include <dev/usb/usbhid.h>
  874. #endif
  875. #if defined(HAVE_USBHID_H)
  876. #include <usbhid.h>
  877. #elif defined(HAVE_LIBUSB_H)
  878. #include <libusb.h>
  879. #elif defined(HAVE_LIBUSBHID_H)
  880. #include <libusbhid.h>
  881. #endif
  882. int main(int argc, char **argv) {
  883. struct report_desc *repdesc;
  884. struct usb_ctl_report *repbuf;
  885. hid_kind_t hidkind;
  886. return 0;
  887. }" HAVE_USBHID)
  888. if(HAVE_USBHID)
  889. check_c_source_compiles("
  890. #include <sys/types.h>
  891. #if defined(HAVE_USB_H)
  892. #include <usb.h>
  893. #endif
  894. #ifdef __DragonFly__
  895. # include <bus/usb/usb.h>
  896. # include <bus/usb/usbhid.h>
  897. #else
  898. # include <dev/usb/usb.h>
  899. # include <dev/usb/usbhid.h>
  900. #endif
  901. #if defined(HAVE_USBHID_H)
  902. #include <usbhid.h>
  903. #elif defined(HAVE_LIBUSB_H)
  904. #include <libusb.h>
  905. #elif defined(HAVE_LIBUSBHID_H)
  906. #include <libusbhid.h>
  907. #endif
  908. int main(int argc, char** argv) {
  909. struct usb_ctl_report buf;
  910. if (buf.ucr_data) { }
  911. return 0;
  912. }" HAVE_USBHID_UCR_DATA)
  913. if(HAVE_USBHID_UCR_DATA)
  914. set(USB_CFLAGS "${USB_CFLAGS} -DUSBHID_UCR_DATA")
  915. endif()
  916. check_c_source_compiles("
  917. #include <sys/types.h>
  918. #if defined(HAVE_USB_H)
  919. #include <usb.h>
  920. #endif
  921. #ifdef __DragonFly__
  922. #include <bus/usb/usb.h>
  923. #include <bus/usb/usbhid.h>
  924. #else
  925. #include <dev/usb/usb.h>
  926. #include <dev/usb/usbhid.h>
  927. #endif
  928. #if defined(HAVE_USBHID_H)
  929. #include <usbhid.h>
  930. #elif defined(HAVE_LIBUSB_H)
  931. #include <libusb.h>
  932. #elif defined(HAVE_LIBUSBHID_H)
  933. #include <libusbhid.h>
  934. #endif
  935. int main(int argc, char **argv) {
  936. report_desc_t d;
  937. hid_start_parse(d, 1, 1);
  938. return 0;
  939. }" HAVE_USBHID_NEW)
  940. if(HAVE_USBHID_NEW)
  941. set(USB_CFLAGS "${USB_CFLAGS} -DUSBHID_NEW")
  942. endif()
  943. check_c_source_compiles("
  944. #include <machine/joystick.h>
  945. int main(int argc, char** argv) {
  946. struct joystick t;
  947. return 0;
  948. }" HAVE_MACHINE_JOYSTICK)
  949. if(HAVE_MACHINE_JOYSTICK)
  950. set(SDL_JOYSTICK_USBHID_MACHINE_JOYSTICK_H 1)
  951. endif()
  952. set(SDL_JOYSTICK_USBHID 1)
  953. file(GLOB BSD_JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/bsd/*.c)
  954. set(SOURCE_FILES ${SOURCE_FILES} ${BSD_JOYSTICK_SOURCES})
  955. list(APPEND EXTRA_CFLAGS ${USB_CFLAGS})
  956. list(APPEND EXTRA_LIBS ${USB_LIBS})
  957. set(HAVE_SDL_JOYSTICK TRUE)
  958. set(CMAKE_REQUIRED_LIBRARIES)
  959. set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
  960. endif()
  961. endmacro()
  962. # Requires:
  963. # - n/a
  964. macro(CheckRPI)
  965. if(VIDEO_RPI)
  966. # Urho3D - bug fix - commented out CMAKE_REQUIRED_LIBRARIES as it actually causes the detection to fail
  967. check_c_source_compiles("
  968. #include <bcm_host.h>
  969. int main(int argc, char **argv) {}" HAVE_VIDEO_RPI)
  970. if(SDL_VIDEO AND HAVE_VIDEO_RPI)
  971. set(HAVE_SDL_VIDEO TRUE)
  972. set(SDL_VIDEO_DRIVER_RPI 1)
  973. file(GLOB VIDEO_RPI_SOURCES ${SDL2_SOURCE_DIR}/src/video/raspberry/*.c)
  974. set(SOURCE_FILES ${SOURCE_FILES} ${VIDEO_RPI_SOURCES})
  975. list (APPEND EXTRA_LIBS bcm_host)
  976. endif(SDL_VIDEO AND HAVE_VIDEO_RPI)
  977. endif(VIDEO_RPI)
  978. endmacro(CheckRPI)