sdlchecks.cmake 39 KB

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