sdlchecks.cmake 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926
  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(DLOPEN_LIB)
  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(CheckDLOPEN)
  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(NOT OSS_FOUND)
  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(OSS_HEADER_FILE STREQUAL "soundcard.h")
  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(NETBSD OR OPENBSD)
  84. set(HAVE_SDL_AUDIO TRUE)
  85. endif(OSS_FOUND)
  86. endif(OSS)
  87. endmacro(CheckOSS)
  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_open "" HAVE_LIBASOUND)
  98. set(HAVE_ALSA TRUE)
  99. file(GLOB ALSA_SOURCES ${SDL2_SOURCE_DIR}/src/audio/alsa/*.c)
  100. set(SOURCE_FILES ${SOURCE_FILES} ${ALSA_SOURCES})
  101. set(SDL_AUDIO_DRIVER_ALSA 1)
  102. if(ALSA_SHARED)
  103. if(NOT HAVE_DLOPEN)
  104. message_warn("You must have SDL_LoadObject() support for dynamic ALSA loading")
  105. else()
  106. FindLibraryAndSONAME("asound")
  107. set(SDL_AUDIO_DRIVER_ALSA_DYNAMIC "\"${ASOUND_LIB_SONAME}\"")
  108. set(HAVE_ALSA_SHARED TRUE)
  109. endif(NOT HAVE_DLOPEN)
  110. else(ALSA_SHARED)
  111. list(APPEND EXTRA_LIBS asound)
  112. endif(ALSA_SHARED)
  113. set(HAVE_SDL_AUDIO TRUE)
  114. endif(HAVE_ASOUNDLIB_H)
  115. endif(ALSA)
  116. endmacro(CheckALSA)
  117. # Requires:
  118. # - PkgCheckModules
  119. # Optional:
  120. # - PULSEAUDIO_SHARED opt
  121. # - HAVE_DLOPEN opt
  122. macro(CheckPulseAudio)
  123. if(PULSEAUDIO)
  124. pkg_check_modules(PKG_PULSEAUDIO libpulse-simple)
  125. if(PKG_PULSEAUDIO_FOUND)
  126. set(HAVE_PULSEAUDIO TRUE)
  127. file(GLOB PULSEAUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/pulseaudio/*.c)
  128. set(SOURCE_FILES ${SOURCE_FILES} ${PULSEAUDIO_SOURCES})
  129. set(SDL_AUDIO_DRIVER_PULSEAUDIO 1)
  130. list(APPEND EXTRA_CFLAGS ${PKG_PULSEAUDIO_CFLAGS})
  131. if(PULSEAUDIO_SHARED)
  132. if(NOT HAVE_DLOPEN)
  133. message_warn("You must have SDL_LoadObject() support for dynamic PulseAudio loading")
  134. else()
  135. FindLibraryAndSONAME("pulse-simple")
  136. set(SDL_AUDIO_DRIVER_PULSEAUDIO_DYNAMIC "\"${PULSE_SIMPLE_LIB_SONAME}\"")
  137. set(HAVE_PULSEAUDIO_SHARED TRUE)
  138. endif(NOT HAVE_DLOPEN)
  139. else(PULSEAUDIO_SHARED)
  140. list(APPEND EXTRA_LDFLAGS ${PKG_PULSEAUDIO_LDFLAGS})
  141. endif(PULSEAUDIO_SHARED)
  142. set(HAVE_SDL_AUDIO TRUE)
  143. endif(PKG_PULSEAUDIO_FOUND)
  144. endif(PULSEAUDIO)
  145. endmacro(CheckPulseAudio)
  146. # Requires:
  147. # - PkgCheckModules
  148. # Optional:
  149. # - ESD_SHARED opt
  150. # - HAVE_DLOPEN opt
  151. macro(CheckESD)
  152. if(ESD)
  153. pkg_check_modules(PKG_ESD esound)
  154. if(PKG_ESD_FOUND)
  155. set(HAVE_ESD TRUE)
  156. file(GLOB ESD_SOURCES ${SDL2_SOURCE_DIR}/src/audio/esd/*.c)
  157. set(SOURCE_FILES ${SOURCE_FILES} ${ESD_SOURCES})
  158. set(SDL_AUDIO_DRIVER_ESD 1)
  159. list(APPEND EXTRA_CFLAGS ${PKG_ESD_CFLAGS})
  160. if(ESD_SHARED)
  161. if(NOT HAVE_DLOPEN)
  162. message_warn("You must have SDL_LoadObject() support for dynamic ESD loading")
  163. else()
  164. FindLibraryAndSONAME(esd)
  165. set(SDL_AUDIO_DRIVER_ESD_DYNAMIC "\"${ESD_LIB_SONAME}\"")
  166. set(HAVE_ESD_SHARED TRUE)
  167. endif(NOT HAVE_DLOPEN)
  168. else(ESD_SHARED)
  169. list(APPEND EXTRA_LDFLAGS ${PKG_ESD_LDFLAGS})
  170. endif(ESD_SHARED)
  171. set(HAVE_SDL_AUDIO TRUE)
  172. endif(PKG_ESD_FOUND)
  173. endif(ESD)
  174. endmacro(CheckESD)
  175. # Requires:
  176. # - n/a
  177. # Optional:
  178. # - ARTS_SHARED opt
  179. # - HAVE_DLOPEN opt
  180. macro(CheckARTS)
  181. if(ARTS)
  182. find_program(ARTS_CONFIG arts-config)
  183. if(ARTS_CONFIG)
  184. execute_process(CMD_ARTSCFLAGS ${ARTS_CONFIG} --cflags
  185. OUTPUT_VARIABLE ARTS_CFLAGS OUTPUT_STRIP_TRAILING_WHITESPACE)
  186. list(APPEND EXTRA_CFLAGS ${ARTS_CFLAGS})
  187. execute_process(CMD_ARTSLIBS ${ARTS_CONFIG} --libs
  188. OUTPUT_VARIABLE ARTS_LIBS OUTPUT_STRIP_TRAILING_WHITESPACE)
  189. file(GLOB ARTS_SOURCES ${SDL2_SOURCE_DIR}/src/audio/arts/*.c)
  190. set(SOURCE_FILES ${SOURCE_FILES} ${ARTS_SOURCES})
  191. set(SDL_AUDIO_DRIVER_ARTS 1)
  192. set(HAVE_ARTS TRUE)
  193. if(ARTS_SHARED)
  194. if(NOT HAVE_DLOPEN)
  195. message_warn("You must have SDL_LoadObject() support for dynamic ARTS loading")
  196. else()
  197. # TODO
  198. FindLibraryAndSONAME(artsc)
  199. set(SDL_AUDIO_DRIVER_ARTS_DYNAMIC "\"${ARTSC_LIB_SONAME}\"")
  200. set(HAVE_ARTS_SHARED TRUE)
  201. endif(NOT HAVE_DLOPEN)
  202. else(ARTS_SHARED)
  203. list(APPEND EXTRA_LDFLAGS ${ARTS_LIBS})
  204. endif(ARTS_SHARED)
  205. set(HAVE_SDL_AUDIO TRUE)
  206. endif(ARTS_CONFIG)
  207. endif(ARTS)
  208. endmacro(CheckARTS)
  209. # Requires:
  210. # - n/a
  211. # Optional:
  212. # - NAS_SHARED opt
  213. # - HAVE_DLOPEN opt
  214. macro(CheckNAS)
  215. if(NAS)
  216. # TODO: set include paths properly, so the NAS headers are found
  217. check_include_file(audio/audiolib.h HAVE_NAS_H)
  218. find_library(D_NAS_LIB audio)
  219. if(HAVE_NAS_H AND D_NAS_LIB)
  220. set(HAVE_NAS TRUE)
  221. file(GLOB NAS_SOURCES ${SDL2_SOURCE_DIR}/src/audio/nas/*.c)
  222. set(SOURCE_FILES ${SOURCE_FILES} ${NAS_SOURCES})
  223. set(SDL_AUDIO_DRIVER_NAS 1)
  224. if(NAS_SHARED)
  225. if(NOT HAVE_DLOPEN)
  226. message_warn("You must have SDL_LoadObject() support for dynamic NAS loading")
  227. else()
  228. FindLibraryAndSONAME("audio")
  229. set(SDL_AUDIO_DRIVER_NAS_DYNAMIC "\"${AUDIO_LIB_SONAME}\"")
  230. set(HAVE_NAS_SHARED TRUE)
  231. endif(NOT HAVE_DLOPEN)
  232. else(NAS_SHARED)
  233. list(APPEND EXTRA_LIBS ${D_NAS_LIB})
  234. endif(NAS_SHARED)
  235. set(HAVE_SDL_AUDIO TRUE)
  236. endif(HAVE_NAS_H AND D_NAS_LIB)
  237. endif(NAS)
  238. endmacro(CheckNAS)
  239. # Requires:
  240. # - n/a
  241. # Optional:
  242. # - SNDIO_SHARED opt
  243. # - HAVE_DLOPEN opt
  244. macro(CheckSNDIO)
  245. if(SNDIO)
  246. # TODO: set include paths properly, so the sndio headers are found
  247. check_include_file(sndio.h HAVE_SNDIO_H)
  248. find_library(D_SNDIO_LIB sndio)
  249. if(HAVE_SNDIO_H AND D_SNDIO_LIB)
  250. set(HAVE_SNDIO TRUE)
  251. file(GLOB SNDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/sndio/*.c)
  252. set(SOURCE_FILES ${SOURCE_FILES} ${SNDIO_SOURCES})
  253. set(SDL_AUDIO_DRIVER_SNDIO 1)
  254. if(SNDIO_SHARED)
  255. if(NOT HAVE_DLOPEN)
  256. message_warn("You must have SDL_LoadObject() support for dynamic sndio loading")
  257. else()
  258. FindLibraryAndSONAME("sndio")
  259. set(SDL_AUDIO_DRIVER_SNDIO_DYNAMIC "\"${SNDIO_LIB_SONAME}\"")
  260. set(HAVE_SNDIO_SHARED TRUE)
  261. endif(NOT HAVE_DLOPEN)
  262. else(SNDIO_SHARED)
  263. list(APPEND EXTRA_LIBS ${D_SNDIO_LIB})
  264. endif(SNDIO_SHARED)
  265. set(HAVE_SDL_AUDIO TRUE)
  266. endif(HAVE_SNDIO_H AND D_SNDIO_LIB)
  267. endif(SNDIO)
  268. endmacro(CheckSNDIO)
  269. # Requires:
  270. # - PkgCheckModules
  271. # Optional:
  272. # - FUSIONSOUND_SHARED opt
  273. # - HAVE_DLOPEN opt
  274. macro(CheckFusionSound)
  275. if(FUSIONSOUND)
  276. pkg_check_modules(PKG_FUSIONSOUND fusionsound>=1.0.0)
  277. if(PKG_FUSIONSOUND_FOUND)
  278. set(HAVE_FUSIONSOUND TRUE)
  279. file(GLOB FUSIONSOUND_SOURCES ${SDL2_SOURCE_DIR}/src/audio/fusionsound/*.c)
  280. set(SOURCE_FILES ${SOURCE_FILES} ${FUSIONSOUND_SOURCES})
  281. set(SDL_AUDIO_DRIVER_FUSIONSOUND 1)
  282. list(APPEND EXTRA_CFLAGS ${PKG_FUSIONSOUND_CFLAGS})
  283. if(FUSIONSOUND_SHARED)
  284. if(NOT HAVE_DLOPEN)
  285. message_warn("You must have SDL_LoadObject() support for dynamic FusionSound loading")
  286. else()
  287. FindLibraryAndSONAME("fusionsound")
  288. set(SDL_AUDIO_DRIVER_FUSIONSOUND_DYNAMIC "\"${FUSIONSOUND_LIB_SONAME}\"")
  289. set(HAVE_FUSIONSOUND_SHARED TRUE)
  290. endif(NOT HAVE_DLOPEN)
  291. else(FUSIONSOUND_SHARED)
  292. list(APPEND EXTRA_LDFLAGS ${PKG_FUSIONSOUND_LDFLAGS})
  293. endif(FUSIONSOUND_SHARED)
  294. set(HAVE_SDL_AUDIO TRUE)
  295. endif(PKG_FUSIONSOUND_FOUND)
  296. endif(FUSIONSOUND)
  297. endmacro(CheckFusionSound)
  298. # Requires:
  299. # - n/a
  300. # Optional:
  301. # - X11_SHARED opt
  302. # - HAVE_DLOPEN opt
  303. macro(CheckX11)
  304. if(VIDEO_X11)
  305. foreach(_LIB X11 Xext Xcursor Xinerama Xi Xrandr Xrender Xss Xxf86vm)
  306. FindLibraryAndSONAME("${_LIB}")
  307. endforeach()
  308. find_path(X_INCLUDEDIR X11/Xlib.h)
  309. if(X_INCLUDEDIR)
  310. set(X_CFLAGS "-I${X_INCLUDEDIR}")
  311. endif()
  312. check_include_file(X11/Xcursor/Xcursor.h HAVE_XCURSOR_H)
  313. check_include_file(X11/extensions/Xinerama.h HAVE_XINERAMA_H)
  314. check_include_file(X11/extensions/XInput2.h HAVE_XINPUT_H)
  315. check_include_file(X11/extensions/Xrandr.h HAVE_XRANDR_H)
  316. check_include_file(X11/extensions/Xrender.h HAVE_XRENDER_H)
  317. check_include_file(X11/extensions/scrnsaver.h HAVE_XSS_H)
  318. check_include_file(X11/extensions/shape.h HAVE_XSHAPE_H)
  319. check_include_files("X11/Xlib.h;X11/extensions/xf86vmode.h" HAVE_XF86VM_H)
  320. check_include_files("X11/Xlib.h;X11/Xproto.h;X11/extensions/Xext.h" HAVE_XEXT_H)
  321. if(X11_LIB)
  322. if(NOT HAVE_XEXT_H)
  323. message_error("Missing Xext.h, maybe you need to install the libxext-dev package?")
  324. endif()
  325. set(HAVE_VIDEO_X11 TRUE)
  326. set(HAVE_SDL_VIDEO TRUE)
  327. file(GLOB X11_SOURCES ${SDL2_SOURCE_DIR}/src/video/x11/*.c)
  328. set(SOURCE_FILES ${SOURCE_FILES} ${X11_SOURCES})
  329. set(SDL_VIDEO_DRIVER_X11 1)
  330. if(APPLE)
  331. set(X11_SHARED OFF)
  332. endif(APPLE)
  333. check_function_exists("shmat" HAVE_SHMAT)
  334. if(NOT HAVE_SHMAT)
  335. check_library_exists(ipc shmat "" HAVE_SHMAT)
  336. if(HAVE_SHMAT)
  337. list(APPEND EXTRA_LIBS ipc)
  338. endif(HAVE_SHMAT)
  339. if(NOT HAVE_SHMAT)
  340. add_definitions(-DNO_SHARED_MEMORY)
  341. set(X_CFLAGS "${X_CFLAGS} -DNO_SHARED_MEMORY")
  342. endif(NOT HAVE_SHMAT)
  343. endif(NOT HAVE_SHMAT)
  344. if(X11_SHARED)
  345. if(NOT HAVE_DLOPEN)
  346. message_warn("You must have SDL_LoadObject() support for dynamic X11 loading")
  347. set(HAVE_X11_SHARED FALSE)
  348. else(NOT HAVE_DLOPEN)
  349. set(HAVE_X11_SHARED TRUE)
  350. endif()
  351. if(HAVE_X11_SHARED)
  352. set(SDL_VIDEO_DRIVER_X11_DYNAMIC "\"${X11_LIB_SONAME}\"")
  353. set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT "\"${XEXT_LIB_SONAME}\"")
  354. else(HAVE_X11_SHARED)
  355. list(APPEND EXTRA_LIBS ${X11_LIB} ${XEXT_LIB})
  356. endif(HAVE_X11_SHARED)
  357. endif(X11_SHARED)
  358. set(SDL_CFLAGS "${SDL_CFLAGS} ${X_CFLAGS}")
  359. set(CMAKE_REQUIRED_LIBRARIES ${X11_LIB} ${X11_LIB})
  360. check_c_source_compiles("
  361. #include <X11/Xlib.h>
  362. #include <X11/Xproto.h>
  363. #include <X11/extensions/Xext.h>
  364. #include <X11/extensions/extutil.h>
  365. extern XExtDisplayInfo* XextAddDisplay(XExtensionInfo* a,Display* b,_Xconst char* c,XExtensionHooks* d,int e,XPointer f);
  366. int main(int argc, char **argv) {}" HAVE_CONST_XEXT_ADDDISPLAY)
  367. if(HAVE_CONST_XEXT_ADDDISPLAY)
  368. set(SDL_VIDEO_DRIVER_X11_CONST_PARAM_XEXTADDDISPLAY 1)
  369. endif(HAVE_CONST_XEXT_ADDDISPLAY)
  370. check_c_source_compiles("
  371. #include <X11/Xlib.h>
  372. int main(int argc, char **argv) {
  373. Display *display;
  374. XEvent event;
  375. XGenericEventCookie *cookie = &event.xcookie;
  376. XNextEvent(display, &event);
  377. XGetEventData(display, cookie);
  378. XFreeEventData(display, cookie); }" HAVE_XGENERICEVENT)
  379. if(HAVE_XGENERICEVENT)
  380. set(SDL_VIDEO_DRIVER_X11_SUPPORTS_GENERIC_EVENTS 1)
  381. endif(HAVE_XGENERICEVENT)
  382. check_c_source_compiles("
  383. #include <X11/Xlibint.h>
  384. extern int _XData32(Display *dpy,register _Xconst long *data,unsigned len);
  385. int main(int argc, char **argv) {}" HAVE_CONST_XDATA32)
  386. if(HAVE_CONST_XDATA32)
  387. set(SDL_VIDEO_DRIVER_X11_CONST_PARAM_XDATA32 1)
  388. endif(HAVE_CONST_XDATA32)
  389. check_function_exists(XkbKeycodeToKeysym SDL_VIDEO_DRIVER_X11_HAS_XKBKEYCODETOKEYSYM)
  390. if(VIDEO_X11_XCURSOR AND HAVE_XCURSOR_H)
  391. set(HAVE_VIDEO_X11_XCURSOR TRUE)
  392. if(HAVE_X11_SHARED AND XCURSOR_LIB)
  393. set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XCURSOR "\"${XCURSOR_LIB_SONAME}\"")
  394. else(HAVE_X11_SHARED AND XCURSOR_LIB)
  395. list(APPEND EXTRA_LIBS ${XCURSOR_LIB})
  396. endif(HAVE_X11_SHARED AND XCURSOR_LIB)
  397. set(SDL_VIDEO_DRIVER_X11_XCURSOR 1)
  398. endif(VIDEO_X11_XCURSOR AND HAVE_XCURSOR_H)
  399. if(VIDEO_X11_XINERAMA AND HAVE_XINERAMA_H)
  400. set(HAVE_VIDEO_X11_XINERAMA TRUE)
  401. if(HAVE_X11_SHARED AND XINERAMA_LIB)
  402. set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XINERAMA "\"${XINERAMA_LIB_SONAME}\"")
  403. else(HAVE_X11_SHARED AND XINERAMA_LIB)
  404. list(APPEND EXTRA_LIBS ${XINERAMA_LIB})
  405. endif(HAVE_X11_SHARED AND XINERAMA_LIB)
  406. set(SDL_VIDEO_DRIVER_X11_XINERAMA 1)
  407. endif(VIDEO_X11_XINERAMA AND HAVE_XINERAMA_H)
  408. if(VIDEO_X11_XINPUT AND HAVE_XINPUT_H)
  409. set(HAVE_VIDEO_X11_XINPUT TRUE)
  410. if(HAVE_X11_SHARED AND XI_LIB)
  411. set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT2 "\"${XI_LIB_SONAME}\"")
  412. else(HAVE_X11_SHARED AND XI_LIB)
  413. list(APPEND EXTRA_LIBS ${XI_LIB})
  414. endif(HAVE_X11_SHARED AND XI_LIB)
  415. set(SDL_VIDEO_DRIVER_X11_XINPUT2 1)
  416. # Check for multitouch
  417. check_c_source_compiles("
  418. #include <X11/Xlib.h>
  419. #include <X11/Xproto.h>
  420. #include <X11/extensions/XInput2.h>
  421. int event_type = XI_TouchBegin;
  422. XITouchClassInfo *t;
  423. Status XIAllowTouchEvents(Display *a,int b,unsigned int c,Window d,int f)
  424. {
  425. return (Status)0;
  426. }
  427. int main(int argc, char **argv) {}" HAVE_XINPUT2_MULTITOUCH)
  428. if(HAVE_XINPUT2_MULTITOUCH)
  429. set(SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH 1)
  430. endif(HAVE_XINPUT2_MULTITOUCH)
  431. endif(VIDEO_X11_XINPUT AND HAVE_XINPUT_H)
  432. if(VIDEO_X11_XRANDR AND HAVE_XRANDR_H)
  433. if(HAVE_X11_SHARED AND XRANDR_LIB)
  434. set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR "\"${XRANDR_LIB_SONAME}\"")
  435. else(HAVE_X11_SHARED AND XRANDR_LIB)
  436. list(APPEND EXTRA_LIBS ${XRANDR_LIB})
  437. endif(HAVE_X11_SHARED AND XRANDR_LIB)
  438. set(SDL_VIDEO_DRIVER_X11_XRANDR 1)
  439. set(HAVE_VIDEO_X11_XRANDR TRUE)
  440. endif(VIDEO_X11_XRANDR AND HAVE_XRANDR_H)
  441. if(VIDEO_X11_XSCRNSAVER AND HAVE_XSS_H)
  442. if(HAVE_X11_SHARED AND XSS_LIB)
  443. set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XSS "\"${XSS_LIB_SONAME}\"")
  444. else(HAVE_X11_SHARED AND XSS_LIB)
  445. list(APPEND EXTRA_LIBS ${XSS_LIB})
  446. endif(HAVE_X11_SHARED AND XSS_LIB)
  447. set(SDL_VIDEO_DRIVER_X11_XSCRNSAVER 1)
  448. set(HAVE_VIDEO_X11_XSCRNSAVER TRUE)
  449. endif(VIDEO_X11_XSCRNSAVER AND HAVE_XSS_H)
  450. if(VIDEO_X11_XSHAPE AND HAVE_XSHAPE_H)
  451. set(SDL_VIDEO_DRIVER_X11_XSHAPE 1)
  452. set(HAVE_VIDEO_X11_XSHAPE TRUE)
  453. endif(VIDEO_X11_XSHAPE AND HAVE_XSHAPE_H)
  454. if(VIDEO_X11_XVM AND HAVE_XF86VM_H)
  455. if(HAVE_X11_SHARED AND XXF86VM_LIB)
  456. set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XVIDMODE "\"${XXF86VM_LIB_SONAME}\"")
  457. else(HAVE_X11_SHARED AND XXF86VM_LIB)
  458. list(APPEND EXTRA_LIBS ${XXF86VM_LIB})
  459. endif(HAVE_X11_SHARED AND XXF86VM_LIB)
  460. set(SDL_VIDEO_DRIVER_X11_XVIDMODE 1)
  461. set(HAVE_VIDEO_X11_XVM TRUE)
  462. endif(VIDEO_X11_XVM AND HAVE_XF86VM_H)
  463. set(CMAKE_REQUIRED_LIBRARIES)
  464. endif(X11_LIB)
  465. endif(VIDEO_X11)
  466. endmacro(CheckX11)
  467. macro(CheckMir)
  468. # !!! FIXME: hook up dynamic loading here.
  469. if(VIDEO_MIR)
  470. find_library(MIR_LIB mirclient mircommon egl)
  471. pkg_check_modules(MIR_TOOLKIT mirclient mircommon)
  472. pkg_check_modules(EGL egl)
  473. pkg_check_modules(XKB xkbcommon)
  474. if (MIR_LIB AND MIR_TOOLKIT_FOUND AND EGL_FOUND AND XKB_FOUND)
  475. set(HAVE_VIDEO_MIR TRUE)
  476. set(HAVE_SDL_VIDEO TRUE)
  477. file(GLOB MIR_SOURCES ${SDL2_SOURCE_DIR}/src/video/mir/*.c)
  478. set(SOURCE_FILES ${SOURCE_FILES} ${MIR_SOURCES})
  479. set(SDL_VIDEO_DRIVER_MIR 1)
  480. list(APPEND EXTRA_CFLAGS ${MIR_TOOLKIT_CFLAGS} ${EGL_CLFAGS} ${XKB_CLFLAGS})
  481. list(APPEND EXTRA_LDFLAGS ${MIR_TOOLKIT_LDFLAGS} ${EGL_LDLAGS} ${XKB_LDLAGS})
  482. endif (MIR_LIB AND MIR_TOOLKIT_FOUND AND EGL_FOUND AND XKB_FOUND)
  483. endif(VIDEO_MIR)
  484. endmacro(CheckMir)
  485. # Requires:
  486. # - EGL
  487. macro(CheckWayland)
  488. # !!! FIXME: hook up dynamic loading here.
  489. if(VIDEO_WAYLAND)
  490. pkg_check_modules(WAYLAND wayland-client wayland-cursor wayland-egl egl xkbcommon)
  491. if(WAYLAND_FOUND)
  492. link_directories(
  493. ${WAYLAND_LIBRARY_DIRS}
  494. )
  495. include_directories(
  496. ${WAYLAND_INCLUDE_DIRS}
  497. )
  498. set(EXTRA_LIBS ${WAYLAND_LIBRARIES} ${EXTRA_LIBS})
  499. set(HAVE_VIDEO_WAYLAND TRUE)
  500. set(HAVE_SDL_VIDEO TRUE)
  501. file(GLOB WAYLAND_SOURCES ${SDL2_SOURCE_DIR}/src/video/wayland/*.c)
  502. set(SOURCE_FILES ${SOURCE_FILES} ${WAYLAND_SOURCES})
  503. set(SDL_VIDEO_DRIVER_WAYLAND 1)
  504. endif(WAYLAND_FOUND)
  505. endif(VIDEO_WAYLAND)
  506. endmacro(CheckWayland)
  507. # Requires:
  508. # - n/a
  509. #
  510. macro(CheckCOCOA)
  511. if(VIDEO_COCOA)
  512. if(APPLE) # Apple always has Cocoa.
  513. set(HAVE_VIDEO_COCOA TRUE)
  514. endif(APPLE)
  515. if(HAVE_VIDEO_COCOA)
  516. file(GLOB COCOA_SOURCES ${SDL2_SOURCE_DIR}/src/video/cocoa/*.m)
  517. set_source_files_properties(${COCOA_SOURCES} PROPERTIES LANGUAGE C)
  518. set(SOURCE_FILES ${SOURCE_FILES} ${COCOA_SOURCES})
  519. set(SDL_VIDEO_DRIVER_COCOA 1)
  520. set(HAVE_SDL_VIDEO TRUE)
  521. endif(HAVE_VIDEO_COCOA)
  522. endif(VIDEO_COCOA)
  523. endmacro(CheckCOCOA)
  524. # Requires:
  525. # - PkgCheckModules
  526. # Optional:
  527. # - DIRECTFB_SHARED opt
  528. # - HAVE_DLOPEN opt
  529. macro(CheckDirectFB)
  530. if(VIDEO_DIRECTFB)
  531. pkg_check_modules(PKG_DIRECTFB directfb>=1.0.0)
  532. if(PKG_DIRECTFB_FOUND)
  533. set(HAVE_VIDEO_DIRECTFB TRUE)
  534. file(GLOB DIRECTFB_SOURCES ${SDL2_SOURCE_DIR}/src/video/directfb/*.c)
  535. set(SOURCE_FILES ${SOURCE_FILES} ${DIRECTFB_SOURCES})
  536. set(SDL_VIDEO_DRIVER_DIRECTFB 1)
  537. set(SDL_VIDEO_RENDER_DIRECTFB 1)
  538. list(APPEND EXTRA_CFLAGS ${PKG_DIRECTFB_CFLAGS})
  539. if(DIRECTFB_SHARED)
  540. if(NOT HAVE_DLOPEN)
  541. message_warn("You must have SDL_LoadObject() support for dynamic DirectFB loading")
  542. else()
  543. FindLibraryAndSONAME("directfb")
  544. set(SDL_VIDEO_DRIVER_DIRECTFB_DYNAMIC "\"${DIRECTFB_LIB_SONAME}\"")
  545. set(HAVE_DIRECTFB_SHARED TRUE)
  546. endif(NOT HAVE_DLOPEN)
  547. else(DIRECTFB_SHARED)
  548. list(APPEND EXTRA_LDFLAGS ${PKG_DIRECTFB_LDFLAGS})
  549. endif(DIRECTFB_SHARED)
  550. set(HAVE_SDL_VIDEO TRUE)
  551. endif(PKG_DIRECTFB_FOUND)
  552. endif(VIDEO_DIRECTFB)
  553. endmacro(CheckDirectFB)
  554. # Requires:
  555. # - nada
  556. macro(CheckOpenGLX11)
  557. if(VIDEO_OPENGL)
  558. check_c_source_compiles("
  559. #include <GL/gl.h>
  560. #include <GL/glx.h>
  561. int main(int argc, char** argv) {}" HAVE_VIDEO_OPENGL)
  562. if(HAVE_VIDEO_OPENGL)
  563. set(HAVE_VIDEO_OPENGL TRUE)
  564. set(SDL_VIDEO_OPENGL 1)
  565. set(SDL_VIDEO_OPENGL_GLX 1)
  566. set(SDL_VIDEO_RENDER_OGL 1)
  567. list(APPEND EXTRA_LIBS GL)
  568. endif(HAVE_VIDEO_OPENGL)
  569. endif(VIDEO_OPENGL)
  570. endmacro(CheckOpenGLX11)
  571. # Requires:
  572. # - nada
  573. macro(CheckOpenGLESX11)
  574. if(VIDEO_OPENGLES)
  575. check_c_source_compiles("
  576. #include <EGL/egl.h>
  577. int main (int argc, char** argv) {}" HAVE_VIDEO_OPENGL_EGL)
  578. if(HAVE_VIDEO_OPENGL_EGL)
  579. set(SDL_VIDEO_OPENGL_EGL 1)
  580. endif(HAVE_VIDEO_OPENGL_EGL)
  581. check_c_source_compiles("
  582. #include <GLES/gl.h>
  583. #include <GLES/glext.h>
  584. int main (int argc, char** argv) {}" HAVE_VIDEO_OPENGLES_V1)
  585. if(HAVE_VIDEO_OPENGLES_V1)
  586. set(HAVE_VIDEO_OPENGLES TRUE)
  587. set(SDL_VIDEO_OPENGL_ES 1)
  588. set(SDL_VIDEO_RENDER_OGL_ES 1)
  589. endif(HAVE_VIDEO_OPENGLES_V1)
  590. check_c_source_compiles("
  591. #include <GLES2/gl2.h>
  592. #include <GLES2/gl2ext.h>
  593. int main (int argc, char** argv) {}" HAVE_VIDEO_OPENGLES_V2)
  594. if(HAVE_VIDEO_OPENGLES_V2)
  595. set(HAVE_VIDEO_OPENGLES TRUE)
  596. set(SDL_VIDEO_OPENGL_ES2 1)
  597. set(SDL_VIDEO_RENDER_OGL_ES2 1)
  598. endif(HAVE_VIDEO_OPENGLES_V2)
  599. endif(VIDEO_OPENGLES)
  600. endmacro(CheckOpenGLESX11)
  601. # Rquires:
  602. # - nada
  603. # Optional:
  604. # - THREADS opt
  605. # Sets:
  606. # PTHREAD_CFLAGS
  607. # PTHREAD_LIBS
  608. macro(CheckPTHREAD)
  609. if(PTHREADS)
  610. if(LINUX)
  611. set(PTHREAD_CFLAGS "-D_REENTRANT")
  612. set(PTHREAD_LDFLAGS "-pthread")
  613. elseif(BSDI)
  614. set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
  615. set(PTHREAD_LDFLAGS "")
  616. elseif(DARWIN)
  617. set(PTHREAD_CFLAGS "-D_THREAD_SAFE")
  618. # causes Carbon.p complaints?
  619. # set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
  620. set(PTHREAD_LDFLAGS "")
  621. elseif(FREEBSD)
  622. set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
  623. set(PTHREAD_LDFLAGS "-pthread")
  624. elseif(NETBSD)
  625. set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
  626. set(PTHREAD_LDFLAGS "-lpthread")
  627. elseif(OPENBSD)
  628. set(PTHREAD_CFLAGS "-D_REENTRANT")
  629. set(PTHREAD_LDFLAGS "-pthread")
  630. elseif(SOLARIS)
  631. set(PTHREAD_CFLAGS "-D_REENTRANT")
  632. set(PTHREAD_LDFLAGS "-pthread -lposix4")
  633. elseif(SYSV5)
  634. set(PTHREAD_CFLAGS "-D_REENTRANT -Kthread")
  635. set(PTHREAD_LDFLAGS "")
  636. elseif(AIX)
  637. set(PTHREAD_CFLAGS "-D_REENTRANT -mthreads")
  638. set(PTHREAD_LDFLAGS "-pthread")
  639. elseif(HPUX)
  640. set(PTHREAD_CFLAGS "-D_REENTRANT")
  641. set(PTHREAD_LDFLAGS "-L/usr/lib -pthread")
  642. elseif(HAIKU)
  643. set(PTHREAD_CFLAGS "-D_REENTRANT")
  644. set(PTHREAD_LDFLAGS "")
  645. else()
  646. set(PTHREAD_CFLAGS "-D_REENTRANT")
  647. set(PTHREAD_LDFLAGS "-lpthread")
  648. endif(LINUX)
  649. # Run some tests
  650. set(CMAKE_REQUIRED_FLAGS "${PTHREAD_CFLAGS} ${PTHREAD_LDFLAGS}")
  651. check_c_source_runs("
  652. #include <pthread.h>
  653. int main(int argc, char** argv) {
  654. pthread_attr_t type;
  655. pthread_attr_init(&type);
  656. return 0;
  657. }" HAVE_PTHREADS)
  658. if(HAVE_PTHREADS)
  659. set(SDL_THREAD_PTHREAD 1)
  660. list(APPEND EXTRA_CFLAGS ${PTHREAD_CFLAGS})
  661. list(APPEND EXTRA_LDFLAGS ${PTHREAD_LDFLAGS})
  662. set(SDL_CFLAGS "${SDL_CFLAGS} ${PTHREAD_CFLAGS}")
  663. list(APPEND SDL_LIBS ${PTHREAD_LDFLAGS})
  664. check_c_source_compiles("
  665. #include <pthread.h>
  666. int main(int argc, char **argv) {
  667. pthread_mutexattr_t attr;
  668. pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
  669. return 0;
  670. }" HAVE_RECURSIVE_MUTEXES)
  671. if(HAVE_RECURSIVE_MUTEXES)
  672. set(SDL_THREAD_PTHREAD_RECURSIVE_MUTEX 1)
  673. else(HAVE_RECURSIVE_MUTEXES)
  674. check_c_source_compiles("
  675. #include <pthread.h>
  676. int main(int argc, char **argv) {
  677. pthread_mutexattr_t attr;
  678. pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
  679. return 0;
  680. }" HAVE_RECURSIVE_MUTEXES_NP)
  681. if(HAVE_RECURSIVE_MUTEXES_NP)
  682. set(SDL_THREAD_PTHREAD_RECURSIVE_MUTEX_NP 1)
  683. endif(HAVE_RECURSIVE_MUTEXES_NP)
  684. endif(HAVE_RECURSIVE_MUTEXES)
  685. if(PTHREADS_SEM)
  686. check_c_source_compiles("#include <pthread.h>
  687. #include <semaphore.h>
  688. int main(int argc, char **argv) { return 0; }" HAVE_PTHREADS_SEM)
  689. if(HAVE_PTHREADS_SEM)
  690. check_c_source_compiles("
  691. #include <pthread.h>
  692. #include <semaphore.h>
  693. int main(int argc, char **argv) {
  694. sem_timedwait(NULL, NULL);
  695. return 0;
  696. }" HAVE_SEM_TIMEDWAIT)
  697. endif(HAVE_PTHREADS_SEM)
  698. endif(PTHREADS_SEM)
  699. check_c_source_compiles("
  700. #include <pthread.h>
  701. int main(int argc, char** argv) {
  702. pthread_spin_trylock(NULL);
  703. return 0;
  704. }" HAVE_PTHREAD_SPINLOCK)
  705. check_c_source_compiles("
  706. #include <pthread.h>
  707. #include <pthread_np.h>
  708. int main(int argc, char** argv) { return 0; }" HAVE_PTHREAD_NP_H)
  709. check_function_exists(pthread_setname_np HAVE_PTHREAD_setNAME_NP)
  710. check_function_exists(pthread_set_name_np HAVE_PTHREAD_set_NAME_NP)
  711. set(CMAKE_REQUIRED_FLAGS)
  712. set(SOURCE_FILES ${SOURCE_FILES}
  713. ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_systhread.c
  714. ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_sysmutex.c # Can be faked, if necessary
  715. ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_syscond.c # Can be faked, if necessary
  716. ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_systls.c
  717. )
  718. if(HAVE_PTHREADS_SEM)
  719. set(SOURCE_FILES ${SOURCE_FILES}
  720. ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_syssem.c)
  721. else(HAVE_PTHREADS_SEM)
  722. set(SOURCE_FILES ${SOURCE_FILES}
  723. ${SDL2_SOURCE_DIR}/src/thread/generic/SDL_syssem.c)
  724. endif(HAVE_PTHREADS_SEM)
  725. set(HAVE_SDL_THREADS TRUE)
  726. endif(HAVE_PTHREADS)
  727. endif(PTHREADS)
  728. endmacro(CheckPTHREAD)
  729. # Requires
  730. # - nada
  731. # Optional:
  732. # Sets:
  733. # USB_LIBS
  734. # USB_CFLAGS
  735. macro(CheckUSBHID)
  736. check_library_exists(usbhid hid_init "" LIBUSBHID)
  737. if(LIBUSBHID)
  738. check_include_file(usbhid.h HAVE_USBHID_H)
  739. if(HAVE_USBHID_H)
  740. set(USB_CFLAGS "-DHAVE_USBHID_H")
  741. endif(HAVE_USBHID_H)
  742. check_include_file(libusbhid.h HAVE_LIBUSBHID_H)
  743. if(HAVE_LIBUSBHID_H)
  744. set(USB_CFLAGS "${USB_CFLAGS} -DHAVE_LIBUSBHID_H")
  745. endif(HAVE_LIBUSBHID_H)
  746. set(USB_LIBS ${USB_LIBS} usbhid)
  747. else(LIBUSBHID)
  748. check_include_file(usb.h HAVE_USB_H)
  749. if(HAVE_USB_H)
  750. set(USB_CFLAGS "-DHAVE_USB_H")
  751. endif(HAVE_USB_H)
  752. check_include_file(libusb.h HAVE_LIBUSB_H)
  753. if(HAVE_LIBUSB_H)
  754. set(USB_CFLAGS "${USB_CFLAGS} -DHAVE_LIBUSB_H")
  755. endif(HAVE_LIBUSB_H)
  756. check_library_exists(usb hid_init "" LIBUSB)
  757. if(LIBUSB)
  758. set(USB_LIBS ${USB_LIBS} usb)
  759. endif(LIBUSB)
  760. endif(LIBUSBHID)
  761. set(CMAKE_REQUIRED_FLAGS "${USB_CFLAGS}")
  762. set(CMAKE_REQUIRED_LIBRARIES "${USB_LIBS}")
  763. check_c_source_compiles("
  764. #include <sys/types.h>
  765. #if defined(HAVE_USB_H)
  766. #include <usb.h>
  767. #endif
  768. #ifdef __DragonFly__
  769. # include <bus/usb/usb.h>
  770. # include <bus/usb/usbhid.h>
  771. #else
  772. # include <dev/usb/usb.h>
  773. # include <dev/usb/usbhid.h>
  774. #endif
  775. #if defined(HAVE_USBHID_H)
  776. #include <usbhid.h>
  777. #elif defined(HAVE_LIBUSB_H)
  778. #include <libusb.h>
  779. #elif defined(HAVE_LIBUSBHID_H)
  780. #include <libusbhid.h>
  781. #endif
  782. int main(int argc, char **argv) {
  783. struct report_desc *repdesc;
  784. struct usb_ctl_report *repbuf;
  785. hid_kind_t hidkind;
  786. return 0;
  787. }" HAVE_USBHID)
  788. if(HAVE_USBHID)
  789. check_c_source_compiles("
  790. #include <sys/types.h>
  791. #if defined(HAVE_USB_H)
  792. #include <usb.h>
  793. #endif
  794. #ifdef __DragonFly__
  795. # include <bus/usb/usb.h>
  796. # include <bus/usb/usbhid.h>
  797. #else
  798. # include <dev/usb/usb.h>
  799. # include <dev/usb/usbhid.h>
  800. #endif
  801. #if defined(HAVE_USBHID_H)
  802. #include <usbhid.h>
  803. #elif defined(HAVE_LIBUSB_H)
  804. #include <libusb.h>
  805. #elif defined(HAVE_LIBUSBHID_H)
  806. #include <libusbhid.h>
  807. #endif
  808. int main(int argc, char** argv) {
  809. struct usb_ctl_report buf;
  810. if (buf.ucr_data) { }
  811. return 0;
  812. }" HAVE_USBHID_UCR_DATA)
  813. if(HAVE_USBHID_UCR_DATA)
  814. set(USB_CFLAGS "${USB_CFLAGS} -DUSBHID_UCR_DATA")
  815. endif(HAVE_USBHID_UCR_DATA)
  816. check_c_source_compiles("
  817. #include <sys/types.h>
  818. #if defined(HAVE_USB_H)
  819. #include <usb.h>
  820. #endif
  821. #ifdef __DragonFly__
  822. #include <bus/usb/usb.h>
  823. #include <bus/usb/usbhid.h>
  824. #else
  825. #include <dev/usb/usb.h>
  826. #include <dev/usb/usbhid.h>
  827. #endif
  828. #if defined(HAVE_USBHID_H)
  829. #include <usbhid.h>
  830. #elif defined(HAVE_LIBUSB_H)
  831. #include <libusb.h>
  832. #elif defined(HAVE_LIBUSBHID_H)
  833. #include <libusbhid.h>
  834. #endif
  835. int main(int argc, char **argv) {
  836. report_desc_t d;
  837. hid_start_parse(d, 1, 1);
  838. return 0;
  839. }" HAVE_USBHID_NEW)
  840. if(HAVE_USBHID_NEW)
  841. set(USB_CFLAGS "${USB_CFLAGS} -DUSBHID_NEW")
  842. endif(HAVE_USBHID_NEW)
  843. check_c_source_compiles("
  844. #include <machine/joystick.h>
  845. int main(int argc, char** argv) {
  846. struct joystick t;
  847. return 0;
  848. }" HAVE_MACHINE_JOYSTICK)
  849. if(HAVE_MACHINE_JOYSTICK)
  850. set(SDL_JOYSTICK_USBHID_MACHINE_JOYSTICK_H 1)
  851. endif(HAVE_MACHINE_JOYSTICK)
  852. set(SDL_JOYSTICK_USBHID 1)
  853. file(GLOB BSD_JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/bsd/*.c)
  854. set(SOURCE_FILES ${SOURCE_FILES} ${BSD_JOYSTICK_SOURCES})
  855. list(APPEND EXTRA_CFLAGS ${USB_CFLAGS})
  856. list(APPEND EXTRA_LIBS ${USB_LIBS})
  857. set(HAVE_SDL_JOYSTICK TRUE)
  858. set(CMAKE_REQUIRED_LIBRARIES)
  859. set(CMAKE_REQUIRED_FLAGS)
  860. endif(HAVE_USBHID)
  861. endmacro(CheckUSBHID)