sdlchecks.cmake 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204
  1. macro(FindLibraryAndSONAME _LIB)
  2. string(TOUPPER ${_LIB} _UPPERLNAME)
  3. string(REGEX REPLACE "\\-" "_" _LNAME "${_UPPERLNAME}")
  4. find_library(${_LNAME}_LIB ${_LIB})
  5. if(${_LNAME}_LIB)
  6. # reduce the library name for shared linking
  7. get_filename_component(_LIB_REALPATH ${${_LNAME}_LIB} REALPATH) # resolves symlinks
  8. get_filename_component(_LIB_JUSTNAME ${_LIB_REALPATH} NAME)
  9. if(APPLE)
  10. string(REGEX REPLACE "(\\.[0-9]*)\\.[0-9\\.]*dylib$" "\\1.dylib" _LIB_REGEXD "${_LIB_JUSTNAME}")
  11. else()
  12. string(REGEX REPLACE "(\\.[0-9]*)\\.[0-9\\.]*$" "\\1" _LIB_REGEXD "${_LIB_JUSTNAME}")
  13. endif()
  14. SET(_DEBUG_FindSONAME FALSE)
  15. if(_DEBUG_FindSONAME)
  16. message_warn("DYNLIB OUTPUTVAR: ${_LIB} ... ${_LNAME}_LIB")
  17. message_warn("DYNLIB ORIGINAL LIB: ${_LIB} ... ${${_LNAME}_LIB}")
  18. message_warn("DYNLIB REALPATH LIB: ${_LIB} ... ${_LIB_REALPATH}")
  19. message_warn("DYNLIB JUSTNAME LIB: ${_LIB} ... ${_LIB_JUSTNAME}")
  20. message_warn("DYNLIB REGEX'd LIB: ${_LIB} ... ${_LIB_REGEXD}")
  21. endif()
  22. message(STATUS "dynamic lib${_LIB} -> ${_LIB_REGEXD}")
  23. set(${_LNAME}_LIB_SONAME ${_LIB_REGEXD})
  24. endif()
  25. endmacro()
  26. macro(CheckDLOPEN)
  27. check_function_exists(dlopen HAVE_DLOPEN)
  28. if(NOT HAVE_DLOPEN)
  29. foreach(_LIBNAME dl tdl)
  30. check_library_exists("${_LIBNAME}" "dlopen" "" DLOPEN_LIB)
  31. if(DLOPEN_LIB)
  32. list(APPEND EXTRA_LIBS ${_LIBNAME})
  33. set(_DLLIB ${_LIBNAME})
  34. set(HAVE_DLOPEN TRUE)
  35. break()
  36. endif()
  37. endforeach()
  38. endif()
  39. if(HAVE_DLOPEN)
  40. if(_DLLIB)
  41. set(CMAKE_REQUIRED_LIBRARIES ${_DLLIB})
  42. endif()
  43. check_c_source_compiles("
  44. #include <dlfcn.h>
  45. int main(int argc, char **argv) {
  46. void *handle = dlopen(\"\", RTLD_NOW);
  47. const char *loaderror = (char *) dlerror();
  48. }" HAVE_DLOPEN)
  49. set(CMAKE_REQUIRED_LIBRARIES)
  50. endif()
  51. if (HAVE_DLOPEN)
  52. set(SDL_LOADSO_DLOPEN 1)
  53. set(HAVE_SDL_DLOPEN TRUE)
  54. file(GLOB DLOPEN_SOURCES ${SDL2_SOURCE_DIR}/src/loadso/dlopen/*.c)
  55. set(SOURCE_FILES ${SOURCE_FILES} ${DLOPEN_SOURCES})
  56. set(HAVE_SDL_LOADSO TRUE)
  57. endif()
  58. endmacro()
  59. # Requires:
  60. # - n/a
  61. macro(CheckOSS)
  62. if(OSS)
  63. set(OSS_HEADER_FILE "sys/soundcard.h")
  64. check_c_source_compiles("
  65. #include <sys/soundcard.h>
  66. int main() { int arg = SNDCTL_DSP_SETFRAGMENT; }" OSS_FOUND)
  67. if(NOT OSS_FOUND)
  68. set(OSS_HEADER_FILE "soundcard.h")
  69. check_c_source_compiles("
  70. #include <soundcard.h>
  71. int main() { int arg = SNDCTL_DSP_SETFRAGMENT; }" OSS_FOUND)
  72. endif()
  73. if(OSS_FOUND)
  74. set(HAVE_OSS TRUE)
  75. file(GLOB OSS_SOURCES ${SDL2_SOURCE_DIR}/src/audio/dsp/*.c)
  76. if(OSS_HEADER_FILE STREQUAL "soundcard.h")
  77. set(SDL_AUDIO_DRIVER_OSS_SOUNDCARD_H 1)
  78. endif()
  79. set(SDL_AUDIO_DRIVER_OSS 1)
  80. set(SOURCE_FILES ${SOURCE_FILES} ${OSS_SOURCES})
  81. if(NETBSD OR OPENBSD)
  82. list(APPEND EXTRA_LIBS ossaudio)
  83. endif()
  84. set(HAVE_SDL_AUDIO TRUE)
  85. endif()
  86. endif()
  87. endmacro()
  88. # Requires:
  89. # - n/a
  90. # Optional:
  91. # - ALSA_SHARED opt
  92. # - HAVE_DLOPEN opt
  93. macro(CheckALSA)
  94. if(ALSA)
  95. CHECK_INCLUDE_FILE(alsa/asoundlib.h HAVE_ASOUNDLIB_H)
  96. if(HAVE_ASOUNDLIB_H)
  97. CHECK_LIBRARY_EXISTS(asound snd_pcm_recover "" HAVE_LIBASOUND)
  98. endif()
  99. if(HAVE_LIBASOUND)
  100. set(HAVE_ALSA TRUE)
  101. file(GLOB ALSA_SOURCES ${SDL2_SOURCE_DIR}/src/audio/alsa/*.c)
  102. set(SOURCE_FILES ${SOURCE_FILES} ${ALSA_SOURCES})
  103. set(SDL_AUDIO_DRIVER_ALSA 1)
  104. if(ALSA_SHARED)
  105. if(NOT HAVE_DLOPEN)
  106. message_warn("You must have SDL_LoadObject() support for dynamic ALSA loading")
  107. else()
  108. FindLibraryAndSONAME("asound")
  109. set(SDL_AUDIO_DRIVER_ALSA_DYNAMIC "\"${ASOUND_LIB_SONAME}\"")
  110. set(HAVE_ALSA_SHARED TRUE)
  111. endif()
  112. else()
  113. list(APPEND EXTRA_LIBS asound)
  114. endif()
  115. set(HAVE_SDL_AUDIO TRUE)
  116. endif()
  117. endif()
  118. endmacro()
  119. # Requires:
  120. # - PkgCheckModules
  121. # Optional:
  122. # - PULSEAUDIO_SHARED opt
  123. # - HAVE_DLOPEN opt
  124. macro(CheckPulseAudio)
  125. if(PULSEAUDIO)
  126. pkg_check_modules(PKG_PULSEAUDIO libpulse-simple)
  127. if(PKG_PULSEAUDIO_FOUND)
  128. set(HAVE_PULSEAUDIO TRUE)
  129. file(GLOB PULSEAUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/pulseaudio/*.c)
  130. set(SOURCE_FILES ${SOURCE_FILES} ${PULSEAUDIO_SOURCES})
  131. set(SDL_AUDIO_DRIVER_PULSEAUDIO 1)
  132. list(APPEND EXTRA_CFLAGS ${PKG_PULSEAUDIO_CFLAGS})
  133. if(PULSEAUDIO_SHARED)
  134. if(NOT HAVE_DLOPEN)
  135. message_warn("You must have SDL_LoadObject() support for dynamic PulseAudio loading")
  136. else()
  137. FindLibraryAndSONAME("pulse-simple")
  138. set(SDL_AUDIO_DRIVER_PULSEAUDIO_DYNAMIC "\"${PULSE_SIMPLE_LIB_SONAME}\"")
  139. set(HAVE_PULSEAUDIO_SHARED TRUE)
  140. endif()
  141. else()
  142. list(APPEND EXTRA_LDFLAGS ${PKG_PULSEAUDIO_LDFLAGS})
  143. endif()
  144. set(HAVE_SDL_AUDIO TRUE)
  145. endif()
  146. endif()
  147. endmacro()
  148. # Requires:
  149. # - PkgCheckModules
  150. # Optional:
  151. # - JACK_SHARED opt
  152. # - HAVE_DLOPEN opt
  153. macro(CheckJACK)
  154. if(JACK)
  155. pkg_check_modules(PKG_JACK jack)
  156. if(PKG_JACK_FOUND)
  157. set(HAVE_JACK TRUE)
  158. file(GLOB JACK_SOURCES ${SDL2_SOURCE_DIR}/src/audio/jack/*.c)
  159. set(SOURCE_FILES ${SOURCE_FILES} ${JACK_SOURCES})
  160. set(SDL_AUDIO_DRIVER_JACK 1)
  161. list(APPEND EXTRA_CFLAGS ${PKG_JACK_CFLAGS})
  162. if(JACK_SHARED)
  163. if(NOT HAVE_DLOPEN)
  164. message_warn("You must have SDL_LoadObject() support for dynamic JACK audio loading")
  165. else()
  166. FindLibraryAndSONAME("jack")
  167. set(SDL_AUDIO_DRIVER_JACK_DYNAMIC "\"${JACK_LIB_SONAME}\"")
  168. set(HAVE_JACK_SHARED TRUE)
  169. endif()
  170. else()
  171. list(APPEND EXTRA_LDFLAGS ${PKG_JACK_LDFLAGS})
  172. endif()
  173. set(HAVE_SDL_AUDIO TRUE)
  174. endif()
  175. endif()
  176. endmacro()
  177. # Requires:
  178. # - PkgCheckModules
  179. # Optional:
  180. # - ESD_SHARED opt
  181. # - HAVE_DLOPEN opt
  182. macro(CheckESD)
  183. if(ESD)
  184. pkg_check_modules(PKG_ESD esound)
  185. if(PKG_ESD_FOUND)
  186. set(HAVE_ESD TRUE)
  187. file(GLOB ESD_SOURCES ${SDL2_SOURCE_DIR}/src/audio/esd/*.c)
  188. set(SOURCE_FILES ${SOURCE_FILES} ${ESD_SOURCES})
  189. set(SDL_AUDIO_DRIVER_ESD 1)
  190. list(APPEND EXTRA_CFLAGS ${PKG_ESD_CFLAGS})
  191. if(ESD_SHARED)
  192. if(NOT HAVE_DLOPEN)
  193. message_warn("You must have SDL_LoadObject() support for dynamic ESD loading")
  194. else()
  195. FindLibraryAndSONAME(esd)
  196. set(SDL_AUDIO_DRIVER_ESD_DYNAMIC "\"${ESD_LIB_SONAME}\"")
  197. set(HAVE_ESD_SHARED TRUE)
  198. endif()
  199. else()
  200. list(APPEND EXTRA_LDFLAGS ${PKG_ESD_LDFLAGS})
  201. endif()
  202. set(HAVE_SDL_AUDIO TRUE)
  203. endif()
  204. endif()
  205. endmacro()
  206. # Requires:
  207. # - n/a
  208. # Optional:
  209. # - ARTS_SHARED opt
  210. # - HAVE_DLOPEN opt
  211. macro(CheckARTS)
  212. if(ARTS)
  213. find_program(ARTS_CONFIG arts-config)
  214. if(ARTS_CONFIG)
  215. execute_process(CMD_ARTSCFLAGS ${ARTS_CONFIG} --cflags
  216. OUTPUT_VARIABLE ARTS_CFLAGS OUTPUT_STRIP_TRAILING_WHITESPACE)
  217. list(APPEND EXTRA_CFLAGS ${ARTS_CFLAGS})
  218. execute_process(CMD_ARTSLIBS ${ARTS_CONFIG} --libs
  219. OUTPUT_VARIABLE ARTS_LIBS OUTPUT_STRIP_TRAILING_WHITESPACE)
  220. file(GLOB ARTS_SOURCES ${SDL2_SOURCE_DIR}/src/audio/arts/*.c)
  221. set(SOURCE_FILES ${SOURCE_FILES} ${ARTS_SOURCES})
  222. set(SDL_AUDIO_DRIVER_ARTS 1)
  223. set(HAVE_ARTS TRUE)
  224. if(ARTS_SHARED)
  225. if(NOT HAVE_DLOPEN)
  226. message_warn("You must have SDL_LoadObject() support for dynamic ARTS loading")
  227. else()
  228. # TODO
  229. FindLibraryAndSONAME(artsc)
  230. set(SDL_AUDIO_DRIVER_ARTS_DYNAMIC "\"${ARTSC_LIB_SONAME}\"")
  231. set(HAVE_ARTS_SHARED TRUE)
  232. endif()
  233. else()
  234. list(APPEND EXTRA_LDFLAGS ${ARTS_LIBS})
  235. endif()
  236. set(HAVE_SDL_AUDIO TRUE)
  237. endif()
  238. endif()
  239. endmacro()
  240. # Requires:
  241. # - n/a
  242. # Optional:
  243. # - NAS_SHARED opt
  244. # - HAVE_DLOPEN opt
  245. macro(CheckNAS)
  246. if(NAS)
  247. # TODO: set include paths properly, so the NAS headers are found
  248. check_include_file(audio/audiolib.h HAVE_NAS_H)
  249. find_library(D_NAS_LIB audio)
  250. if(HAVE_NAS_H AND D_NAS_LIB)
  251. set(HAVE_NAS TRUE)
  252. file(GLOB NAS_SOURCES ${SDL2_SOURCE_DIR}/src/audio/nas/*.c)
  253. set(SOURCE_FILES ${SOURCE_FILES} ${NAS_SOURCES})
  254. set(SDL_AUDIO_DRIVER_NAS 1)
  255. if(NAS_SHARED)
  256. if(NOT HAVE_DLOPEN)
  257. message_warn("You must have SDL_LoadObject() support for dynamic NAS loading")
  258. else()
  259. FindLibraryAndSONAME("audio")
  260. set(SDL_AUDIO_DRIVER_NAS_DYNAMIC "\"${AUDIO_LIB_SONAME}\"")
  261. set(HAVE_NAS_SHARED TRUE)
  262. endif()
  263. else()
  264. list(APPEND EXTRA_LIBS ${D_NAS_LIB})
  265. endif()
  266. set(HAVE_SDL_AUDIO TRUE)
  267. endif()
  268. endif()
  269. endmacro()
  270. # Requires:
  271. # - n/a
  272. # Optional:
  273. # - SNDIO_SHARED opt
  274. # - HAVE_DLOPEN opt
  275. macro(CheckSNDIO)
  276. if(SNDIO)
  277. # TODO: set include paths properly, so the sndio headers are found
  278. check_include_file(sndio.h HAVE_SNDIO_H)
  279. find_library(D_SNDIO_LIB sndio)
  280. if(HAVE_SNDIO_H AND D_SNDIO_LIB)
  281. set(HAVE_SNDIO TRUE)
  282. file(GLOB SNDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/sndio/*.c)
  283. set(SOURCE_FILES ${SOURCE_FILES} ${SNDIO_SOURCES})
  284. set(SDL_AUDIO_DRIVER_SNDIO 1)
  285. if(SNDIO_SHARED)
  286. if(NOT HAVE_DLOPEN)
  287. message_warn("You must have SDL_LoadObject() support for dynamic sndio loading")
  288. else()
  289. FindLibraryAndSONAME("sndio")
  290. set(SDL_AUDIO_DRIVER_SNDIO_DYNAMIC "\"${SNDIO_LIB_SONAME}\"")
  291. set(HAVE_SNDIO_SHARED TRUE)
  292. endif()
  293. else()
  294. list(APPEND EXTRA_LIBS ${D_SNDIO_LIB})
  295. endif()
  296. set(HAVE_SDL_AUDIO TRUE)
  297. endif()
  298. endif()
  299. endmacro()
  300. # Requires:
  301. # - PkgCheckModules
  302. # Optional:
  303. # - FUSIONSOUND_SHARED opt
  304. # - HAVE_DLOPEN opt
  305. macro(CheckFusionSound)
  306. if(FUSIONSOUND)
  307. pkg_check_modules(PKG_FUSIONSOUND fusionsound>=1.0.0)
  308. if(PKG_FUSIONSOUND_FOUND)
  309. set(HAVE_FUSIONSOUND TRUE)
  310. file(GLOB FUSIONSOUND_SOURCES ${SDL2_SOURCE_DIR}/src/audio/fusionsound/*.c)
  311. set(SOURCE_FILES ${SOURCE_FILES} ${FUSIONSOUND_SOURCES})
  312. set(SDL_AUDIO_DRIVER_FUSIONSOUND 1)
  313. list(APPEND EXTRA_CFLAGS ${PKG_FUSIONSOUND_CFLAGS})
  314. if(FUSIONSOUND_SHARED)
  315. if(NOT HAVE_DLOPEN)
  316. message_warn("You must have SDL_LoadObject() support for dynamic FusionSound loading")
  317. else()
  318. FindLibraryAndSONAME("fusionsound")
  319. set(SDL_AUDIO_DRIVER_FUSIONSOUND_DYNAMIC "\"${FUSIONSOUND_LIB_SONAME}\"")
  320. set(HAVE_FUSIONSOUND_SHARED TRUE)
  321. endif()
  322. else()
  323. list(APPEND EXTRA_LDFLAGS ${PKG_FUSIONSOUND_LDFLAGS})
  324. endif()
  325. set(HAVE_SDL_AUDIO TRUE)
  326. endif()
  327. endif()
  328. endmacro()
  329. # Requires:
  330. # - LIBSAMPLERATE
  331. # Optional:
  332. # - LIBSAMPLERATE_SHARED opt
  333. # - HAVE_DLOPEN opt
  334. macro(CheckLibSampleRate)
  335. if(LIBSAMPLERATE)
  336. check_include_file(samplerate.h HAVE_LIBSAMPLERATE_H)
  337. if(HAVE_LIBSAMPLERATE_H)
  338. set(HAVE_LIBSAMPLERATE TRUE)
  339. if(LIBSAMPLERATE_SHARED)
  340. if(NOT HAVE_DLOPEN)
  341. message_warn("You must have SDL_LoadObject() support for dynamic libsamplerate loading")
  342. else()
  343. FindLibraryAndSONAME("samplerate")
  344. set(SDL_LIBSAMPLERATE_DYNAMIC "\"${SAMPLERATE_LIB_SONAME}\"")
  345. set(HAVE_LIBSAMPLERATE_SHARED TRUE)
  346. endif()
  347. else()
  348. list(APPEND EXTRA_LDFLAGS -lsamplerate)
  349. endif()
  350. endif()
  351. endif()
  352. endmacro()
  353. # Requires:
  354. # - n/a
  355. # Optional:
  356. # - X11_SHARED opt
  357. # - HAVE_DLOPEN opt
  358. macro(CheckX11)
  359. if(VIDEO_X11)
  360. foreach(_LIB X11 Xext Xcursor Xinerama Xi Xrandr Xrender Xss Xxf86vm)
  361. FindLibraryAndSONAME("${_LIB}")
  362. endforeach()
  363. find_path(X_INCLUDEDIR X11/Xlib.h)
  364. if(X_INCLUDEDIR)
  365. set(X_CFLAGS "-I${X_INCLUDEDIR}")
  366. endif()
  367. check_include_file(X11/Xcursor/Xcursor.h HAVE_XCURSOR_H)
  368. check_include_file(X11/extensions/Xinerama.h HAVE_XINERAMA_H)
  369. check_include_file(X11/extensions/XInput2.h HAVE_XINPUT_H)
  370. check_include_file(X11/extensions/Xrandr.h HAVE_XRANDR_H)
  371. check_include_file(X11/extensions/Xrender.h HAVE_XRENDER_H)
  372. check_include_file(X11/extensions/scrnsaver.h HAVE_XSS_H)
  373. check_include_file(X11/extensions/shape.h HAVE_XSHAPE_H)
  374. check_include_files("X11/Xlib.h;X11/extensions/xf86vmode.h" HAVE_XF86VM_H)
  375. check_include_files("X11/Xlib.h;X11/Xproto.h;X11/extensions/Xext.h" HAVE_XEXT_H)
  376. if(X11_LIB)
  377. if(NOT HAVE_XEXT_H)
  378. message_error("Missing Xext.h, maybe you need to install the libxext-dev package?")
  379. endif()
  380. set(HAVE_VIDEO_X11 TRUE)
  381. set(HAVE_SDL_VIDEO TRUE)
  382. file(GLOB X11_SOURCES ${SDL2_SOURCE_DIR}/src/video/x11/*.c)
  383. set(SOURCE_FILES ${SOURCE_FILES} ${X11_SOURCES})
  384. set(SDL_VIDEO_DRIVER_X11 1)
  385. if(APPLE)
  386. set(X11_SHARED OFF)
  387. endif()
  388. check_function_exists("shmat" HAVE_SHMAT)
  389. if(NOT HAVE_SHMAT)
  390. check_library_exists(ipc shmat "" HAVE_SHMAT)
  391. if(HAVE_SHMAT)
  392. list(APPEND EXTRA_LIBS ipc)
  393. endif()
  394. if(NOT HAVE_SHMAT)
  395. add_definitions(-DNO_SHARED_MEMORY)
  396. set(X_CFLAGS "${X_CFLAGS} -DNO_SHARED_MEMORY")
  397. endif()
  398. endif()
  399. if(X11_SHARED)
  400. if(NOT HAVE_DLOPEN)
  401. message_warn("You must have SDL_LoadObject() support for dynamic X11 loading")
  402. set(HAVE_X11_SHARED FALSE)
  403. else()
  404. set(HAVE_X11_SHARED TRUE)
  405. endif()
  406. if(HAVE_X11_SHARED)
  407. set(SDL_VIDEO_DRIVER_X11_DYNAMIC "\"${X11_LIB_SONAME}\"")
  408. set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT "\"${XEXT_LIB_SONAME}\"")
  409. else()
  410. list(APPEND EXTRA_LIBS ${X11_LIB} ${XEXT_LIB})
  411. endif()
  412. endif()
  413. set(SDL_CFLAGS "${SDL_CFLAGS} ${X_CFLAGS}")
  414. set(CMAKE_REQUIRED_LIBRARIES ${X11_LIB} ${X11_LIB})
  415. check_c_source_compiles("
  416. #include <X11/Xlib.h>
  417. #include <X11/Xproto.h>
  418. #include <X11/extensions/Xext.h>
  419. #include <X11/extensions/extutil.h>
  420. extern XExtDisplayInfo* XextAddDisplay(XExtensionInfo* a,Display* b,_Xconst char* c,XExtensionHooks* d,int e,XPointer f);
  421. int main(int argc, char **argv) {}" HAVE_CONST_XEXT_ADDDISPLAY)
  422. if(HAVE_CONST_XEXT_ADDDISPLAY)
  423. set(SDL_VIDEO_DRIVER_X11_CONST_PARAM_XEXTADDDISPLAY 1)
  424. endif()
  425. check_c_source_compiles("
  426. #include <X11/Xlib.h>
  427. int main(int argc, char **argv) {
  428. Display *display;
  429. XEvent event;
  430. XGenericEventCookie *cookie = &event.xcookie;
  431. XNextEvent(display, &event);
  432. XGetEventData(display, cookie);
  433. XFreeEventData(display, cookie); }" HAVE_XGENERICEVENT)
  434. if(HAVE_XGENERICEVENT)
  435. set(SDL_VIDEO_DRIVER_X11_SUPPORTS_GENERIC_EVENTS 1)
  436. endif()
  437. check_function_exists(XkbKeycodeToKeysym SDL_VIDEO_DRIVER_X11_HAS_XKBKEYCODETOKEYSYM)
  438. if(VIDEO_X11_XCURSOR AND HAVE_XCURSOR_H)
  439. set(HAVE_VIDEO_X11_XCURSOR TRUE)
  440. if(HAVE_X11_SHARED AND XCURSOR_LIB)
  441. set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XCURSOR "\"${XCURSOR_LIB_SONAME}\"")
  442. else()
  443. list(APPEND EXTRA_LIBS ${XCURSOR_LIB})
  444. endif()
  445. set(SDL_VIDEO_DRIVER_X11_XCURSOR 1)
  446. endif()
  447. if(VIDEO_X11_XINERAMA AND HAVE_XINERAMA_H)
  448. set(HAVE_VIDEO_X11_XINERAMA TRUE)
  449. if(HAVE_X11_SHARED AND XINERAMA_LIB)
  450. set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XINERAMA "\"${XINERAMA_LIB_SONAME}\"")
  451. else()
  452. list(APPEND EXTRA_LIBS ${XINERAMA_LIB})
  453. endif()
  454. set(SDL_VIDEO_DRIVER_X11_XINERAMA 1)
  455. endif()
  456. if(VIDEO_X11_XINPUT AND HAVE_XINPUT_H)
  457. set(HAVE_VIDEO_X11_XINPUT TRUE)
  458. if(HAVE_X11_SHARED AND XI_LIB)
  459. set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT2 "\"${XI_LIB_SONAME}\"")
  460. else()
  461. list(APPEND EXTRA_LIBS ${XI_LIB})
  462. endif()
  463. set(SDL_VIDEO_DRIVER_X11_XINPUT2 1)
  464. # Check for multitouch
  465. check_c_source_compiles("
  466. #include <X11/Xlib.h>
  467. #include <X11/Xproto.h>
  468. #include <X11/extensions/XInput2.h>
  469. int event_type = XI_TouchBegin;
  470. XITouchClassInfo *t;
  471. Status XIAllowTouchEvents(Display *a,int b,unsigned int c,Window d,int f)
  472. {
  473. return (Status)0;
  474. }
  475. int main(int argc, char **argv) {}" HAVE_XINPUT2_MULTITOUCH)
  476. if(HAVE_XINPUT2_MULTITOUCH)
  477. set(SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH 1)
  478. endif()
  479. endif()
  480. if(VIDEO_X11_XRANDR AND HAVE_XRANDR_H)
  481. if(HAVE_X11_SHARED AND XRANDR_LIB)
  482. set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR "\"${XRANDR_LIB_SONAME}\"")
  483. else()
  484. list(APPEND EXTRA_LIBS ${XRANDR_LIB})
  485. endif()
  486. set(SDL_VIDEO_DRIVER_X11_XRANDR 1)
  487. set(HAVE_VIDEO_X11_XRANDR TRUE)
  488. endif()
  489. if(VIDEO_X11_XSCRNSAVER AND HAVE_XSS_H)
  490. if(HAVE_X11_SHARED AND XSS_LIB)
  491. set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XSS "\"${XSS_LIB_SONAME}\"")
  492. else()
  493. list(APPEND EXTRA_LIBS ${XSS_LIB})
  494. endif()
  495. set(SDL_VIDEO_DRIVER_X11_XSCRNSAVER 1)
  496. set(HAVE_VIDEO_X11_XSCRNSAVER TRUE)
  497. endif()
  498. if(VIDEO_X11_XSHAPE AND HAVE_XSHAPE_H)
  499. set(SDL_VIDEO_DRIVER_X11_XSHAPE 1)
  500. set(HAVE_VIDEO_X11_XSHAPE TRUE)
  501. endif()
  502. if(VIDEO_X11_XVM AND HAVE_XF86VM_H)
  503. if(HAVE_X11_SHARED AND XXF86VM_LIB)
  504. set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XVIDMODE "\"${XXF86VM_LIB_SONAME}\"")
  505. else()
  506. list(APPEND EXTRA_LIBS ${XXF86VM_LIB})
  507. endif()
  508. set(SDL_VIDEO_DRIVER_X11_XVIDMODE 1)
  509. set(HAVE_VIDEO_X11_XVM TRUE)
  510. endif()
  511. set(CMAKE_REQUIRED_LIBRARIES)
  512. endif()
  513. endif()
  514. endmacro()
  515. # Requires:
  516. # - EGL
  517. # - PkgCheckModules
  518. # Optional:
  519. # - MIR_SHARED opt
  520. # - HAVE_DLOPEN opt
  521. macro(CheckMir)
  522. if(VIDEO_MIR)
  523. find_library(MIR_LIB mirclient mircommon egl)
  524. pkg_check_modules(MIR_TOOLKIT mirclient>=0.26 mircommon)
  525. pkg_check_modules(EGL egl)
  526. pkg_check_modules(XKB xkbcommon)
  527. if (MIR_LIB AND MIR_TOOLKIT_FOUND AND EGL_FOUND AND XKB_FOUND)
  528. set(HAVE_VIDEO_MIR TRUE)
  529. set(HAVE_SDL_VIDEO TRUE)
  530. file(GLOB MIR_SOURCES ${SDL2_SOURCE_DIR}/src/video/mir/*.c)
  531. set(SOURCE_FILES ${SOURCE_FILES} ${MIR_SOURCES})
  532. set(SDL_VIDEO_DRIVER_MIR 1)
  533. list(APPEND EXTRA_CFLAGS ${MIR_TOOLKIT_CFLAGS} ${EGL_CFLAGS} ${XKB_CFLAGS})
  534. if(MIR_SHARED)
  535. if(NOT HAVE_DLOPEN)
  536. message_warn("You must have SDL_LoadObject() support for dynamic Mir loading")
  537. else()
  538. FindLibraryAndSONAME(mirclient)
  539. FindLibraryAndSONAME(xkbcommon)
  540. set(SDL_VIDEO_DRIVER_MIR_DYNAMIC "\"${MIRCLIENT_LIB_SONAME}\"")
  541. set(SDL_VIDEO_DRIVER_MIR_DYNAMIC_XKBCOMMON "\"${XKBCOMMON_LIB_SONAME}\"")
  542. set(HAVE_MIR_SHARED TRUE)
  543. endif()
  544. else()
  545. set(EXTRA_LIBS ${MIR_TOOLKIT_LIBRARIES} ${EXTRA_LIBS})
  546. endif()
  547. endif()
  548. endif()
  549. endmacro()
  550. macro(WaylandProtocolGen _SCANNER _XML _PROTL)
  551. set(_WAYLAND_PROT_C_CODE "${CMAKE_CURRENT_BINARY_DIR}/wayland-generated-protocols/${_PROTL}-protocol.c")
  552. set(_WAYLAND_PROT_H_CODE "${CMAKE_CURRENT_BINARY_DIR}/wayland-generated-protocols/${_PROTL}-client-protocol.h")
  553. add_custom_command(
  554. OUTPUT "${_WAYLAND_PROT_H_CODE}"
  555. DEPENDS "${_XML}"
  556. COMMAND "${_SCANNER}"
  557. ARGS client-header "${_XML}" "${_WAYLAND_PROT_H_CODE}"
  558. )
  559. add_custom_command(
  560. OUTPUT "${_WAYLAND_PROT_C_CODE}"
  561. DEPENDS "${_WAYLAND_PROT_H_CODE}"
  562. COMMAND "${_SCANNER}"
  563. ARGS code "${_XML}" "${_WAYLAND_PROT_C_CODE}"
  564. )
  565. set(SOURCE_FILES ${SOURCE_FILES} "${_WAYLAND_PROT_C_CODE}")
  566. endmacro()
  567. # Requires:
  568. # - EGL
  569. # - PkgCheckModules
  570. # Optional:
  571. # - WAYLAND_SHARED opt
  572. # - HAVE_DLOPEN opt
  573. macro(CheckWayland)
  574. if(VIDEO_WAYLAND)
  575. pkg_check_modules(WAYLAND wayland-client wayland-scanner wayland-protocols wayland-egl wayland-cursor egl xkbcommon)
  576. # We have to generate some protocol interface code for some various Wayland features.
  577. if(WAYLAND_FOUND)
  578. execute_process(
  579. COMMAND ${PKG_CONFIG_EXECUTABLE} --variable=pkgdatadir wayland-client
  580. WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
  581. RESULT_VARIABLE WAYLAND_CORE_PROTOCOL_DIR_RC
  582. OUTPUT_VARIABLE WAYLAND_CORE_PROTOCOL_DIR
  583. ERROR_QUIET
  584. OUTPUT_STRIP_TRAILING_WHITESPACE
  585. )
  586. if(NOT WAYLAND_CORE_PROTOCOL_DIR_RC EQUAL 0)
  587. set(WAYLAND_FOUND FALSE)
  588. endif()
  589. endif()
  590. if(WAYLAND_FOUND)
  591. execute_process(
  592. COMMAND ${PKG_CONFIG_EXECUTABLE} --variable=pkgdatadir wayland-protocols
  593. WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
  594. RESULT_VARIABLE WAYLAND_PROTOCOLS_DIR_RC
  595. OUTPUT_VARIABLE WAYLAND_PROTOCOLS_DIR
  596. ERROR_QUIET
  597. OUTPUT_STRIP_TRAILING_WHITESPACE
  598. )
  599. if(NOT WAYLAND_PROTOCOLS_DIR_RC EQUAL 0)
  600. set(WAYLAND_FOUND FALSE)
  601. endif()
  602. endif()
  603. if(WAYLAND_FOUND)
  604. execute_process(
  605. COMMAND ${PKG_CONFIG_EXECUTABLE} --variable=wayland_scanner wayland-scanner
  606. WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
  607. RESULT_VARIABLE WAYLAND_SCANNER_RC
  608. OUTPUT_VARIABLE WAYLAND_SCANNER
  609. ERROR_QUIET
  610. OUTPUT_STRIP_TRAILING_WHITESPACE
  611. )
  612. if(NOT WAYLAND_SCANNER_RC EQUAL 0)
  613. set(WAYLAND_FOUND FALSE)
  614. endif()
  615. endif()
  616. if(WAYLAND_FOUND)
  617. link_directories(
  618. ${WAYLAND_LIBRARY_DIRS}
  619. )
  620. include_directories(
  621. ${WAYLAND_INCLUDE_DIRS}
  622. )
  623. set(HAVE_VIDEO_WAYLAND TRUE)
  624. set(HAVE_SDL_VIDEO TRUE)
  625. file(GLOB WAYLAND_SOURCES ${SDL2_SOURCE_DIR}/src/video/wayland/*.c)
  626. set(SOURCE_FILES ${SOURCE_FILES} ${WAYLAND_SOURCES})
  627. # We have to generate some protocol interface code for some unstable Wayland features.
  628. file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/wayland-generated-protocols")
  629. include_directories("${CMAKE_CURRENT_BINARY_DIR}/wayland-generated-protocols")
  630. WaylandProtocolGen("${WAYLAND_SCANNER}" "${WAYLAND_CORE_PROTOCOL_DIR}/wayland.xml" "wayland")
  631. foreach(_PROTL relative-pointer-unstable-v1 pointer-constraints-unstable-v1 xdg-shell-unstable-v6)
  632. string(REGEX REPLACE "\\-unstable\\-.*$" "" PROTSUBDIR ${_PROTL})
  633. WaylandProtocolGen("${WAYLAND_SCANNER}" "${WAYLAND_PROTOCOLS_DIR}/unstable/${PROTSUBDIR}/${_PROTL}.xml" "${_PROTL}")
  634. endforeach()
  635. if(VIDEO_WAYLAND_QT_TOUCH)
  636. set(SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH 1)
  637. endif()
  638. if(WAYLAND_SHARED)
  639. if(NOT HAVE_DLOPEN)
  640. message_warn("You must have SDL_LoadObject() support for dynamic Wayland loading")
  641. else()
  642. FindLibraryAndSONAME(wayland-client)
  643. FindLibraryAndSONAME(wayland-egl)
  644. FindLibraryAndSONAME(wayland-cursor)
  645. FindLibraryAndSONAME(xkbcommon)
  646. set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC "\"${WAYLAND_CLIENT_LIB_SONAME}\"")
  647. set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_EGL "\"${WAYLAND_EGL_LIB_SONAME}\"")
  648. set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_CURSOR "\"${WAYLAND_CURSOR_LIB_SONAME}\"")
  649. set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_XKBCOMMON "\"${XKBCOMMON_LIB_SONAME}\"")
  650. set(HAVE_WAYLAND_SHARED TRUE)
  651. endif()
  652. else()
  653. set(EXTRA_LIBS ${WAYLAND_LIBRARIES} ${EXTRA_LIBS})
  654. endif()
  655. set(SDL_VIDEO_DRIVER_WAYLAND 1)
  656. endif()
  657. endif()
  658. endmacro()
  659. # Requires:
  660. # - n/a
  661. #
  662. macro(CheckCOCOA)
  663. if(VIDEO_COCOA)
  664. if(APPLE) # Apple always has Cocoa.
  665. set(HAVE_VIDEO_COCOA TRUE)
  666. endif()
  667. if(HAVE_VIDEO_COCOA)
  668. file(GLOB COCOA_SOURCES ${SDL2_SOURCE_DIR}/src/video/cocoa/*.m)
  669. set_source_files_properties(${COCOA_SOURCES} PROPERTIES LANGUAGE C)
  670. set(SOURCE_FILES ${SOURCE_FILES} ${COCOA_SOURCES})
  671. set(SDL_VIDEO_DRIVER_COCOA 1)
  672. set(HAVE_SDL_VIDEO TRUE)
  673. endif()
  674. endif()
  675. endmacro()
  676. # Requires:
  677. # - PkgCheckModules
  678. # Optional:
  679. # - DIRECTFB_SHARED opt
  680. # - HAVE_DLOPEN opt
  681. macro(CheckDirectFB)
  682. if(VIDEO_DIRECTFB)
  683. pkg_check_modules(PKG_DIRECTFB directfb>=1.0.0)
  684. if(PKG_DIRECTFB_FOUND)
  685. set(HAVE_VIDEO_DIRECTFB TRUE)
  686. file(GLOB DIRECTFB_SOURCES ${SDL2_SOURCE_DIR}/src/video/directfb/*.c)
  687. set(SOURCE_FILES ${SOURCE_FILES} ${DIRECTFB_SOURCES})
  688. set(SDL_VIDEO_DRIVER_DIRECTFB 1)
  689. set(SDL_VIDEO_RENDER_DIRECTFB 1)
  690. list(APPEND EXTRA_CFLAGS ${PKG_DIRECTFB_CFLAGS})
  691. if(DIRECTFB_SHARED)
  692. if(NOT HAVE_DLOPEN)
  693. message_warn("You must have SDL_LoadObject() support for dynamic DirectFB loading")
  694. else()
  695. FindLibraryAndSONAME("directfb")
  696. set(SDL_VIDEO_DRIVER_DIRECTFB_DYNAMIC "\"${DIRECTFB_LIB_SONAME}\"")
  697. set(HAVE_DIRECTFB_SHARED TRUE)
  698. endif()
  699. else()
  700. list(APPEND EXTRA_LDFLAGS ${PKG_DIRECTFB_LDFLAGS})
  701. endif()
  702. set(HAVE_SDL_VIDEO TRUE)
  703. endif()
  704. endif()
  705. endmacro()
  706. # Requires:
  707. # - n/a
  708. macro(CheckVivante)
  709. if(VIDEO_VIVANTE)
  710. check_c_source_compiles("
  711. #include <gc_vdk.h>
  712. int main(int argc, char** argv) {}" HAVE_VIDEO_VIVANTE_VDK)
  713. check_c_source_compiles("
  714. #define LINUX
  715. #define EGL_API_FB
  716. #include <EGL/eglvivante.h>
  717. int main(int argc, char** argv) {}" HAVE_VIDEO_VIVANTE_EGL_FB)
  718. if(HAVE_VIDEO_VIVANTE_VDK OR HAVE_VIDEO_VIVANTE_EGL_FB)
  719. set(HAVE_VIDEO_VIVANTE TRUE)
  720. set(HAVE_SDL_VIDEO TRUE)
  721. file(GLOB VIVANTE_SOURCES ${SDL2_SOURCE_DIR}/src/video/vivante/*.c)
  722. set(SOURCE_FILES ${SOURCE_FILES} ${VIVANTE_SOURCES})
  723. set(SDL_VIDEO_DRIVER_VIVANTE 1)
  724. if(HAVE_VIDEO_VIVANTE_VDK)
  725. set(SDL_VIDEO_DRIVER_VIVANTE_VDK 1)
  726. list(APPEND EXTRA_LIBS VDK VIVANTE)
  727. else()
  728. set(SDL_CFLAGS "${SDL_CFLAGS} -DLINUX -DEGL_API_FB")
  729. list(APPEND EXTRA_LIBS EGL)
  730. endif(HAVE_VIDEO_VIVANTE_VDK)
  731. endif(HAVE_VIDEO_VIVANTE_VDK OR HAVE_VIDEO_VIVANTE_EGL_FB)
  732. endif(VIDEO_VIVANTE)
  733. endmacro(CheckVivante)
  734. # Requires:
  735. # - nada
  736. macro(CheckOpenGLX11)
  737. if(VIDEO_OPENGL)
  738. check_c_source_compiles("
  739. #include <GL/gl.h>
  740. #include <GL/glx.h>
  741. int main(int argc, char** argv) {}" HAVE_VIDEO_OPENGL)
  742. if(HAVE_VIDEO_OPENGL)
  743. set(HAVE_VIDEO_OPENGL TRUE)
  744. set(SDL_VIDEO_OPENGL 1)
  745. set(SDL_VIDEO_OPENGL_GLX 1)
  746. set(SDL_VIDEO_RENDER_OGL 1)
  747. endif()
  748. endif()
  749. endmacro()
  750. # Requires:
  751. # - nada
  752. macro(CheckOpenGLESX11)
  753. if(VIDEO_OPENGLES)
  754. check_c_source_compiles("
  755. #define EGL_API_FB
  756. #include <EGL/egl.h>
  757. int main (int argc, char** argv) {}" HAVE_VIDEO_OPENGL_EGL)
  758. if(HAVE_VIDEO_OPENGL_EGL)
  759. set(SDL_VIDEO_OPENGL_EGL 1)
  760. endif()
  761. check_c_source_compiles("
  762. #include <GLES/gl.h>
  763. #include <GLES/glext.h>
  764. int main (int argc, char** argv) {}" HAVE_VIDEO_OPENGLES_V1)
  765. if(HAVE_VIDEO_OPENGLES_V1)
  766. set(HAVE_VIDEO_OPENGLES TRUE)
  767. set(SDL_VIDEO_OPENGL_ES 1)
  768. set(SDL_VIDEO_RENDER_OGL_ES 1)
  769. endif()
  770. check_c_source_compiles("
  771. #include <GLES2/gl2.h>
  772. #include <GLES2/gl2ext.h>
  773. int main (int argc, char** argv) {}" HAVE_VIDEO_OPENGLES_V2)
  774. if(HAVE_VIDEO_OPENGLES_V2)
  775. set(HAVE_VIDEO_OPENGLES TRUE)
  776. set(SDL_VIDEO_OPENGL_ES2 1)
  777. set(SDL_VIDEO_RENDER_OGL_ES2 1)
  778. endif()
  779. endif()
  780. endmacro()
  781. # Requires:
  782. # - nada
  783. # Optional:
  784. # - THREADS opt
  785. # Sets:
  786. # PTHREAD_CFLAGS
  787. # PTHREAD_LIBS
  788. macro(CheckPTHREAD)
  789. if(PTHREADS)
  790. if(ANDROID)
  791. # the android libc provides built-in support for pthreads, so no
  792. # additional linking or compile flags are necessary
  793. elseif(LINUX)
  794. set(PTHREAD_CFLAGS "-D_REENTRANT")
  795. set(PTHREAD_LDFLAGS "-pthread")
  796. elseif(BSDI)
  797. set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
  798. set(PTHREAD_LDFLAGS "")
  799. elseif(DARWIN)
  800. set(PTHREAD_CFLAGS "-D_THREAD_SAFE")
  801. # causes Carbon.p complaints?
  802. # set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
  803. set(PTHREAD_LDFLAGS "")
  804. elseif(FREEBSD)
  805. set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
  806. set(PTHREAD_LDFLAGS "-pthread")
  807. elseif(NETBSD)
  808. set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
  809. set(PTHREAD_LDFLAGS "-lpthread")
  810. elseif(OPENBSD)
  811. set(PTHREAD_CFLAGS "-D_REENTRANT")
  812. set(PTHREAD_LDFLAGS "-pthread")
  813. elseif(SOLARIS)
  814. set(PTHREAD_CFLAGS "-D_REENTRANT")
  815. set(PTHREAD_LDFLAGS "-pthread -lposix4")
  816. elseif(SYSV5)
  817. set(PTHREAD_CFLAGS "-D_REENTRANT -Kthread")
  818. set(PTHREAD_LDFLAGS "")
  819. elseif(AIX)
  820. set(PTHREAD_CFLAGS "-D_REENTRANT -mthreads")
  821. set(PTHREAD_LDFLAGS "-pthread")
  822. elseif(HPUX)
  823. set(PTHREAD_CFLAGS "-D_REENTRANT")
  824. set(PTHREAD_LDFLAGS "-L/usr/lib -pthread")
  825. elseif(HAIKU)
  826. set(PTHREAD_CFLAGS "-D_REENTRANT")
  827. set(PTHREAD_LDFLAGS "")
  828. else()
  829. set(PTHREAD_CFLAGS "-D_REENTRANT")
  830. set(PTHREAD_LDFLAGS "-lpthread")
  831. endif()
  832. # Run some tests
  833. set(ORIG_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
  834. set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${PTHREAD_CFLAGS} ${PTHREAD_LDFLAGS}")
  835. if(CMAKE_CROSSCOMPILING)
  836. set(HAVE_PTHREADS 1)
  837. else()
  838. check_c_source_runs("
  839. #include <pthread.h>
  840. int main(int argc, char** argv) {
  841. pthread_attr_t type;
  842. pthread_attr_init(&type);
  843. return 0;
  844. }" HAVE_PTHREADS)
  845. endif()
  846. if(HAVE_PTHREADS)
  847. set(SDL_THREAD_PTHREAD 1)
  848. list(APPEND EXTRA_CFLAGS ${PTHREAD_CFLAGS})
  849. list(APPEND EXTRA_LDFLAGS ${PTHREAD_LDFLAGS})
  850. set(SDL_CFLAGS "${SDL_CFLAGS} ${PTHREAD_CFLAGS}")
  851. list(APPEND SDL_LIBS ${PTHREAD_LDFLAGS})
  852. check_c_source_compiles("
  853. #include <pthread.h>
  854. int main(int argc, char **argv) {
  855. pthread_mutexattr_t attr;
  856. pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
  857. return 0;
  858. }" HAVE_RECURSIVE_MUTEXES)
  859. if(HAVE_RECURSIVE_MUTEXES)
  860. set(SDL_THREAD_PTHREAD_RECURSIVE_MUTEX 1)
  861. else()
  862. check_c_source_compiles("
  863. #include <pthread.h>
  864. int main(int argc, char **argv) {
  865. pthread_mutexattr_t attr;
  866. pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE_NP);
  867. return 0;
  868. }" HAVE_RECURSIVE_MUTEXES_NP)
  869. if(HAVE_RECURSIVE_MUTEXES_NP)
  870. set(SDL_THREAD_PTHREAD_RECURSIVE_MUTEX_NP 1)
  871. endif()
  872. endif()
  873. if(PTHREADS_SEM)
  874. check_c_source_compiles("#include <pthread.h>
  875. #include <semaphore.h>
  876. int main(int argc, char **argv) { return 0; }" HAVE_PTHREADS_SEM)
  877. if(HAVE_PTHREADS_SEM)
  878. check_c_source_compiles("
  879. #include <pthread.h>
  880. #include <semaphore.h>
  881. int main(int argc, char **argv) {
  882. sem_timedwait(NULL, NULL);
  883. return 0;
  884. }" HAVE_SEM_TIMEDWAIT)
  885. endif()
  886. endif()
  887. check_c_source_compiles("
  888. #include <pthread.h>
  889. #include <pthread_np.h>
  890. int main(int argc, char** argv) { return 0; }" HAVE_PTHREAD_NP_H)
  891. check_function_exists(pthread_setname_np HAVE_PTHREAD_SETNAME_NP)
  892. check_function_exists(pthread_set_name_np HAVE_PTHREAD_SET_NAME_NP)
  893. set(SOURCE_FILES ${SOURCE_FILES}
  894. ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_systhread.c
  895. ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_sysmutex.c # Can be faked, if necessary
  896. ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_syscond.c # Can be faked, if necessary
  897. ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_systls.c
  898. )
  899. if(HAVE_PTHREADS_SEM)
  900. set(SOURCE_FILES ${SOURCE_FILES}
  901. ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_syssem.c)
  902. else()
  903. set(SOURCE_FILES ${SOURCE_FILES}
  904. ${SDL2_SOURCE_DIR}/src/thread/generic/SDL_syssem.c)
  905. endif()
  906. set(HAVE_SDL_THREADS TRUE)
  907. endif()
  908. set(CMAKE_REQUIRED_FLAGS "${ORIG_CMAKE_REQUIRED_FLAGS}")
  909. endif()
  910. endmacro()
  911. # Requires
  912. # - nada
  913. # Optional:
  914. # Sets:
  915. # USB_LIBS
  916. # USB_CFLAGS
  917. macro(CheckUSBHID)
  918. check_library_exists(usbhid hid_init "" LIBUSBHID)
  919. if(LIBUSBHID)
  920. check_include_file(usbhid.h HAVE_USBHID_H)
  921. if(HAVE_USBHID_H)
  922. set(USB_CFLAGS "-DHAVE_USBHID_H")
  923. endif()
  924. check_include_file(libusbhid.h HAVE_LIBUSBHID_H)
  925. if(HAVE_LIBUSBHID_H)
  926. set(USB_CFLAGS "${USB_CFLAGS} -DHAVE_LIBUSBHID_H")
  927. endif()
  928. set(USB_LIBS ${USB_LIBS} usbhid)
  929. else()
  930. check_include_file(usb.h HAVE_USB_H)
  931. if(HAVE_USB_H)
  932. set(USB_CFLAGS "-DHAVE_USB_H")
  933. endif()
  934. check_include_file(libusb.h HAVE_LIBUSB_H)
  935. if(HAVE_LIBUSB_H)
  936. set(USB_CFLAGS "${USB_CFLAGS} -DHAVE_LIBUSB_H")
  937. endif()
  938. check_library_exists(usb hid_init "" LIBUSB)
  939. if(LIBUSB)
  940. set(USB_LIBS ${USB_LIBS} usb)
  941. endif()
  942. endif()
  943. set(ORIG_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
  944. set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${USB_CFLAGS}")
  945. set(CMAKE_REQUIRED_LIBRARIES "${USB_LIBS}")
  946. check_c_source_compiles("
  947. #include <sys/types.h>
  948. #if defined(HAVE_USB_H)
  949. #include <usb.h>
  950. #endif
  951. #ifdef __DragonFly__
  952. # include <bus/usb/usb.h>
  953. # include <bus/usb/usbhid.h>
  954. #else
  955. # include <dev/usb/usb.h>
  956. # include <dev/usb/usbhid.h>
  957. #endif
  958. #if defined(HAVE_USBHID_H)
  959. #include <usbhid.h>
  960. #elif defined(HAVE_LIBUSB_H)
  961. #include <libusb.h>
  962. #elif defined(HAVE_LIBUSBHID_H)
  963. #include <libusbhid.h>
  964. #endif
  965. int main(int argc, char **argv) {
  966. struct report_desc *repdesc;
  967. struct usb_ctl_report *repbuf;
  968. hid_kind_t hidkind;
  969. return 0;
  970. }" HAVE_USBHID)
  971. if(HAVE_USBHID)
  972. check_c_source_compiles("
  973. #include <sys/types.h>
  974. #if defined(HAVE_USB_H)
  975. #include <usb.h>
  976. #endif
  977. #ifdef __DragonFly__
  978. # include <bus/usb/usb.h>
  979. # include <bus/usb/usbhid.h>
  980. #else
  981. # include <dev/usb/usb.h>
  982. # include <dev/usb/usbhid.h>
  983. #endif
  984. #if defined(HAVE_USBHID_H)
  985. #include <usbhid.h>
  986. #elif defined(HAVE_LIBUSB_H)
  987. #include <libusb.h>
  988. #elif defined(HAVE_LIBUSBHID_H)
  989. #include <libusbhid.h>
  990. #endif
  991. int main(int argc, char** argv) {
  992. struct usb_ctl_report buf;
  993. if (buf.ucr_data) { }
  994. return 0;
  995. }" HAVE_USBHID_UCR_DATA)
  996. if(HAVE_USBHID_UCR_DATA)
  997. set(USB_CFLAGS "${USB_CFLAGS} -DUSBHID_UCR_DATA")
  998. endif()
  999. check_c_source_compiles("
  1000. #include <sys/types.h>
  1001. #if defined(HAVE_USB_H)
  1002. #include <usb.h>
  1003. #endif
  1004. #ifdef __DragonFly__
  1005. #include <bus/usb/usb.h>
  1006. #include <bus/usb/usbhid.h>
  1007. #else
  1008. #include <dev/usb/usb.h>
  1009. #include <dev/usb/usbhid.h>
  1010. #endif
  1011. #if defined(HAVE_USBHID_H)
  1012. #include <usbhid.h>
  1013. #elif defined(HAVE_LIBUSB_H)
  1014. #include <libusb.h>
  1015. #elif defined(HAVE_LIBUSBHID_H)
  1016. #include <libusbhid.h>
  1017. #endif
  1018. int main(int argc, char **argv) {
  1019. report_desc_t d;
  1020. hid_start_parse(d, 1, 1);
  1021. return 0;
  1022. }" HAVE_USBHID_NEW)
  1023. if(HAVE_USBHID_NEW)
  1024. set(USB_CFLAGS "${USB_CFLAGS} -DUSBHID_NEW")
  1025. endif()
  1026. check_c_source_compiles("
  1027. #include <machine/joystick.h>
  1028. int main(int argc, char** argv) {
  1029. struct joystick t;
  1030. return 0;
  1031. }" HAVE_MACHINE_JOYSTICK)
  1032. if(HAVE_MACHINE_JOYSTICK)
  1033. set(SDL_JOYSTICK_USBHID_MACHINE_JOYSTICK_H 1)
  1034. endif()
  1035. set(SDL_JOYSTICK_USBHID 1)
  1036. file(GLOB BSD_JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/bsd/*.c)
  1037. set(SOURCE_FILES ${SOURCE_FILES} ${BSD_JOYSTICK_SOURCES})
  1038. list(APPEND EXTRA_CFLAGS ${USB_CFLAGS})
  1039. list(APPEND EXTRA_LIBS ${USB_LIBS})
  1040. set(HAVE_SDL_JOYSTICK TRUE)
  1041. set(CMAKE_REQUIRED_LIBRARIES)
  1042. set(CMAKE_REQUIRED_FLAGS "${ORIG_CMAKE_REQUIRED_FLAGS}")
  1043. endif()
  1044. endmacro()
  1045. # Requires:
  1046. # - n/a
  1047. macro(CheckRPI)
  1048. if(VIDEO_RPI)
  1049. pkg_check_modules(VIDEO_RPI bcm_host brcmegl)
  1050. if (NOT VIDEO_RPI_FOUND)
  1051. set(VIDEO_RPI_INCLUDE_DIRS "/opt/vc/include" "/opt/vc/include/interface/vcos/pthreads" "/opt/vc/include/interface/vmcs_host/linux/" )
  1052. set(VIDEO_RPI_LIBRARY_DIRS "/opt/vc/lib" )
  1053. set(VIDEO_RPI_LIBRARIES bcm_host )
  1054. set(VIDEO_RPI_LDFLAGS "-Wl,-rpath,/opt/vc/lib")
  1055. endif()
  1056. listtostr(VIDEO_RPI_INCLUDE_DIRS VIDEO_RPI_INCLUDE_FLAGS "-I")
  1057. listtostr(VIDEO_RPI_LIBRARY_DIRS VIDEO_RPI_LIBRARY_FLAGS "-L")
  1058. set(ORIG_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
  1059. set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${VIDEO_RPI_INCLUDE_FLAGS} ${VIDEO_RPI_LIBRARY_FLAGS}")
  1060. set(CMAKE_REQUIRED_LIBRARIES "${VIDEO_RPI_LIBRARIES}")
  1061. check_c_source_compiles("
  1062. #include <bcm_host.h>
  1063. int main(int argc, char **argv) {}" HAVE_VIDEO_RPI)
  1064. set(CMAKE_REQUIRED_FLAGS "${ORIG_CMAKE_REQUIRED_FLAGS}")
  1065. set(CMAKE_REQUIRED_LIBRARIES)
  1066. if(SDL_VIDEO AND HAVE_VIDEO_RPI)
  1067. set(HAVE_SDL_VIDEO TRUE)
  1068. set(SDL_VIDEO_DRIVER_RPI 1)
  1069. file(GLOB VIDEO_RPI_SOURCES ${SDL2_SOURCE_DIR}/src/video/raspberry/*.c)
  1070. set(SOURCE_FILES ${SOURCE_FILES} ${VIDEO_RPI_SOURCES})
  1071. list(APPEND EXTRA_LIBS ${VIDEO_RPI_LIBRARIES})
  1072. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${VIDEO_RPI_INCLUDE_FLAGS} ${VIDEO_RPI_LIBRARY_FLAGS}")
  1073. list(APPEND EXTRA_LDFLAGS ${VIDEO_RPI_LDFLAGS})
  1074. endif(SDL_VIDEO AND HAVE_VIDEO_RPI)
  1075. endif(VIDEO_RPI)
  1076. endmacro(CheckRPI)
  1077. # Requires:
  1078. # - EGL
  1079. # - PkgCheckModules
  1080. # Optional:
  1081. # - KMSDRM_SHARED opt
  1082. # - HAVE_DLOPEN opt
  1083. macro(CheckKMSDRM)
  1084. if(VIDEO_KMSDRM)
  1085. pkg_check_modules(KMSDRM libdrm gbm egl)
  1086. if(KMSDRM_FOUND)
  1087. link_directories(
  1088. ${KMSDRM_LIBRARY_DIRS}
  1089. )
  1090. include_directories(
  1091. ${KMSDRM_INCLUDE_DIRS}
  1092. )
  1093. set(HAVE_VIDEO_KMSDRM TRUE)
  1094. set(HAVE_SDL_VIDEO TRUE)
  1095. file(GLOB KMSDRM_SOURCES ${SDL2_SOURCE_DIR}/src/video/kmsdrm/*.c)
  1096. set(SOURCE_FILES ${SOURCE_FILES} ${KMSDRM_SOURCES})
  1097. list(APPEND EXTRA_CFLAGS ${KMSDRM_CFLAGS})
  1098. set(SDL_VIDEO_DRIVER_KMSDRM 1)
  1099. if(KMSDRM_SHARED)
  1100. if(NOT HAVE_DLOPEN)
  1101. message_warn("You must have SDL_LoadObject() support for dynamic KMS/DRM loading")
  1102. else()
  1103. FindLibraryAndSONAME(drm)
  1104. FindLibraryAndSONAME(gbm)
  1105. set(SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC "\"${DRM_LIB_SONAME}\"")
  1106. set(SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC_GBM "\"${GBM_LIB_SONAME}\"")
  1107. set(HAVE_KMSDRM_SHARED TRUE)
  1108. endif()
  1109. else()
  1110. set(EXTRA_LIBS ${KMSDRM_LIBRARIES} ${EXTRA_LIBS})
  1111. endif()
  1112. endif()
  1113. endif()
  1114. endmacro()