🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1175 lines
37 KiB

  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. /usr/pkg/xorg/include
  365. /usr/X11R6/include
  366. /usr/X11R7/include
  367. /usr/local/include/X11
  368. /usr/include/X11
  369. /usr/openwin/include
  370. /usr/openwin/share/include
  371. /opt/graphics/OpenGL/include
  372. /opt/X11/include
  373. )
  374. if(X_INCLUDEDIR)
  375. list(APPEND EXTRA_CFLAGS "-I${X_INCLUDEDIR}")
  376. list(APPEND CMAKE_REQUIRED_INCLUDES "${X_INCLUDEDIR}")
  377. endif()
  378. check_include_file(X11/Xcursor/Xcursor.h HAVE_XCURSOR_H)
  379. check_include_file(X11/extensions/Xinerama.h HAVE_XINERAMA_H)
  380. check_include_file(X11/extensions/XInput2.h HAVE_XINPUT_H)
  381. check_include_file(X11/extensions/Xrandr.h HAVE_XRANDR_H)
  382. check_include_file(X11/extensions/Xrender.h HAVE_XRENDER_H)
  383. check_include_file(X11/extensions/scrnsaver.h HAVE_XSS_H)
  384. check_include_file(X11/extensions/shape.h HAVE_XSHAPE_H)
  385. check_include_files("X11/Xlib.h;X11/extensions/xf86vmode.h" HAVE_XF86VM_H)
  386. check_include_files("X11/Xlib.h;X11/Xproto.h;X11/extensions/Xext.h" HAVE_XEXT_H)
  387. if(X11_LIB)
  388. if(NOT HAVE_XEXT_H)
  389. message_error("Missing Xext.h, maybe you need to install the libxext-dev package?")
  390. endif()
  391. set(HAVE_VIDEO_X11 TRUE)
  392. set(HAVE_SDL_VIDEO TRUE)
  393. file(GLOB X11_SOURCES ${SDL2_SOURCE_DIR}/src/video/x11/*.c)
  394. set(SOURCE_FILES ${SOURCE_FILES} ${X11_SOURCES})
  395. set(SDL_VIDEO_DRIVER_X11 1)
  396. if(APPLE)
  397. set(X11_SHARED OFF)
  398. endif()
  399. check_function_exists("shmat" HAVE_SHMAT)
  400. if(NOT HAVE_SHMAT)
  401. check_library_exists(ipc shmat "" HAVE_SHMAT)
  402. if(HAVE_SHMAT)
  403. list(APPEND EXTRA_LIBS ipc)
  404. endif()
  405. if(NOT HAVE_SHMAT)
  406. add_definitions(-DNO_SHARED_MEMORY)
  407. list(APPEND EXTRA_CFLAGS "-DNO_SHARED_MEMORY")
  408. endif()
  409. endif()
  410. if(X11_SHARED)
  411. if(NOT HAVE_DLOPEN)
  412. message_warn("You must have SDL_LoadObject() support for dynamic X11 loading")
  413. set(HAVE_X11_SHARED FALSE)
  414. else()
  415. set(HAVE_X11_SHARED TRUE)
  416. endif()
  417. if(HAVE_X11_SHARED)
  418. set(SDL_VIDEO_DRIVER_X11_DYNAMIC "\"${X11_LIB_SONAME}\"")
  419. set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT "\"${XEXT_LIB_SONAME}\"")
  420. else()
  421. list(APPEND EXTRA_LIBS ${X11_LIB} ${XEXT_LIB})
  422. endif()
  423. endif()
  424. set(CMAKE_REQUIRED_LIBRARIES ${X11_LIB} ${X11_LIB})
  425. check_c_source_compiles("
  426. #include <X11/Xlib.h>
  427. #include <X11/Xproto.h>
  428. #include <X11/extensions/Xext.h>
  429. #include <X11/extensions/extutil.h>
  430. extern XExtDisplayInfo* XextAddDisplay(XExtensionInfo* a,Display* b,_Xconst char* c,XExtensionHooks* d,int e,XPointer f);
  431. int main(int argc, char **argv) {}" HAVE_CONST_XEXT_ADDDISPLAY)
  432. if(HAVE_CONST_XEXT_ADDDISPLAY)
  433. set(SDL_VIDEO_DRIVER_X11_CONST_PARAM_XEXTADDDISPLAY 1)
  434. endif()
  435. check_c_source_compiles("
  436. #include <X11/Xlib.h>
  437. int main(int argc, char **argv) {
  438. Display *display;
  439. XEvent event;
  440. XGenericEventCookie *cookie = &event.xcookie;
  441. XNextEvent(display, &event);
  442. XGetEventData(display, cookie);
  443. XFreeEventData(display, cookie); }" HAVE_XGENERICEVENT)
  444. if(HAVE_XGENERICEVENT)
  445. set(SDL_VIDEO_DRIVER_X11_SUPPORTS_GENERIC_EVENTS 1)
  446. endif()
  447. check_function_exists(XkbKeycodeToKeysym SDL_VIDEO_DRIVER_X11_HAS_XKBKEYCODETOKEYSYM)
  448. if(VIDEO_X11_XCURSOR AND HAVE_XCURSOR_H)
  449. set(HAVE_VIDEO_X11_XCURSOR TRUE)
  450. if(HAVE_X11_SHARED AND XCURSOR_LIB)
  451. set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XCURSOR "\"${XCURSOR_LIB_SONAME}\"")
  452. else()
  453. list(APPEND EXTRA_LIBS ${XCURSOR_LIB})
  454. endif()
  455. set(SDL_VIDEO_DRIVER_X11_XCURSOR 1)
  456. endif()
  457. if(VIDEO_X11_XINERAMA AND HAVE_XINERAMA_H)
  458. set(HAVE_VIDEO_X11_XINERAMA TRUE)
  459. if(HAVE_X11_SHARED AND XINERAMA_LIB)
  460. set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XINERAMA "\"${XINERAMA_LIB_SONAME}\"")
  461. else()
  462. list(APPEND EXTRA_LIBS ${XINERAMA_LIB})
  463. endif()
  464. set(SDL_VIDEO_DRIVER_X11_XINERAMA 1)
  465. endif()
  466. if(VIDEO_X11_XINPUT AND HAVE_XINPUT_H)
  467. set(HAVE_VIDEO_X11_XINPUT TRUE)
  468. if(HAVE_X11_SHARED AND XI_LIB)
  469. set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT2 "\"${XI_LIB_SONAME}\"")
  470. else()
  471. list(APPEND EXTRA_LIBS ${XI_LIB})
  472. endif()
  473. set(SDL_VIDEO_DRIVER_X11_XINPUT2 1)
  474. # Check for multitouch
  475. check_c_source_compiles("
  476. #include <X11/Xlib.h>
  477. #include <X11/Xproto.h>
  478. #include <X11/extensions/XInput2.h>
  479. int event_type = XI_TouchBegin;
  480. XITouchClassInfo *t;
  481. Status XIAllowTouchEvents(Display *a,int b,unsigned int c,Window d,int f)
  482. {
  483. return (Status)0;
  484. }
  485. int main(int argc, char **argv) {}" HAVE_XINPUT2_MULTITOUCH)
  486. if(HAVE_XINPUT2_MULTITOUCH)
  487. set(SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH 1)
  488. endif()
  489. endif()
  490. if(VIDEO_X11_XRANDR AND HAVE_XRANDR_H)
  491. if(HAVE_X11_SHARED AND XRANDR_LIB)
  492. set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR "\"${XRANDR_LIB_SONAME}\"")
  493. else()
  494. list(APPEND EXTRA_LIBS ${XRANDR_LIB})
  495. endif()
  496. set(SDL_VIDEO_DRIVER_X11_XRANDR 1)
  497. set(HAVE_VIDEO_X11_XRANDR TRUE)
  498. endif()
  499. if(VIDEO_X11_XSCRNSAVER AND HAVE_XSS_H)
  500. if(HAVE_X11_SHARED AND XSS_LIB)
  501. set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XSS "\"${XSS_LIB_SONAME}\"")
  502. else()
  503. list(APPEND EXTRA_LIBS ${XSS_LIB})
  504. endif()
  505. set(SDL_VIDEO_DRIVER_X11_XSCRNSAVER 1)
  506. set(HAVE_VIDEO_X11_XSCRNSAVER TRUE)
  507. endif()
  508. if(VIDEO_X11_XSHAPE AND HAVE_XSHAPE_H)
  509. set(SDL_VIDEO_DRIVER_X11_XSHAPE 1)
  510. set(HAVE_VIDEO_X11_XSHAPE TRUE)
  511. endif()
  512. if(VIDEO_X11_XVM AND HAVE_XF86VM_H)
  513. if(HAVE_X11_SHARED AND XXF86VM_LIB)
  514. set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XVIDMODE "\"${XXF86VM_LIB_SONAME}\"")
  515. else()
  516. list(APPEND EXTRA_LIBS ${XXF86VM_LIB})
  517. endif()
  518. set(SDL_VIDEO_DRIVER_X11_XVIDMODE 1)
  519. set(HAVE_VIDEO_X11_XVM TRUE)
  520. endif()
  521. set(CMAKE_REQUIRED_LIBRARIES)
  522. endif()
  523. endif()
  524. endmacro()
  525. macro(WaylandProtocolGen _SCANNER _XML _PROTL)
  526. set(_WAYLAND_PROT_C_CODE "${CMAKE_CURRENT_BINARY_DIR}/wayland-generated-protocols/${_PROTL}-protocol.c")
  527. set(_WAYLAND_PROT_H_CODE "${CMAKE_CURRENT_BINARY_DIR}/wayland-generated-protocols/${_PROTL}-client-protocol.h")
  528. add_custom_command(
  529. OUTPUT "${_WAYLAND_PROT_H_CODE}"
  530. DEPENDS "${_XML}"
  531. COMMAND "${_SCANNER}"
  532. ARGS client-header "${_XML}" "${_WAYLAND_PROT_H_CODE}"
  533. )
  534. add_custom_command(
  535. OUTPUT "${_WAYLAND_PROT_C_CODE}"
  536. DEPENDS "${_WAYLAND_PROT_H_CODE}"
  537. COMMAND "${_SCANNER}"
  538. ARGS code "${_XML}" "${_WAYLAND_PROT_C_CODE}"
  539. )
  540. set(SOURCE_FILES ${SOURCE_FILES} "${_WAYLAND_PROT_C_CODE}")
  541. endmacro()
  542. # Requires:
  543. # - EGL
  544. # - PkgCheckModules
  545. # Optional:
  546. # - WAYLAND_SHARED opt
  547. # - HAVE_DLOPEN opt
  548. macro(CheckWayland)
  549. if(VIDEO_WAYLAND)
  550. pkg_check_modules(WAYLAND wayland-client wayland-scanner wayland-protocols wayland-egl wayland-cursor egl xkbcommon)
  551. if(WAYLAND_FOUND)
  552. execute_process(
  553. COMMAND ${PKG_CONFIG_EXECUTABLE} --variable=wayland_scanner wayland-scanner
  554. WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
  555. RESULT_VARIABLE WAYLAND_SCANNER_RC
  556. OUTPUT_VARIABLE WAYLAND_SCANNER
  557. ERROR_QUIET
  558. OUTPUT_STRIP_TRAILING_WHITESPACE
  559. )
  560. if(NOT WAYLAND_SCANNER_RC EQUAL 0)
  561. set(WAYLAND_FOUND FALSE)
  562. endif()
  563. endif()
  564. if(WAYLAND_FOUND)
  565. link_directories(
  566. ${WAYLAND_LIBRARY_DIRS}
  567. )
  568. include_directories(
  569. ${WAYLAND_INCLUDE_DIRS}
  570. )
  571. set(HAVE_VIDEO_WAYLAND TRUE)
  572. set(HAVE_SDL_VIDEO TRUE)
  573. file(GLOB WAYLAND_SOURCES ${SDL2_SOURCE_DIR}/src/video/wayland/*.c)
  574. set(SOURCE_FILES ${SOURCE_FILES} ${WAYLAND_SOURCES})
  575. # We have to generate some protocol interface code for some unstable Wayland features.
  576. file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/wayland-generated-protocols")
  577. include_directories("${CMAKE_CURRENT_BINARY_DIR}/wayland-generated-protocols")
  578. file(GLOB WAYLAND_PROTOCOLS_XML RELATIVE "${SDL2_SOURCE_DIR}/wayland-protocols/" "${SDL2_SOURCE_DIR}/wayland-protocols/*.xml")
  579. foreach(_XML ${WAYLAND_PROTOCOLS_XML})
  580. string(REGEX REPLACE "\\.xml$" "" _PROTL "${_XML}")
  581. WaylandProtocolGen("${WAYLAND_SCANNER}" "${SDL2_SOURCE_DIR}/wayland-protocols/${_XML}" "${_PROTL}")
  582. endforeach()
  583. if(VIDEO_WAYLAND_QT_TOUCH)
  584. set(SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH 1)
  585. endif()
  586. if(WAYLAND_SHARED)
  587. if(NOT HAVE_DLOPEN)
  588. message_warn("You must have SDL_LoadObject() support for dynamic Wayland loading")
  589. else()
  590. FindLibraryAndSONAME(wayland-client)
  591. FindLibraryAndSONAME(wayland-egl)
  592. FindLibraryAndSONAME(wayland-cursor)
  593. FindLibraryAndSONAME(xkbcommon)
  594. set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC "\"${WAYLAND_CLIENT_LIB_SONAME}\"")
  595. set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_EGL "\"${WAYLAND_EGL_LIB_SONAME}\"")
  596. set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_CURSOR "\"${WAYLAND_CURSOR_LIB_SONAME}\"")
  597. set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_XKBCOMMON "\"${XKBCOMMON_LIB_SONAME}\"")
  598. set(HAVE_WAYLAND_SHARED TRUE)
  599. endif()
  600. else()
  601. set(EXTRA_LIBS ${WAYLAND_LIBRARIES} ${EXTRA_LIBS})
  602. endif()
  603. set(SDL_VIDEO_DRIVER_WAYLAND 1)
  604. endif()
  605. endif()
  606. endmacro()
  607. # Requires:
  608. # - n/a
  609. #
  610. macro(CheckCOCOA)
  611. if(VIDEO_COCOA)
  612. if(APPLE) # Apple always has Cocoa.
  613. set(HAVE_VIDEO_COCOA TRUE)
  614. endif()
  615. if(HAVE_VIDEO_COCOA)
  616. file(GLOB COCOA_SOURCES ${SDL2_SOURCE_DIR}/src/video/cocoa/*.m)
  617. set_source_files_properties(${COCOA_SOURCES} PROPERTIES LANGUAGE C)
  618. set(SOURCE_FILES ${SOURCE_FILES} ${COCOA_SOURCES})
  619. set(SDL_VIDEO_DRIVER_COCOA 1)
  620. set(HAVE_SDL_VIDEO TRUE)
  621. endif()
  622. endif()
  623. endmacro()
  624. # Requires:
  625. # - PkgCheckModules
  626. # Optional:
  627. # - DIRECTFB_SHARED opt
  628. # - HAVE_DLOPEN opt
  629. macro(CheckDirectFB)
  630. if(VIDEO_DIRECTFB)
  631. pkg_check_modules(PKG_DIRECTFB directfb>=1.0.0)
  632. if(PKG_DIRECTFB_FOUND)
  633. set(HAVE_VIDEO_DIRECTFB TRUE)
  634. file(GLOB DIRECTFB_SOURCES ${SDL2_SOURCE_DIR}/src/video/directfb/*.c)
  635. set(SOURCE_FILES ${SOURCE_FILES} ${DIRECTFB_SOURCES})
  636. set(SDL_VIDEO_DRIVER_DIRECTFB 1)
  637. set(SDL_VIDEO_RENDER_DIRECTFB 1)
  638. list(APPEND EXTRA_CFLAGS ${PKG_DIRECTFB_CFLAGS})
  639. if(DIRECTFB_SHARED)
  640. if(NOT HAVE_DLOPEN)
  641. message_warn("You must have SDL_LoadObject() support for dynamic DirectFB loading")
  642. else()
  643. FindLibraryAndSONAME("directfb")
  644. set(SDL_VIDEO_DRIVER_DIRECTFB_DYNAMIC "\"${DIRECTFB_LIB_SONAME}\"")
  645. set(HAVE_DIRECTFB_SHARED TRUE)
  646. endif()
  647. else()
  648. list(APPEND EXTRA_LDFLAGS ${PKG_DIRECTFB_LDFLAGS})
  649. endif()
  650. set(HAVE_SDL_VIDEO TRUE)
  651. endif()
  652. endif()
  653. endmacro()
  654. # Requires:
  655. # - n/a
  656. macro(CheckVivante)
  657. if(VIDEO_VIVANTE)
  658. check_c_source_compiles("
  659. #include <gc_vdk.h>
  660. int main(int argc, char** argv) {}" HAVE_VIDEO_VIVANTE_VDK)
  661. check_c_source_compiles("
  662. #define LINUX
  663. #define EGL_API_FB
  664. #include <EGL/eglvivante.h>
  665. int main(int argc, char** argv) {}" HAVE_VIDEO_VIVANTE_EGL_FB)
  666. if(HAVE_VIDEO_VIVANTE_VDK OR HAVE_VIDEO_VIVANTE_EGL_FB)
  667. set(HAVE_VIDEO_VIVANTE TRUE)
  668. set(HAVE_SDL_VIDEO TRUE)
  669. file(GLOB VIVANTE_SOURCES ${SDL2_SOURCE_DIR}/src/video/vivante/*.c)
  670. set(SOURCE_FILES ${SOURCE_FILES} ${VIVANTE_SOURCES})
  671. set(SDL_VIDEO_DRIVER_VIVANTE 1)
  672. if(HAVE_VIDEO_VIVANTE_VDK)
  673. set(SDL_VIDEO_DRIVER_VIVANTE_VDK 1)
  674. list(APPEND EXTRA_LIBS VDK VIVANTE)
  675. else()
  676. set(SDL_CFLAGS "${SDL_CFLAGS} -DLINUX -DEGL_API_FB")
  677. list(APPEND EXTRA_LIBS EGL)
  678. endif(HAVE_VIDEO_VIVANTE_VDK)
  679. endif(HAVE_VIDEO_VIVANTE_VDK OR HAVE_VIDEO_VIVANTE_EGL_FB)
  680. endif(VIDEO_VIVANTE)
  681. endmacro(CheckVivante)
  682. # Requires:
  683. # - nada
  684. macro(CheckOpenGLX11)
  685. if(VIDEO_OPENGL)
  686. check_c_source_compiles("
  687. #include <GL/gl.h>
  688. #include <GL/glx.h>
  689. int main(int argc, char** argv) {}" HAVE_VIDEO_OPENGL)
  690. if(HAVE_VIDEO_OPENGL)
  691. set(HAVE_VIDEO_OPENGL TRUE)
  692. set(SDL_VIDEO_OPENGL 1)
  693. set(SDL_VIDEO_OPENGL_GLX 1)
  694. set(SDL_VIDEO_RENDER_OGL 1)
  695. endif()
  696. endif()
  697. endmacro()
  698. # Requires:
  699. # - nada
  700. macro(CheckOpenGLESX11)
  701. if(VIDEO_OPENGLES)
  702. check_c_source_compiles("
  703. #define EGL_API_FB
  704. #include <EGL/egl.h>
  705. int main (int argc, char** argv) {}" HAVE_VIDEO_OPENGL_EGL)
  706. if(HAVE_VIDEO_OPENGL_EGL)
  707. set(SDL_VIDEO_OPENGL_EGL 1)
  708. endif()
  709. check_c_source_compiles("
  710. #include <GLES/gl.h>
  711. #include <GLES/glext.h>
  712. int main (int argc, char** argv) {}" HAVE_VIDEO_OPENGLES_V1)
  713. if(HAVE_VIDEO_OPENGLES_V1)
  714. set(HAVE_VIDEO_OPENGLES TRUE)
  715. set(SDL_VIDEO_OPENGL_ES 1)
  716. set(SDL_VIDEO_RENDER_OGL_ES 1)
  717. endif()
  718. check_c_source_compiles("
  719. #include <GLES2/gl2.h>
  720. #include <GLES2/gl2ext.h>
  721. int main (int argc, char** argv) {}" HAVE_VIDEO_OPENGLES_V2)
  722. if(HAVE_VIDEO_OPENGLES_V2)
  723. set(HAVE_VIDEO_OPENGLES TRUE)
  724. set(SDL_VIDEO_OPENGL_ES2 1)
  725. set(SDL_VIDEO_RENDER_OGL_ES2 1)
  726. endif()
  727. endif()
  728. endmacro()
  729. # Requires:
  730. # - nada
  731. # Optional:
  732. # - THREADS opt
  733. # Sets:
  734. # PTHREAD_CFLAGS
  735. # PTHREAD_LIBS
  736. macro(CheckPTHREAD)
  737. if(PTHREADS)
  738. if(ANDROID)
  739. # the android libc provides built-in support for pthreads, so no
  740. # additional linking or compile flags are necessary
  741. elseif(LINUX)
  742. set(PTHREAD_CFLAGS "-D_REENTRANT")
  743. set(PTHREAD_LDFLAGS "-pthread")
  744. elseif(BSDI)
  745. set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
  746. set(PTHREAD_LDFLAGS "")
  747. elseif(DARWIN)
  748. set(PTHREAD_CFLAGS "-D_THREAD_SAFE")
  749. # causes Carbon.p complaints?
  750. # set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
  751. set(PTHREAD_LDFLAGS "")
  752. elseif(FREEBSD)
  753. set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
  754. set(PTHREAD_LDFLAGS "-pthread")
  755. elseif(NETBSD)
  756. set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
  757. set(PTHREAD_LDFLAGS "-lpthread")
  758. elseif(OPENBSD)
  759. set(PTHREAD_CFLAGS "-D_REENTRANT")
  760. set(PTHREAD_LDFLAGS "-pthread")
  761. elseif(SOLARIS)
  762. set(PTHREAD_CFLAGS "-D_REENTRANT")
  763. set(PTHREAD_LDFLAGS "-pthread -lposix4")
  764. elseif(SYSV5)
  765. set(PTHREAD_CFLAGS "-D_REENTRANT -Kthread")
  766. set(PTHREAD_LDFLAGS "")
  767. elseif(AIX)
  768. set(PTHREAD_CFLAGS "-D_REENTRANT -mthreads")
  769. set(PTHREAD_LDFLAGS "-pthread")
  770. elseif(HPUX)
  771. set(PTHREAD_CFLAGS "-D_REENTRANT")
  772. set(PTHREAD_LDFLAGS "-L/usr/lib -pthread")
  773. elseif(HAIKU)
  774. set(PTHREAD_CFLAGS "-D_REENTRANT")
  775. set(PTHREAD_LDFLAGS "")
  776. else()
  777. set(PTHREAD_CFLAGS "-D_REENTRANT")
  778. set(PTHREAD_LDFLAGS "-lpthread")
  779. endif()
  780. # Run some tests
  781. set(ORIG_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
  782. set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${PTHREAD_CFLAGS} ${PTHREAD_LDFLAGS}")
  783. if(CMAKE_CROSSCOMPILING)
  784. set(HAVE_PTHREADS 1)
  785. else()
  786. check_c_source_runs("
  787. #include <pthread.h>
  788. int main(int argc, char** argv) {
  789. pthread_attr_t type;
  790. pthread_attr_init(&type);
  791. return 0;
  792. }" HAVE_PTHREADS)
  793. endif()
  794. if(HAVE_PTHREADS)
  795. set(SDL_THREAD_PTHREAD 1)
  796. list(APPEND EXTRA_CFLAGS ${PTHREAD_CFLAGS})
  797. list(APPEND EXTRA_LDFLAGS ${PTHREAD_LDFLAGS})
  798. set(SDL_CFLAGS "${SDL_CFLAGS} ${PTHREAD_CFLAGS}")
  799. list(APPEND SDL_LIBS ${PTHREAD_LDFLAGS})
  800. check_c_source_compiles("
  801. #include <pthread.h>
  802. int main(int argc, char **argv) {
  803. pthread_mutexattr_t attr;
  804. pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
  805. return 0;
  806. }" HAVE_RECURSIVE_MUTEXES)
  807. if(HAVE_RECURSIVE_MUTEXES)
  808. set(SDL_THREAD_PTHREAD_RECURSIVE_MUTEX 1)
  809. else()
  810. check_c_source_compiles("
  811. #include <pthread.h>
  812. int main(int argc, char **argv) {
  813. pthread_mutexattr_t attr;
  814. pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE_NP);
  815. return 0;
  816. }" HAVE_RECURSIVE_MUTEXES_NP)
  817. if(HAVE_RECURSIVE_MUTEXES_NP)
  818. set(SDL_THREAD_PTHREAD_RECURSIVE_MUTEX_NP 1)
  819. endif()
  820. endif()
  821. if(PTHREADS_SEM)
  822. check_c_source_compiles("#include <pthread.h>
  823. #include <semaphore.h>
  824. int main(int argc, char **argv) { return 0; }" HAVE_PTHREADS_SEM)
  825. if(HAVE_PTHREADS_SEM)
  826. check_c_source_compiles("
  827. #include <pthread.h>
  828. #include <semaphore.h>
  829. int main(int argc, char **argv) {
  830. sem_timedwait(NULL, NULL);
  831. return 0;
  832. }" HAVE_SEM_TIMEDWAIT)
  833. endif()
  834. endif()
  835. check_c_source_compiles("
  836. #include <pthread.h>
  837. #include <pthread_np.h>
  838. int main(int argc, char** argv) { return 0; }" HAVE_PTHREAD_NP_H)
  839. check_function_exists(pthread_setname_np HAVE_PTHREAD_SETNAME_NP)
  840. check_function_exists(pthread_set_name_np HAVE_PTHREAD_SET_NAME_NP)
  841. set(SOURCE_FILES ${SOURCE_FILES}
  842. ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_systhread.c
  843. ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_sysmutex.c # Can be faked, if necessary
  844. ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_syscond.c # Can be faked, if necessary
  845. ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_systls.c
  846. )
  847. if(HAVE_PTHREADS_SEM)
  848. set(SOURCE_FILES ${SOURCE_FILES}
  849. ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_syssem.c)
  850. else()
  851. set(SOURCE_FILES ${SOURCE_FILES}
  852. ${SDL2_SOURCE_DIR}/src/thread/generic/SDL_syssem.c)
  853. endif()
  854. set(HAVE_SDL_THREADS TRUE)
  855. endif()
  856. set(CMAKE_REQUIRED_FLAGS "${ORIG_CMAKE_REQUIRED_FLAGS}")
  857. endif()
  858. endmacro()
  859. # Requires
  860. # - nada
  861. # Optional:
  862. # Sets:
  863. # USB_LIBS
  864. # USB_CFLAGS
  865. macro(CheckUSBHID)
  866. check_library_exists(usbhid hid_init "" LIBUSBHID)
  867. if(LIBUSBHID)
  868. check_include_file(usbhid.h HAVE_USBHID_H)
  869. if(HAVE_USBHID_H)
  870. set(USB_CFLAGS "-DHAVE_USBHID_H")
  871. endif()
  872. check_include_file(libusbhid.h HAVE_LIBUSBHID_H)
  873. if(HAVE_LIBUSBHID_H)
  874. set(USB_CFLAGS "${USB_CFLAGS} -DHAVE_LIBUSBHID_H")
  875. endif()
  876. set(USB_LIBS ${USB_LIBS} usbhid)
  877. else()
  878. check_include_file(usb.h HAVE_USB_H)
  879. if(HAVE_USB_H)
  880. set(USB_CFLAGS "-DHAVE_USB_H")
  881. endif()
  882. check_include_file(libusb.h HAVE_LIBUSB_H)
  883. if(HAVE_LIBUSB_H)
  884. set(USB_CFLAGS "${USB_CFLAGS} -DHAVE_LIBUSB_H")
  885. endif()
  886. check_library_exists(usb hid_init "" LIBUSB)
  887. if(LIBUSB)
  888. set(USB_LIBS ${USB_LIBS} usb)
  889. endif()
  890. endif()
  891. set(ORIG_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
  892. set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${USB_CFLAGS}")
  893. set(CMAKE_REQUIRED_LIBRARIES "${USB_LIBS}")
  894. check_c_source_compiles("
  895. #include <sys/types.h>
  896. #if defined(HAVE_USB_H)
  897. #include <usb.h>
  898. #endif
  899. #ifdef __DragonFly__
  900. # include <bus/usb/usb.h>
  901. # include <bus/usb/usbhid.h>
  902. #else
  903. # include <dev/usb/usb.h>
  904. # include <dev/usb/usbhid.h>
  905. #endif
  906. #if defined(HAVE_USBHID_H)
  907. #include <usbhid.h>
  908. #elif defined(HAVE_LIBUSB_H)
  909. #include <libusb.h>
  910. #elif defined(HAVE_LIBUSBHID_H)
  911. #include <libusbhid.h>
  912. #endif
  913. int main(int argc, char **argv) {
  914. struct report_desc *repdesc;
  915. struct usb_ctl_report *repbuf;
  916. hid_kind_t hidkind;
  917. return 0;
  918. }" HAVE_USBHID)
  919. if(HAVE_USBHID)
  920. check_c_source_compiles("
  921. #include <sys/types.h>
  922. #if defined(HAVE_USB_H)
  923. #include <usb.h>
  924. #endif
  925. #ifdef __DragonFly__
  926. # include <bus/usb/usb.h>
  927. # include <bus/usb/usbhid.h>
  928. #else
  929. # include <dev/usb/usb.h>
  930. # include <dev/usb/usbhid.h>
  931. #endif
  932. #if defined(HAVE_USBHID_H)
  933. #include <usbhid.h>
  934. #elif defined(HAVE_LIBUSB_H)
  935. #include <libusb.h>
  936. #elif defined(HAVE_LIBUSBHID_H)
  937. #include <libusbhid.h>
  938. #endif
  939. int main(int argc, char** argv) {
  940. struct usb_ctl_report buf;
  941. if (buf.ucr_data) { }
  942. return 0;
  943. }" HAVE_USBHID_UCR_DATA)
  944. if(HAVE_USBHID_UCR_DATA)
  945. set(USB_CFLAGS "${USB_CFLAGS} -DUSBHID_UCR_DATA")
  946. endif()
  947. check_c_source_compiles("
  948. #include <sys/types.h>
  949. #if defined(HAVE_USB_H)
  950. #include <usb.h>
  951. #endif
  952. #ifdef __DragonFly__
  953. #include <bus/usb/usb.h>
  954. #include <bus/usb/usbhid.h>
  955. #else
  956. #include <dev/usb/usb.h>
  957. #include <dev/usb/usbhid.h>
  958. #endif
  959. #if defined(HAVE_USBHID_H)
  960. #include <usbhid.h>
  961. #elif defined(HAVE_LIBUSB_H)
  962. #include <libusb.h>
  963. #elif defined(HAVE_LIBUSBHID_H)
  964. #include <libusbhid.h>
  965. #endif
  966. int main(int argc, char **argv) {
  967. report_desc_t d;
  968. hid_start_parse(d, 1, 1);
  969. return 0;
  970. }" HAVE_USBHID_NEW)
  971. if(HAVE_USBHID_NEW)
  972. set(USB_CFLAGS "${USB_CFLAGS} -DUSBHID_NEW")
  973. endif()
  974. check_c_source_compiles("
  975. #include <machine/joystick.h>
  976. int main(int argc, char** argv) {
  977. struct joystick t;
  978. return 0;
  979. }" HAVE_MACHINE_JOYSTICK)
  980. if(HAVE_MACHINE_JOYSTICK)
  981. set(SDL_JOYSTICK_USBHID_MACHINE_JOYSTICK_H 1)
  982. endif()
  983. set(SDL_JOYSTICK_USBHID 1)
  984. file(GLOB BSD_JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/bsd/*.c)
  985. set(SOURCE_FILES ${SOURCE_FILES} ${BSD_JOYSTICK_SOURCES})
  986. list(APPEND EXTRA_CFLAGS ${USB_CFLAGS})
  987. list(APPEND EXTRA_LIBS ${USB_LIBS})
  988. set(HAVE_SDL_JOYSTICK TRUE)
  989. set(CMAKE_REQUIRED_LIBRARIES)
  990. set(CMAKE_REQUIRED_FLAGS "${ORIG_CMAKE_REQUIRED_FLAGS}")
  991. endif()
  992. endmacro()
  993. # Check for HIDAPI joystick drivers. This is currently a Unix thing, not Windows or macOS!
  994. macro(CheckHIDAPI)
  995. if(HIDAPI)
  996. if(HIDAPI_SKIP_LIBUSB)
  997. set(HAVE_HIDAPI TRUE)
  998. else()
  999. set(HAVE_HIDAPI FALSE)
  1000. pkg_check_modules(LIBUSB libusb)
  1001. if (LIBUSB_FOUND)
  1002. check_include_file(libusb.h HAVE_LIBUSB_H)
  1003. if (HAVE_LIBUSB_H)
  1004. set(HAVE_HIDAPI TRUE)
  1005. endif()
  1006. endif()
  1007. endif()
  1008. if(HAVE_HIDAPI)
  1009. set(SDL_JOYSTICK_HIDAPI 1)
  1010. set(HAVE_SDL_JOYSTICK TRUE)
  1011. file(GLOB HIDAPI_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/hidapi/*.c)
  1012. set(SOURCE_FILES ${SOURCE_FILES} ${HIDAPI_SOURCES})
  1013. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${LIBUSB_CFLAGS} -I${SDL2_SOURCE_DIR}/src/hidapi/hidapi")
  1014. if(NOT HIDAPI_SKIP_LIBUSB)
  1015. set(SOURCE_FILES ${SOURCE_FILES} ${SDL2_SOURCE_DIR}/src/hidapi/libusb/hid.c)
  1016. list(APPEND EXTRA_LIBS ${LIBUSB_LIBS})
  1017. endif()
  1018. endif()
  1019. endif()
  1020. endmacro()
  1021. # Requires:
  1022. # - n/a
  1023. macro(CheckRPI)
  1024. if(VIDEO_RPI)
  1025. pkg_check_modules(VIDEO_RPI bcm_host brcmegl)
  1026. if (NOT VIDEO_RPI_FOUND)
  1027. set(VIDEO_RPI_INCLUDE_DIRS "/opt/vc/include" "/opt/vc/include/interface/vcos/pthreads" "/opt/vc/include/interface/vmcs_host/linux/" )
  1028. set(VIDEO_RPI_LIBRARY_DIRS "/opt/vc/lib" )
  1029. set(VIDEO_RPI_LIBRARIES bcm_host )
  1030. set(VIDEO_RPI_LDFLAGS "-Wl,-rpath,/opt/vc/lib")
  1031. endif()
  1032. listtostr(VIDEO_RPI_INCLUDE_DIRS VIDEO_RPI_INCLUDE_FLAGS "-I")
  1033. listtostr(VIDEO_RPI_LIBRARY_DIRS VIDEO_RPI_LIBRARY_FLAGS "-L")
  1034. set(ORIG_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
  1035. set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${VIDEO_RPI_INCLUDE_FLAGS} ${VIDEO_RPI_LIBRARY_FLAGS}")
  1036. set(CMAKE_REQUIRED_LIBRARIES "${VIDEO_RPI_LIBRARIES}")
  1037. check_c_source_compiles("
  1038. #include <bcm_host.h>
  1039. int main(int argc, char **argv) {}" HAVE_VIDEO_RPI)
  1040. set(CMAKE_REQUIRED_FLAGS "${ORIG_CMAKE_REQUIRED_FLAGS}")
  1041. set(CMAKE_REQUIRED_LIBRARIES)
  1042. if(SDL_VIDEO AND HAVE_VIDEO_RPI)
  1043. set(HAVE_SDL_VIDEO TRUE)
  1044. set(SDL_VIDEO_DRIVER_RPI 1)
  1045. file(GLOB VIDEO_RPI_SOURCES ${SDL2_SOURCE_DIR}/src/video/raspberry/*.c)
  1046. set(SOURCE_FILES ${SOURCE_FILES} ${VIDEO_RPI_SOURCES})
  1047. list(APPEND EXTRA_LIBS ${VIDEO_RPI_LIBRARIES})
  1048. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${VIDEO_RPI_INCLUDE_FLAGS} ${VIDEO_RPI_LIBRARY_FLAGS}")
  1049. list(APPEND EXTRA_LDFLAGS ${VIDEO_RPI_LDFLAGS})
  1050. endif(SDL_VIDEO AND HAVE_VIDEO_RPI)
  1051. endif(VIDEO_RPI)
  1052. endmacro(CheckRPI)
  1053. # Requires:
  1054. # - EGL
  1055. # - PkgCheckModules
  1056. # Optional:
  1057. # - KMSDRM_SHARED opt
  1058. # - HAVE_DLOPEN opt
  1059. macro(CheckKMSDRM)
  1060. if(VIDEO_KMSDRM)
  1061. pkg_check_modules(KMSDRM libdrm gbm egl)
  1062. if(KMSDRM_FOUND)
  1063. link_directories(
  1064. ${KMSDRM_LIBRARY_DIRS}
  1065. )
  1066. include_directories(
  1067. ${KMSDRM_INCLUDE_DIRS}
  1068. )
  1069. set(HAVE_VIDEO_KMSDRM TRUE)
  1070. set(HAVE_SDL_VIDEO TRUE)
  1071. file(GLOB KMSDRM_SOURCES ${SDL2_SOURCE_DIR}/src/video/kmsdrm/*.c)
  1072. set(SOURCE_FILES ${SOURCE_FILES} ${KMSDRM_SOURCES})
  1073. list(APPEND EXTRA_CFLAGS ${KMSDRM_CFLAGS})
  1074. set(SDL_VIDEO_DRIVER_KMSDRM 1)
  1075. if(KMSDRM_SHARED)
  1076. if(NOT HAVE_DLOPEN)
  1077. message_warn("You must have SDL_LoadObject() support for dynamic KMS/DRM loading")
  1078. else()
  1079. FindLibraryAndSONAME(drm)
  1080. FindLibraryAndSONAME(gbm)
  1081. set(SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC "\"${DRM_LIB_SONAME}\"")
  1082. set(SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC_GBM "\"${GBM_LIB_SONAME}\"")
  1083. set(HAVE_KMSDRM_SHARED TRUE)
  1084. endif()
  1085. else()
  1086. set(EXTRA_LIBS ${KMSDRM_LIBRARIES} ${EXTRA_LIBS})
  1087. endif()
  1088. endif()
  1089. endif()
  1090. endmacro()