sdlchecks.cmake 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083
  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 - 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 (${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. # Requires:
  545. # - EGL
  546. # Optional:
  547. # - WAYLAND_SHARED opt
  548. # - HAVE_DLOPEN opt
  549. macro(CheckWayland)
  550. if(VIDEO_WAYLAND)
  551. # 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
  552. find_package (Wayland)
  553. if(WAYLAND_FOUND)
  554. include_directories (${WAYLAND_INCLUDE_DIRS})
  555. set(HAVE_VIDEO_WAYLAND TRUE)
  556. set(HAVE_SDL_VIDEO TRUE)
  557. file(GLOB WAYLAND_SOURCES ${SDL2_SOURCE_DIR}/src/video/wayland/*.c)
  558. set(SOURCE_FILES ${SOURCE_FILES} ${WAYLAND_SOURCES})
  559. if(VIDEO_WAYLAND_QT_TOUCH)
  560. set(SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH 1)
  561. endif()
  562. if(WAYLAND_SHARED)
  563. if(NOT HAVE_DLOPEN)
  564. message_warn("You must have SDL_LoadObject() support for dynamic Wayland loading")
  565. else()
  566. get_soname (WAYLAND_CLIENT_LIB_SONAME WAYLAND_CLIENT)
  567. get_soname (WAYLAND_EGL_LIB_SONAME WAYLAND_EGL)
  568. get_soname (WAYLAND_CURSOR_LIB_SONAME WAYLAND_CURSOR)
  569. get_soname (XKBCOMMON_LIB_SONAME XKB)
  570. set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC "\"${WAYLAND_CLIENT_LIB_SONAME}\"")
  571. set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_EGL "\"${WAYLAND_EGL_LIB_SONAME}\"")
  572. set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_CURSOR "\"${WAYLAND_CURSOR_LIB_SONAME}\"")
  573. set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_XKBCOMMON "\"${XKBCOMMON_LIB_SONAME}\"")
  574. set(HAVE_WAYLAND_SHARED TRUE)
  575. endif()
  576. else()
  577. list (APPEND EXTRA_LIBS wayland-client)
  578. endif()
  579. set(SDL_VIDEO_DRIVER_WAYLAND 1)
  580. set(SDL_VIDEO_OPENGL_EGL 1)
  581. endif()
  582. endif()
  583. endmacro()
  584. # Urho3D - commented out CheckCOCOA macro as it does not perform any check at all, moved the code to SDL's CMakeLists.txt
  585. # Requires:
  586. # - n/a
  587. # Optional:
  588. # - DIRECTFB_SHARED opt
  589. # - HAVE_DLOPEN opt
  590. macro(CheckDirectFB)
  591. if(VIDEO_DIRECTFB)
  592. # 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
  593. find_package (DirectFB 1.0.0)
  594. if(DIRECTFB_FOUND)
  595. include_directories (${DIRECTFB_INCLUDE_DIRS})
  596. set(HAVE_VIDEO_DIRECTFB TRUE)
  597. file(GLOB DIRECTFB_SOURCES ${SDL2_SOURCE_DIR}/src/video/directfb/*.c)
  598. set(SOURCE_FILES ${SOURCE_FILES} ${DIRECTFB_SOURCES})
  599. set(SDL_VIDEO_DRIVER_DIRECTFB 1)
  600. set(SDL_VIDEO_RENDER_DIRECTFB 1)
  601. if(DIRECTFB_SHARED)
  602. if(NOT HAVE_DLOPEN)
  603. message_warn("You must have SDL_LoadObject() support for dynamic DirectFB loading")
  604. else()
  605. get_soname (DIRECTFB_LIB_SONAME DIRECTFB_LIBRARIES)
  606. set(SDL_VIDEO_DRIVER_DIRECTFB_DYNAMIC "\"${DIRECTFB_LIB_SONAME}\"")
  607. set(HAVE_DIRECTFB_SHARED TRUE)
  608. endif()
  609. else()
  610. list(APPEND EXTRA_LIBS directfb)
  611. endif()
  612. set(HAVE_SDL_VIDEO TRUE)
  613. endif()
  614. endif()
  615. endmacro()
  616. # Requires:
  617. # - n/a
  618. macro(CheckVivante)
  619. if(VIDEO_VIVANTE)
  620. # 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
  621. set (CMAKE_REQUIRED_INCLUDES_VIVANTE_SAVED ${CMAKE_REQUIRED_INCLUDES})
  622. if (CMAKE_CROSSCOMPILING AND NOT "${CMAKE_C_FLAGS} ${CMAKE_REQUIRED_FLAGS}" MATCHES sysroot)
  623. find_path (VIVANTE_INCLUDE_DIRS NAMES gc_vdk.h EGL/eglvivante.h)
  624. if (VIVANTE_INCLUDE_DIRS)
  625. # 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
  626. list (APPEND CMAKE_REQUIRED_INCLUDES ${VIVANTE_INCLUDE_DIRS})
  627. endif ()
  628. endif ()
  629. check_c_source_compiles("
  630. #include <gc_vdk.h>
  631. int main(int argc, char** argv) {}" HAVE_VIDEO_VIVANTE_VDK)
  632. check_c_source_compiles("
  633. #define LINUX
  634. #define EGL_API_FB
  635. #include <EGL/eglvivante.h>
  636. int main(int argc, char** argv) {}" HAVE_VIDEO_VIVANTE_EGL_FB)
  637. if(HAVE_VIDEO_VIVANTE_VDK OR HAVE_VIDEO_VIVANTE_EGL_FB)
  638. set(HAVE_VIDEO_VIVANTE TRUE)
  639. set(HAVE_SDL_VIDEO TRUE)
  640. file(GLOB VIVANTE_SOURCES ${SDL2_SOURCE_DIR}/src/video/vivante/*.c)
  641. set(SOURCE_FILES ${SOURCE_FILES} ${VIVANTE_SOURCES})
  642. set(SDL_VIDEO_DRIVER_VIVANTE 1)
  643. if(HAVE_VIDEO_VIVANTE_VDK)
  644. set(SDL_VIDEO_DRIVER_VIVANTE_VDK 1)
  645. list(APPEND EXTRA_LIBS VDK VIVANTE)
  646. else()
  647. set(SDL_CFLAGS "${SDL_CFLAGS} -DLINUX -DEGL_API_FB")
  648. list(APPEND EXTRA_LIBS EGL)
  649. endif(HAVE_VIDEO_VIVANTE_VDK)
  650. endif(HAVE_VIDEO_VIVANTE_VDK OR HAVE_VIDEO_VIVANTE_EGL_FB)
  651. set (CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES_VIVANTE_SAVED})
  652. endif(VIDEO_VIVANTE)
  653. endmacro(CheckVivante)
  654. # Requires:
  655. # - nada
  656. # Urho3D - rename the macro to be generic OpenGL check and make it also work for OSX platform
  657. macro(CheckOpenGL)
  658. if(VIDEO_OPENGL)
  659. # 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
  660. if (CMAKE_CROSSCOMPILING AND SYSROOT AND NOT CMAKE_REQUIRED_INCLUDES)
  661. set (CMAKE_REQUIRED_FLAGS "--sysroot=\"${SYSROOT}\" ${ORIG_CMAKE_REQUIRED_FLAGS}")
  662. endif ()
  663. if (APPLE)
  664. check_c_source_compiles ("
  665. #include <OpenGL/OpenGL.h>
  666. #include <OpenGL/CGLRenderers.h>
  667. int main(int argc, char** argv) {}" HAVE_VIDEO_OPENGL)
  668. else ()
  669. check_c_source_compiles("
  670. #include <GL/gl.h>
  671. #include <GL/glx.h>
  672. int main(int argc, char** argv) {}" HAVE_VIDEO_OPENGL)
  673. endif ()
  674. if(HAVE_VIDEO_OPENGL)
  675. set(HAVE_VIDEO_OPENGL TRUE)
  676. set(SDL_VIDEO_OPENGL 1)
  677. if (APPLE)
  678. set (SDL_VIDEO_OPENGL_CGL 1)
  679. else ()
  680. set(SDL_VIDEO_OPENGL_GLX 1)
  681. endif ()
  682. set(SDL_VIDEO_RENDER_OGL 1)
  683. list(APPEND EXTRA_LIBS GL)
  684. endif()
  685. set (CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
  686. endif()
  687. endmacro()
  688. # Requires:
  689. # - nada
  690. # Urho3D - rename the macro to be generic OpenGLES check and make it also work for iOS platform
  691. macro(CheckOpenGLES)
  692. if(VIDEO_OPENGLES)
  693. # 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
  694. if (CMAKE_CROSSCOMPILING AND SYSROOT AND NOT CMAKE_REQUIRED_INCLUDES)
  695. set (CMAKE_REQUIRED_FLAGS "--sysroot=\"${SYSROOT}\" ${ORIG_CMAKE_REQUIRED_FLAGS}")
  696. endif ()
  697. check_c_source_compiles("
  698. #define EGL_API_FB
  699. #include <EGL/egl.h>
  700. int main (int argc, char** argv) {}" HAVE_VIDEO_OPENGL_EGL)
  701. if(HAVE_VIDEO_OPENGL_EGL)
  702. set(SDL_VIDEO_OPENGL_EGL 1)
  703. endif()
  704. check_c_source_compiles("
  705. #include <GLES/gl.h>
  706. #include <GLES/glext.h>
  707. int main (int argc, char** argv) {}" HAVE_VIDEO_OPENGLES_V1)
  708. if(HAVE_VIDEO_OPENGLES_V1)
  709. set(HAVE_VIDEO_OPENGLES TRUE)
  710. set(SDL_VIDEO_OPENGL_ES 1)
  711. set(SDL_VIDEO_RENDER_OGL_ES 1)
  712. endif()
  713. check_c_source_compiles("
  714. #include <GLES2/gl2.h>
  715. #include <GLES2/gl2ext.h>
  716. int main (int argc, char** argv) {}" HAVE_VIDEO_OPENGLES_V2)
  717. if(HAVE_VIDEO_OPENGLES_V2)
  718. set(HAVE_VIDEO_OPENGLES TRUE)
  719. set(SDL_VIDEO_OPENGL_ES2 1)
  720. set(SDL_VIDEO_RENDER_OGL_ES2 1)
  721. endif()
  722. set (CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
  723. endif()
  724. endmacro()
  725. # Requires:
  726. # - nada
  727. # Optional:
  728. # - THREADS opt
  729. # Sets:
  730. # PTHREAD_CFLAGS
  731. # PTHREAD_LIBS
  732. macro(CheckPTHREAD)
  733. if(PTHREADS)
  734. # 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
  735. if(LINUX)
  736. set(PTHREAD_CFLAGS "-D_REENTRANT")
  737. set(PTHREAD_LDFLAGS "-pthread")
  738. elseif(BSDI)
  739. set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
  740. set(PTHREAD_LDFLAGS "")
  741. elseif(DARWIN)
  742. set(PTHREAD_CFLAGS "-D_THREAD_SAFE")
  743. # causes Carbon.p complaints?
  744. # set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
  745. set(PTHREAD_LDFLAGS "")
  746. elseif(FREEBSD)
  747. set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
  748. set(PTHREAD_LDFLAGS "-pthread")
  749. elseif(NETBSD)
  750. set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
  751. set(PTHREAD_LDFLAGS "-lpthread")
  752. elseif(OPENBSD)
  753. set(PTHREAD_CFLAGS "-D_REENTRANT")
  754. set(PTHREAD_LDFLAGS "-pthread")
  755. elseif(SOLARIS)
  756. set(PTHREAD_CFLAGS "-D_REENTRANT")
  757. set(PTHREAD_LDFLAGS "-pthread -lposix4")
  758. elseif(SYSV5)
  759. set(PTHREAD_CFLAGS "-D_REENTRANT -Kthread")
  760. set(PTHREAD_LDFLAGS "")
  761. elseif(AIX)
  762. set(PTHREAD_CFLAGS "-D_REENTRANT -mthreads")
  763. set(PTHREAD_LDFLAGS "-pthread")
  764. elseif(HPUX)
  765. set(PTHREAD_CFLAGS "-D_REENTRANT")
  766. set(PTHREAD_LDFLAGS "-L/usr/lib -pthread")
  767. elseif(HAIKU)
  768. set(PTHREAD_CFLAGS "-D_REENTRANT")
  769. set(PTHREAD_LDFLAGS "")
  770. elseif(ANDROID)
  771. # ATOMIC: Add android so -lpthread isn't appended to linker
  772. set(PTHREAD_CFLAGS "")
  773. set(PTHREAD_LDFLAGS "")
  774. else()
  775. set(PTHREAD_CFLAGS "-D_REENTRANT")
  776. set(PTHREAD_LDFLAGS "-lpthread")
  777. endif()
  778. # Run some tests
  779. set(CMAKE_REQUIRED_FLAGS "${PTHREAD_CFLAGS} ${PTHREAD_LDFLAGS} ${ORIG_CMAKE_REQUIRED_FLAGS}")
  780. # 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
  781. if(CMAKE_CROSSCOMPILING)
  782. if (SYSROOT AND NOT CMAKE_REQUIRED_INCLUDES)
  783. set (CMAKE_REQUIRED_FLAGS "--sysroot=\"${SYSROOT}\" ${ORIG_CMAKE_REQUIRED_FLAGS}")
  784. endif ()
  785. check_c_source_compiles("
  786. #include <pthread.h>
  787. int main(int argc, char** argv) {
  788. pthread_attr_t type;
  789. pthread_attr_init(&type);
  790. return 0;
  791. }" HAVE_PTHREADS)
  792. else()
  793. check_c_source_runs("
  794. #include <pthread.h>
  795. int main(int argc, char** argv) {
  796. pthread_attr_t type;
  797. pthread_attr_init(&type);
  798. return 0;
  799. }" HAVE_PTHREADS)
  800. endif()
  801. if(HAVE_PTHREADS)
  802. set(SDL_THREAD_PTHREAD 1)
  803. # 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
  804. set(SDL_CFLAGS "${SDL_CFLAGS} ${PTHREAD_CFLAGS}")
  805. list(APPEND SDL_LIBS ${PTHREAD_LDFLAGS})
  806. check_c_source_compiles("
  807. #include <pthread.h>
  808. int main(int argc, char **argv) {
  809. pthread_mutexattr_t attr;
  810. pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
  811. return 0;
  812. }" HAVE_RECURSIVE_MUTEXES)
  813. if(HAVE_RECURSIVE_MUTEXES)
  814. set(SDL_THREAD_PTHREAD_RECURSIVE_MUTEX 1)
  815. else()
  816. check_c_source_compiles("
  817. #include <pthread.h>
  818. int main(int argc, char **argv) {
  819. pthread_mutexattr_t attr;
  820. pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
  821. return 0;
  822. }" HAVE_RECURSIVE_MUTEXES_NP)
  823. if(HAVE_RECURSIVE_MUTEXES_NP)
  824. set(SDL_THREAD_PTHREAD_RECURSIVE_MUTEX_NP 1)
  825. endif()
  826. endif()
  827. if(PTHREADS_SEM)
  828. check_c_source_compiles("#include <pthread.h>
  829. #include <semaphore.h>
  830. int main(int argc, char **argv) { return 0; }" HAVE_PTHREADS_SEM)
  831. if(HAVE_PTHREADS_SEM)
  832. check_c_source_compiles("
  833. #include <pthread.h>
  834. #include <semaphore.h>
  835. int main(int argc, char **argv) {
  836. sem_timedwait(NULL, NULL);
  837. return 0;
  838. }" HAVE_SEM_TIMEDWAIT)
  839. endif()
  840. endif()
  841. check_c_source_compiles("
  842. #include <pthread.h>
  843. #include <pthread_np.h>
  844. int main(int argc, char** argv) { return 0; }" HAVE_PTHREAD_NP_H)
  845. check_function_exists(pthread_setname_np HAVE_PTHREAD_SETNAME_NP)
  846. check_function_exists(pthread_set_name_np HAVE_PTHREAD_SET_NAME_NP)
  847. set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
  848. set(SOURCE_FILES ${SOURCE_FILES}
  849. ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_systhread.c
  850. ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_sysmutex.c # Can be faked, if necessary
  851. ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_syscond.c # Can be faked, if necessary
  852. ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_systls.c
  853. )
  854. if(HAVE_PTHREADS_SEM)
  855. set(SOURCE_FILES ${SOURCE_FILES}
  856. ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_syssem.c)
  857. else()
  858. set(SOURCE_FILES ${SOURCE_FILES}
  859. ${SDL2_SOURCE_DIR}/src/thread/generic/SDL_syssem.c)
  860. endif()
  861. set(HAVE_SDL_THREADS TRUE)
  862. endif()
  863. endif()
  864. endmacro()
  865. # Requires
  866. # - nada
  867. # Optional:
  868. # Sets:
  869. # USB_LIBS
  870. # USB_CFLAGS
  871. macro(CheckUSBHID)
  872. # Urho3D - no fix required - all these checks appear to be for BSD only, assume only native build
  873. # Cannot fix them for X-compiling anyway as we/I don't have the necessary means to verify the changes
  874. check_library_exists(usbhid hid_init "" LIBUSBHID)
  875. if(LIBUSBHID)
  876. check_include_file(usbhid.h HAVE_USBHID_H)
  877. if(HAVE_USBHID_H)
  878. set(USB_CFLAGS "-DHAVE_USBHID_H")
  879. endif()
  880. check_include_file(libusbhid.h HAVE_LIBUSBHID_H)
  881. if(HAVE_LIBUSBHID_H)
  882. set(USB_CFLAGS "${USB_CFLAGS} -DHAVE_LIBUSBHID_H")
  883. endif()
  884. set(USB_LIBS ${USB_LIBS} usbhid)
  885. else()
  886. check_include_file(usb.h HAVE_USB_H)
  887. if(HAVE_USB_H)
  888. set(USB_CFLAGS "-DHAVE_USB_H")
  889. endif()
  890. check_include_file(libusb.h HAVE_LIBUSB_H)
  891. if(HAVE_LIBUSB_H)
  892. set(USB_CFLAGS "${USB_CFLAGS} -DHAVE_LIBUSB_H")
  893. endif()
  894. check_library_exists(usb hid_init "" LIBUSB)
  895. if(LIBUSB)
  896. set(USB_LIBS ${USB_LIBS} usb)
  897. endif()
  898. endif()
  899. set(CMAKE_REQUIRED_FLAGS "${USB_CFLAGS} ${ORIG_CMAKE_REQUIRED_FLAGS}")
  900. set(CMAKE_REQUIRED_LIBRARIES "${USB_LIBS}")
  901. check_c_source_compiles("
  902. #include <sys/types.h>
  903. #if defined(HAVE_USB_H)
  904. #include <usb.h>
  905. #endif
  906. #ifdef __DragonFly__
  907. # include <bus/usb/usb.h>
  908. # include <bus/usb/usbhid.h>
  909. #else
  910. # include <dev/usb/usb.h>
  911. # include <dev/usb/usbhid.h>
  912. #endif
  913. #if defined(HAVE_USBHID_H)
  914. #include <usbhid.h>
  915. #elif defined(HAVE_LIBUSB_H)
  916. #include <libusb.h>
  917. #elif defined(HAVE_LIBUSBHID_H)
  918. #include <libusbhid.h>
  919. #endif
  920. int main(int argc, char **argv) {
  921. struct report_desc *repdesc;
  922. struct usb_ctl_report *repbuf;
  923. hid_kind_t hidkind;
  924. return 0;
  925. }" HAVE_USBHID)
  926. if(HAVE_USBHID)
  927. check_c_source_compiles("
  928. #include <sys/types.h>
  929. #if defined(HAVE_USB_H)
  930. #include <usb.h>
  931. #endif
  932. #ifdef __DragonFly__
  933. # include <bus/usb/usb.h>
  934. # include <bus/usb/usbhid.h>
  935. #else
  936. # include <dev/usb/usb.h>
  937. # include <dev/usb/usbhid.h>
  938. #endif
  939. #if defined(HAVE_USBHID_H)
  940. #include <usbhid.h>
  941. #elif defined(HAVE_LIBUSB_H)
  942. #include <libusb.h>
  943. #elif defined(HAVE_LIBUSBHID_H)
  944. #include <libusbhid.h>
  945. #endif
  946. int main(int argc, char** argv) {
  947. struct usb_ctl_report buf;
  948. if (buf.ucr_data) { }
  949. return 0;
  950. }" HAVE_USBHID_UCR_DATA)
  951. if(HAVE_USBHID_UCR_DATA)
  952. set(USB_CFLAGS "${USB_CFLAGS} -DUSBHID_UCR_DATA")
  953. endif()
  954. check_c_source_compiles("
  955. #include <sys/types.h>
  956. #if defined(HAVE_USB_H)
  957. #include <usb.h>
  958. #endif
  959. #ifdef __DragonFly__
  960. #include <bus/usb/usb.h>
  961. #include <bus/usb/usbhid.h>
  962. #else
  963. #include <dev/usb/usb.h>
  964. #include <dev/usb/usbhid.h>
  965. #endif
  966. #if defined(HAVE_USBHID_H)
  967. #include <usbhid.h>
  968. #elif defined(HAVE_LIBUSB_H)
  969. #include <libusb.h>
  970. #elif defined(HAVE_LIBUSBHID_H)
  971. #include <libusbhid.h>
  972. #endif
  973. int main(int argc, char **argv) {
  974. report_desc_t d;
  975. hid_start_parse(d, 1, 1);
  976. return 0;
  977. }" HAVE_USBHID_NEW)
  978. if(HAVE_USBHID_NEW)
  979. set(USB_CFLAGS "${USB_CFLAGS} -DUSBHID_NEW")
  980. endif()
  981. check_c_source_compiles("
  982. #include <machine/joystick.h>
  983. int main(int argc, char** argv) {
  984. struct joystick t;
  985. return 0;
  986. }" HAVE_MACHINE_JOYSTICK)
  987. if(HAVE_MACHINE_JOYSTICK)
  988. set(SDL_JOYSTICK_USBHID_MACHINE_JOYSTICK_H 1)
  989. endif()
  990. set(SDL_JOYSTICK_USBHID 1)
  991. file(GLOB BSD_JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/bsd/*.c)
  992. set(SOURCE_FILES ${SOURCE_FILES} ${BSD_JOYSTICK_SOURCES})
  993. list(APPEND EXTRA_CFLAGS ${USB_CFLAGS})
  994. list(APPEND EXTRA_LIBS ${USB_LIBS})
  995. set(HAVE_SDL_JOYSTICK TRUE)
  996. set(CMAKE_REQUIRED_LIBRARIES)
  997. set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
  998. endif()
  999. endmacro()
  1000. # Requires:
  1001. # - n/a
  1002. macro(CheckRPI)
  1003. if(VIDEO_RPI)
  1004. # Urho3D - bug fix - when cross-compiling the headers are rooted
  1005. set(CMAKE_REQUIRED_FLAGS "${VIDEO_RPI_INCLUDE_FLAGS} ${ORIG_CMAKE_REQUIRED_FLAGS}")
  1006. # Urho3D - bug fix - commented out CMAKE_REQUIRED_LIBRARIES as it actually causes the detection to fail
  1007. check_c_source_compiles("
  1008. #include <bcm_host.h>
  1009. int main(int argc, char **argv) {}" HAVE_VIDEO_RPI)
  1010. set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
  1011. if(SDL_VIDEO AND HAVE_VIDEO_RPI)
  1012. set(HAVE_SDL_VIDEO TRUE)
  1013. set(SDL_VIDEO_DRIVER_RPI 1)
  1014. file(GLOB VIDEO_RPI_SOURCES ${SDL2_SOURCE_DIR}/src/video/raspberry/*.c)
  1015. set(SOURCE_FILES ${SOURCE_FILES} ${VIDEO_RPI_SOURCES})
  1016. list (APPEND EXTRA_LIBS bcm_host)
  1017. endif(SDL_VIDEO AND HAVE_VIDEO_RPI)
  1018. endif(VIDEO_RPI)
  1019. endmacro(CheckRPI)