🛠️🐜 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.

1187 lines
38 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_symbol_exists(dlopen "dlfcn.h" 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_symbol_exists(shmat "sys/shm.h" 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_symbol_exists(XkbKeycodeToKeysym "X11/Xlib.h;X11/XKBlib.h" 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-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(HAVE_VIDEO_WAYLAND_QT_TOUCH TRUE)
  585. set(SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH 1)
  586. endif()
  587. if(WAYLAND_SHARED)
  588. if(NOT HAVE_DLOPEN)
  589. message_warn("You must have SDL_LoadObject() support for dynamic Wayland loading")
  590. else()
  591. FindLibraryAndSONAME(wayland-client)
  592. FindLibraryAndSONAME(wayland-egl)
  593. FindLibraryAndSONAME(wayland-cursor)
  594. FindLibraryAndSONAME(xkbcommon)
  595. set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC "\"${WAYLAND_CLIENT_LIB_SONAME}\"")
  596. set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_EGL "\"${WAYLAND_EGL_LIB_SONAME}\"")
  597. set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_CURSOR "\"${WAYLAND_CURSOR_LIB_SONAME}\"")
  598. set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_XKBCOMMON "\"${XKBCOMMON_LIB_SONAME}\"")
  599. set(HAVE_WAYLAND_SHARED TRUE)
  600. endif()
  601. else()
  602. set(EXTRA_LIBS ${WAYLAND_LIBRARIES} ${EXTRA_LIBS})
  603. endif()
  604. set(SDL_VIDEO_DRIVER_WAYLAND 1)
  605. endif()
  606. endif()
  607. endmacro()
  608. # Requires:
  609. # - n/a
  610. #
  611. macro(CheckCOCOA)
  612. if(VIDEO_COCOA)
  613. if(APPLE) # Apple always has Cocoa.
  614. set(HAVE_VIDEO_COCOA TRUE)
  615. endif()
  616. if(HAVE_VIDEO_COCOA)
  617. file(GLOB COCOA_SOURCES ${SDL2_SOURCE_DIR}/src/video/cocoa/*.m)
  618. set_source_files_properties(${COCOA_SOURCES} PROPERTIES LANGUAGE C)
  619. set(SOURCE_FILES ${SOURCE_FILES} ${COCOA_SOURCES})
  620. set(SDL_VIDEO_DRIVER_COCOA 1)
  621. set(HAVE_SDL_VIDEO TRUE)
  622. endif()
  623. endif()
  624. endmacro()
  625. # Requires:
  626. # - PkgCheckModules
  627. # Optional:
  628. # - DIRECTFB_SHARED opt
  629. # - HAVE_DLOPEN opt
  630. macro(CheckDirectFB)
  631. if(VIDEO_DIRECTFB)
  632. pkg_check_modules(PKG_DIRECTFB directfb>=1.0.0)
  633. if(PKG_DIRECTFB_FOUND)
  634. set(HAVE_VIDEO_DIRECTFB TRUE)
  635. file(GLOB DIRECTFB_SOURCES ${SDL2_SOURCE_DIR}/src/video/directfb/*.c)
  636. set(SOURCE_FILES ${SOURCE_FILES} ${DIRECTFB_SOURCES})
  637. set(SDL_VIDEO_DRIVER_DIRECTFB 1)
  638. set(SDL_VIDEO_RENDER_DIRECTFB 1)
  639. list(APPEND EXTRA_CFLAGS ${PKG_DIRECTFB_CFLAGS})
  640. if(DIRECTFB_SHARED)
  641. if(NOT HAVE_DLOPEN)
  642. message_warn("You must have SDL_LoadObject() support for dynamic DirectFB loading")
  643. else()
  644. FindLibraryAndSONAME("directfb")
  645. set(SDL_VIDEO_DRIVER_DIRECTFB_DYNAMIC "\"${DIRECTFB_LIB_SONAME}\"")
  646. set(HAVE_DIRECTFB_SHARED TRUE)
  647. endif()
  648. else()
  649. list(APPEND EXTRA_LDFLAGS ${PKG_DIRECTFB_LDFLAGS})
  650. endif()
  651. set(HAVE_SDL_VIDEO TRUE)
  652. endif()
  653. endif()
  654. endmacro()
  655. # Requires:
  656. # - n/a
  657. macro(CheckVivante)
  658. if(VIDEO_VIVANTE)
  659. check_c_source_compiles("
  660. #include <gc_vdk.h>
  661. int main(int argc, char** argv) {}" HAVE_VIDEO_VIVANTE_VDK)
  662. check_c_source_compiles("
  663. #define LINUX
  664. #define EGL_API_FB
  665. #include <EGL/eglvivante.h>
  666. int main(int argc, char** argv) {}" HAVE_VIDEO_VIVANTE_EGL_FB)
  667. if(HAVE_VIDEO_VIVANTE_VDK OR HAVE_VIDEO_VIVANTE_EGL_FB)
  668. set(HAVE_VIDEO_VIVANTE TRUE)
  669. set(HAVE_SDL_VIDEO TRUE)
  670. file(GLOB VIVANTE_SOURCES ${SDL2_SOURCE_DIR}/src/video/vivante/*.c)
  671. set(SOURCE_FILES ${SOURCE_FILES} ${VIVANTE_SOURCES})
  672. set(SDL_VIDEO_DRIVER_VIVANTE 1)
  673. if(HAVE_VIDEO_VIVANTE_VDK)
  674. set(SDL_VIDEO_DRIVER_VIVANTE_VDK 1)
  675. list(APPEND EXTRA_LIBS VDK VIVANTE)
  676. else()
  677. set(SDL_CFLAGS "${SDL_CFLAGS} -DLINUX -DEGL_API_FB")
  678. list(APPEND EXTRA_LIBS EGL)
  679. endif(HAVE_VIDEO_VIVANTE_VDK)
  680. endif(HAVE_VIDEO_VIVANTE_VDK OR HAVE_VIDEO_VIVANTE_EGL_FB)
  681. endif(VIDEO_VIVANTE)
  682. endmacro(CheckVivante)
  683. # Requires:
  684. # - nada
  685. macro(CheckOpenGLX11)
  686. if(VIDEO_OPENGL)
  687. check_c_source_compiles("
  688. #include <GL/gl.h>
  689. #include <GL/glx.h>
  690. int main(int argc, char** argv) {}" HAVE_VIDEO_OPENGL)
  691. if(HAVE_VIDEO_OPENGL)
  692. set(HAVE_VIDEO_OPENGL TRUE)
  693. set(SDL_VIDEO_OPENGL 1)
  694. set(SDL_VIDEO_OPENGL_GLX 1)
  695. set(SDL_VIDEO_RENDER_OGL 1)
  696. endif()
  697. endif()
  698. endmacro()
  699. # Requires:
  700. # - PkgCheckModules
  701. macro(CheckOpenGLESX11)
  702. pkg_check_modules(EGL egl)
  703. set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${EGL_CFLAGS}")
  704. if(VIDEO_OPENGLES)
  705. check_c_source_compiles("
  706. #define EGL_API_FB
  707. #include <EGL/egl.h>
  708. int main (int argc, char** argv) {}" HAVE_VIDEO_OPENGL_EGL)
  709. if(HAVE_VIDEO_OPENGL_EGL)
  710. set(SDL_VIDEO_OPENGL_EGL 1)
  711. endif()
  712. check_c_source_compiles("
  713. #include <GLES/gl.h>
  714. #include <GLES/glext.h>
  715. int main (int argc, char** argv) {}" HAVE_VIDEO_OPENGLES_V1)
  716. if(HAVE_VIDEO_OPENGLES_V1)
  717. set(HAVE_VIDEO_OPENGLES TRUE)
  718. set(SDL_VIDEO_OPENGL_ES 1)
  719. set(SDL_VIDEO_RENDER_OGL_ES 1)
  720. endif()
  721. check_c_source_compiles("
  722. #include <GLES2/gl2.h>
  723. #include <GLES2/gl2ext.h>
  724. int main (int argc, char** argv) {}" HAVE_VIDEO_OPENGLES_V2)
  725. if(HAVE_VIDEO_OPENGLES_V2)
  726. set(HAVE_VIDEO_OPENGLES TRUE)
  727. set(SDL_VIDEO_OPENGL_ES2 1)
  728. set(SDL_VIDEO_RENDER_OGL_ES2 1)
  729. endif()
  730. endif()
  731. endmacro()
  732. # Requires:
  733. # - nada
  734. # Optional:
  735. # - THREADS opt
  736. # Sets:
  737. # PTHREAD_CFLAGS
  738. # PTHREAD_LIBS
  739. macro(CheckPTHREAD)
  740. if(PTHREADS)
  741. if(ANDROID)
  742. # the android libc provides built-in support for pthreads, so no
  743. # additional linking or compile flags are necessary
  744. elseif(LINUX)
  745. set(PTHREAD_CFLAGS "-D_REENTRANT")
  746. set(PTHREAD_LDFLAGS "-pthread")
  747. elseif(BSDI)
  748. set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
  749. set(PTHREAD_LDFLAGS "")
  750. elseif(DARWIN)
  751. set(PTHREAD_CFLAGS "-D_THREAD_SAFE")
  752. # causes Carbon.p complaints?
  753. # set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
  754. set(PTHREAD_LDFLAGS "")
  755. elseif(FREEBSD)
  756. set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
  757. set(PTHREAD_LDFLAGS "-pthread")
  758. elseif(NETBSD)
  759. set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
  760. set(PTHREAD_LDFLAGS "-lpthread")
  761. elseif(OPENBSD)
  762. set(PTHREAD_CFLAGS "-D_REENTRANT")
  763. set(PTHREAD_LDFLAGS "-pthread")
  764. elseif(SOLARIS)
  765. set(PTHREAD_CFLAGS "-D_REENTRANT")
  766. set(PTHREAD_LDFLAGS "-pthread -lposix4")
  767. elseif(SYSV5)
  768. set(PTHREAD_CFLAGS "-D_REENTRANT -Kthread")
  769. set(PTHREAD_LDFLAGS "")
  770. elseif(AIX)
  771. set(PTHREAD_CFLAGS "-D_REENTRANT -mthreads")
  772. set(PTHREAD_LDFLAGS "-pthread")
  773. elseif(HPUX)
  774. set(PTHREAD_CFLAGS "-D_REENTRANT")
  775. set(PTHREAD_LDFLAGS "-L/usr/lib -pthread")
  776. elseif(HAIKU)
  777. set(PTHREAD_CFLAGS "-D_REENTRANT")
  778. set(PTHREAD_LDFLAGS "")
  779. else()
  780. set(PTHREAD_CFLAGS "-D_REENTRANT")
  781. set(PTHREAD_LDFLAGS "-lpthread")
  782. endif()
  783. # Run some tests
  784. set(ORIG_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
  785. set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${PTHREAD_CFLAGS} ${PTHREAD_LDFLAGS}")
  786. if(CMAKE_CROSSCOMPILING)
  787. set(HAVE_PTHREADS 1)
  788. else()
  789. check_c_source_runs("
  790. #include <pthread.h>
  791. int main(int argc, char** argv) {
  792. pthread_attr_t type;
  793. pthread_attr_init(&type);
  794. return 0;
  795. }" HAVE_PTHREADS)
  796. endif()
  797. if(HAVE_PTHREADS)
  798. set(SDL_THREAD_PTHREAD 1)
  799. list(APPEND EXTRA_CFLAGS ${PTHREAD_CFLAGS})
  800. list(APPEND EXTRA_LDFLAGS ${PTHREAD_LDFLAGS})
  801. set(SDL_CFLAGS "${SDL_CFLAGS} ${PTHREAD_CFLAGS}")
  802. list(APPEND SDL_LIBS ${PTHREAD_LDFLAGS})
  803. check_c_source_compiles("
  804. #include <pthread.h>
  805. int main(int argc, char **argv) {
  806. pthread_mutexattr_t attr;
  807. pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
  808. return 0;
  809. }" HAVE_RECURSIVE_MUTEXES)
  810. if(HAVE_RECURSIVE_MUTEXES)
  811. set(SDL_THREAD_PTHREAD_RECURSIVE_MUTEX 1)
  812. else()
  813. check_c_source_compiles("
  814. #include <pthread.h>
  815. int main(int argc, char **argv) {
  816. pthread_mutexattr_t attr;
  817. pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE_NP);
  818. return 0;
  819. }" HAVE_RECURSIVE_MUTEXES_NP)
  820. if(HAVE_RECURSIVE_MUTEXES_NP)
  821. set(SDL_THREAD_PTHREAD_RECURSIVE_MUTEX_NP 1)
  822. endif()
  823. endif()
  824. if(PTHREADS_SEM)
  825. check_c_source_compiles("#include <pthread.h>
  826. #include <semaphore.h>
  827. int main(int argc, char **argv) { return 0; }" HAVE_PTHREADS_SEM)
  828. if(HAVE_PTHREADS_SEM)
  829. check_c_source_compiles("
  830. #include <pthread.h>
  831. #include <semaphore.h>
  832. int main(int argc, char **argv) {
  833. sem_timedwait(NULL, NULL);
  834. return 0;
  835. }" HAVE_SEM_TIMEDWAIT)
  836. endif()
  837. endif()
  838. check_include_files("pthread.h" HAVE_PTHREAD_H)
  839. check_include_files("pthread_np.h" HAVE_PTHREAD_NP_H)
  840. if (HAVE_PTHREAD_H)
  841. check_symbol_exists(pthread_setname_np "pthread.h" HAVE_PTHREAD_SETNAME_NP)
  842. if (HAVE_PTHREAD_NP_H)
  843. check_symbol_exists(pthread_set_name_np "pthread.h;pthread_np.h" HAVE_PTHREAD_SET_NAME_NP)
  844. endif()
  845. endif()
  846. set(SOURCE_FILES ${SOURCE_FILES}
  847. ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_systhread.c
  848. ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_sysmutex.c # Can be faked, if necessary
  849. ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_syscond.c # Can be faked, if necessary
  850. ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_systls.c
  851. )
  852. if(HAVE_PTHREADS_SEM)
  853. set(SOURCE_FILES ${SOURCE_FILES}
  854. ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_syssem.c)
  855. else()
  856. set(SOURCE_FILES ${SOURCE_FILES}
  857. ${SDL2_SOURCE_DIR}/src/thread/generic/SDL_syssem.c)
  858. endif()
  859. set(HAVE_SDL_THREADS TRUE)
  860. endif()
  861. set(CMAKE_REQUIRED_FLAGS "${ORIG_CMAKE_REQUIRED_FLAGS}")
  862. endif()
  863. endmacro()
  864. # Requires
  865. # - nada
  866. # Optional:
  867. # Sets:
  868. # USB_LIBS
  869. # USB_CFLAGS
  870. macro(CheckUSBHID)
  871. check_library_exists(usbhid hid_init "" LIBUSBHID)
  872. if(LIBUSBHID)
  873. check_include_file(usbhid.h HAVE_USBHID_H)
  874. if(HAVE_USBHID_H)
  875. set(USB_CFLAGS "-DHAVE_USBHID_H")
  876. endif()
  877. check_include_file(libusbhid.h HAVE_LIBUSBHID_H)
  878. if(HAVE_LIBUSBHID_H)
  879. set(USB_CFLAGS "${USB_CFLAGS} -DHAVE_LIBUSBHID_H")
  880. endif()
  881. set(USB_LIBS ${USB_LIBS} usbhid)
  882. else()
  883. check_include_file(usb.h HAVE_USB_H)
  884. if(HAVE_USB_H)
  885. set(USB_CFLAGS "-DHAVE_USB_H")
  886. endif()
  887. check_include_file(libusb.h HAVE_LIBUSB_H)
  888. if(HAVE_LIBUSB_H)
  889. set(USB_CFLAGS "${USB_CFLAGS} -DHAVE_LIBUSB_H")
  890. endif()
  891. check_library_exists(usb hid_init "" LIBUSB)
  892. if(LIBUSB)
  893. set(USB_LIBS ${USB_LIBS} usb)
  894. endif()
  895. endif()
  896. set(ORIG_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
  897. set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${USB_CFLAGS}")
  898. set(CMAKE_REQUIRED_LIBRARIES "${USB_LIBS}")
  899. check_c_source_compiles("
  900. #include <sys/types.h>
  901. #if defined(HAVE_USB_H)
  902. #include <usb.h>
  903. #endif
  904. #ifdef __DragonFly__
  905. # include <bus/usb/usb.h>
  906. # include <bus/usb/usbhid.h>
  907. #else
  908. # include <dev/usb/usb.h>
  909. # include <dev/usb/usbhid.h>
  910. #endif
  911. #if defined(HAVE_USBHID_H)
  912. #include <usbhid.h>
  913. #elif defined(HAVE_LIBUSB_H)
  914. #include <libusb.h>
  915. #elif defined(HAVE_LIBUSBHID_H)
  916. #include <libusbhid.h>
  917. #endif
  918. int main(int argc, char **argv) {
  919. struct report_desc *repdesc;
  920. struct usb_ctl_report *repbuf;
  921. hid_kind_t hidkind;
  922. return 0;
  923. }" HAVE_USBHID)
  924. if(HAVE_USBHID)
  925. check_c_source_compiles("
  926. #include <sys/types.h>
  927. #if defined(HAVE_USB_H)
  928. #include <usb.h>
  929. #endif
  930. #ifdef __DragonFly__
  931. # include <bus/usb/usb.h>
  932. # include <bus/usb/usbhid.h>
  933. #else
  934. # include <dev/usb/usb.h>
  935. # include <dev/usb/usbhid.h>
  936. #endif
  937. #if defined(HAVE_USBHID_H)
  938. #include <usbhid.h>
  939. #elif defined(HAVE_LIBUSB_H)
  940. #include <libusb.h>
  941. #elif defined(HAVE_LIBUSBHID_H)
  942. #include <libusbhid.h>
  943. #endif
  944. int main(int argc, char** argv) {
  945. struct usb_ctl_report buf;
  946. if (buf.ucr_data) { }
  947. return 0;
  948. }" HAVE_USBHID_UCR_DATA)
  949. if(HAVE_USBHID_UCR_DATA)
  950. set(USB_CFLAGS "${USB_CFLAGS} -DUSBHID_UCR_DATA")
  951. endif()
  952. check_c_source_compiles("
  953. #include <sys/types.h>
  954. #if defined(HAVE_USB_H)
  955. #include <usb.h>
  956. #endif
  957. #ifdef __DragonFly__
  958. #include <bus/usb/usb.h>
  959. #include <bus/usb/usbhid.h>
  960. #else
  961. #include <dev/usb/usb.h>
  962. #include <dev/usb/usbhid.h>
  963. #endif
  964. #if defined(HAVE_USBHID_H)
  965. #include <usbhid.h>
  966. #elif defined(HAVE_LIBUSB_H)
  967. #include <libusb.h>
  968. #elif defined(HAVE_LIBUSBHID_H)
  969. #include <libusbhid.h>
  970. #endif
  971. int main(int argc, char **argv) {
  972. report_desc_t d;
  973. hid_start_parse(d, 1, 1);
  974. return 0;
  975. }" HAVE_USBHID_NEW)
  976. if(HAVE_USBHID_NEW)
  977. set(USB_CFLAGS "${USB_CFLAGS} -DUSBHID_NEW")
  978. endif()
  979. check_c_source_compiles("
  980. #include <machine/joystick.h>
  981. int main(int argc, char** argv) {
  982. struct joystick t;
  983. return 0;
  984. }" HAVE_MACHINE_JOYSTICK)
  985. if(HAVE_MACHINE_JOYSTICK)
  986. set(SDL_JOYSTICK_USBHID_MACHINE_JOYSTICK_H 1)
  987. endif()
  988. set(SDL_JOYSTICK_USBHID 1)
  989. file(GLOB BSD_JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/bsd/*.c)
  990. set(SOURCE_FILES ${SOURCE_FILES} ${BSD_JOYSTICK_SOURCES})
  991. list(APPEND EXTRA_CFLAGS ${USB_CFLAGS})
  992. list(APPEND EXTRA_LIBS ${USB_LIBS})
  993. set(HAVE_SDL_JOYSTICK TRUE)
  994. set(CMAKE_REQUIRED_LIBRARIES)
  995. set(CMAKE_REQUIRED_FLAGS "${ORIG_CMAKE_REQUIRED_FLAGS}")
  996. endif()
  997. endmacro()
  998. # Check for HIDAPI joystick drivers. This is currently a Unix thing, not Windows or macOS!
  999. macro(CheckHIDAPI)
  1000. if(HIDAPI)
  1001. if(HIDAPI_SKIP_LIBUSB)
  1002. set(HAVE_HIDAPI TRUE)
  1003. else()
  1004. set(HAVE_HIDAPI FALSE)
  1005. pkg_check_modules(LIBUSB libusb)
  1006. if (LIBUSB_FOUND)
  1007. check_include_file(libusb.h HAVE_LIBUSB_H ${LIBUSB_CFLAGS})
  1008. if (HAVE_LIBUSB_H)
  1009. set(HAVE_HIDAPI TRUE)
  1010. endif()
  1011. endif()
  1012. endif()
  1013. if(HAVE_HIDAPI)
  1014. set(SDL_JOYSTICK_HIDAPI 1)
  1015. set(HAVE_SDL_JOYSTICK TRUE)
  1016. file(GLOB HIDAPI_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/hidapi/*.c)
  1017. set(SOURCE_FILES ${SOURCE_FILES} ${HIDAPI_SOURCES})
  1018. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${LIBUSB_CFLAGS} \"-I${SDL2_SOURCE_DIR}/src/hidapi/hidapi\"")
  1019. if(NOT HIDAPI_SKIP_LIBUSB)
  1020. if(HIDAPI_ONLY_LIBUSB)
  1021. set(SOURCE_FILES ${SOURCE_FILES} ${SDL2_SOURCE_DIR}/src/hidapi/libusb/hid.c)
  1022. list(APPEND EXTRA_LIBS ${LIBUSB_LIBS})
  1023. else()
  1024. set(SOURCE_FILES ${SOURCE_FILES} ${SDL2_SOURCE_DIR}/src/hidapi/SDL_hidapi.c)
  1025. # libusb is loaded dynamically, so don't add it to EXTRA_LIBS
  1026. FindLibraryAndSONAME("usb-1.0")
  1027. set(SDL_LIBUSB_DYNAMIC "\"${USB_LIB_SONAME}\"")
  1028. endif()
  1029. endif()
  1030. endif()
  1031. endif()
  1032. endmacro()
  1033. # Requires:
  1034. # - n/a
  1035. macro(CheckRPI)
  1036. if(VIDEO_RPI)
  1037. pkg_check_modules(VIDEO_RPI bcm_host brcmegl)
  1038. if (NOT VIDEO_RPI_FOUND)
  1039. set(VIDEO_RPI_INCLUDE_DIRS "/opt/vc/include" "/opt/vc/include/interface/vcos/pthreads" "/opt/vc/include/interface/vmcs_host/linux/" )
  1040. set(VIDEO_RPI_LIBRARY_DIRS "/opt/vc/lib" )
  1041. set(VIDEO_RPI_LIBRARIES bcm_host )
  1042. set(VIDEO_RPI_LDFLAGS "-Wl,-rpath,/opt/vc/lib")
  1043. endif()
  1044. listtostr(VIDEO_RPI_INCLUDE_DIRS VIDEO_RPI_INCLUDE_FLAGS "-I")
  1045. listtostr(VIDEO_RPI_LIBRARY_DIRS VIDEO_RPI_LIBRARY_FLAGS "-L")
  1046. set(ORIG_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
  1047. set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${VIDEO_RPI_INCLUDE_FLAGS} ${VIDEO_RPI_LIBRARY_FLAGS}")
  1048. set(CMAKE_REQUIRED_LIBRARIES "${VIDEO_RPI_LIBRARIES}")
  1049. check_c_source_compiles("
  1050. #include <bcm_host.h>
  1051. int main(int argc, char **argv) {}" HAVE_VIDEO_RPI)
  1052. set(CMAKE_REQUIRED_FLAGS "${ORIG_CMAKE_REQUIRED_FLAGS}")
  1053. set(CMAKE_REQUIRED_LIBRARIES)
  1054. if(SDL_VIDEO AND HAVE_VIDEO_RPI)
  1055. set(HAVE_SDL_VIDEO TRUE)
  1056. set(SDL_VIDEO_DRIVER_RPI 1)
  1057. file(GLOB VIDEO_RPI_SOURCES ${SDL2_SOURCE_DIR}/src/video/raspberry/*.c)
  1058. set(SOURCE_FILES ${SOURCE_FILES} ${VIDEO_RPI_SOURCES})
  1059. list(APPEND EXTRA_LIBS ${VIDEO_RPI_LIBRARIES})
  1060. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${VIDEO_RPI_INCLUDE_FLAGS} ${VIDEO_RPI_LIBRARY_FLAGS}")
  1061. list(APPEND EXTRA_LDFLAGS ${VIDEO_RPI_LDFLAGS})
  1062. endif(SDL_VIDEO AND HAVE_VIDEO_RPI)
  1063. endif(VIDEO_RPI)
  1064. endmacro(CheckRPI)
  1065. # Requires:
  1066. # - EGL
  1067. # - PkgCheckModules
  1068. # Optional:
  1069. # - KMSDRM_SHARED opt
  1070. # - HAVE_DLOPEN opt
  1071. macro(CheckKMSDRM)
  1072. if(VIDEO_KMSDRM)
  1073. pkg_check_modules(KMSDRM libdrm gbm egl)
  1074. if(KMSDRM_FOUND)
  1075. link_directories(
  1076. ${KMSDRM_LIBRARY_DIRS}
  1077. )
  1078. include_directories(
  1079. ${KMSDRM_INCLUDE_DIRS}
  1080. )
  1081. set(HAVE_VIDEO_KMSDRM TRUE)
  1082. set(HAVE_SDL_VIDEO TRUE)
  1083. file(GLOB KMSDRM_SOURCES ${SDL2_SOURCE_DIR}/src/video/kmsdrm/*.c)
  1084. set(SOURCE_FILES ${SOURCE_FILES} ${KMSDRM_SOURCES})
  1085. list(APPEND EXTRA_CFLAGS ${KMSDRM_CFLAGS})
  1086. set(SDL_VIDEO_DRIVER_KMSDRM 1)
  1087. if(KMSDRM_SHARED)
  1088. if(NOT HAVE_DLOPEN)
  1089. message_warn("You must have SDL_LoadObject() support for dynamic KMS/DRM loading")
  1090. else()
  1091. FindLibraryAndSONAME(drm)
  1092. FindLibraryAndSONAME(gbm)
  1093. set(SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC "\"${DRM_LIB_SONAME}\"")
  1094. set(SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC_GBM "\"${GBM_LIB_SONAME}\"")
  1095. set(HAVE_KMSDRM_SHARED TRUE)
  1096. endif()
  1097. else()
  1098. set(EXTRA_LIBS ${KMSDRM_LIBRARIES} ${EXTRA_LIBS})
  1099. endif()
  1100. endif()
  1101. endif()
  1102. endmacro()