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

1288 lines
42 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. check_library_exists(dl dlopen "" DLOPEN_LIB)
  30. if(DLOPEN_LIB)
  31. list(APPEND EXTRA_LIBS dl)
  32. set(_DLLIB dl)
  33. set(HAVE_DLOPEN TRUE)
  34. endif()
  35. endif()
  36. if(HAVE_DLOPEN)
  37. if(_DLLIB)
  38. set(CMAKE_REQUIRED_LIBRARIES ${_DLLIB})
  39. endif()
  40. check_c_source_compiles("
  41. #include <dlfcn.h>
  42. int main(int argc, char **argv) {
  43. void *handle = dlopen(\"\", RTLD_NOW);
  44. const char *loaderror = (char *) dlerror();
  45. return 0;
  46. }" HAVE_DLOPEN)
  47. set(CMAKE_REQUIRED_LIBRARIES)
  48. endif()
  49. endmacro()
  50. macro(CheckO_CLOEXEC)
  51. check_c_source_compiles("
  52. #include <fcntl.h>
  53. int flag = O_CLOEXEC;
  54. int main(int argc, char **argv) { return 0; }" HAVE_O_CLOEXEC)
  55. endmacro()
  56. # Requires:
  57. # - n/a
  58. macro(CheckOSS)
  59. if(SDL_OSS)
  60. set(OSS_HEADER_FILE "sys/soundcard.h")
  61. check_c_source_compiles("
  62. #include <sys/soundcard.h>
  63. int main(int argc, char **argv) { int arg = SNDCTL_DSP_SETFRAGMENT; return 0; }" OSS_FOUND)
  64. if(NOT OSS_FOUND)
  65. set(OSS_HEADER_FILE "soundcard.h")
  66. check_c_source_compiles("
  67. #include <soundcard.h>
  68. int main(int argc, char **argv) { int arg = SNDCTL_DSP_SETFRAGMENT; return 0; }" OSS_FOUND)
  69. endif()
  70. if(OSS_FOUND)
  71. set(HAVE_OSS TRUE)
  72. file(GLOB OSS_SOURCES ${SDL2_SOURCE_DIR}/src/audio/dsp/*.c)
  73. if(OSS_HEADER_FILE STREQUAL "soundcard.h")
  74. set(SDL_AUDIO_DRIVER_OSS_SOUNDCARD_H 1)
  75. endif()
  76. set(SDL_AUDIO_DRIVER_OSS 1)
  77. set(SOURCE_FILES ${SOURCE_FILES} ${OSS_SOURCES})
  78. if(NETBSD OR OPENBSD)
  79. list(APPEND EXTRA_LIBS ossaudio)
  80. endif()
  81. set(HAVE_SDL_AUDIO TRUE)
  82. endif()
  83. endif()
  84. endmacro()
  85. # Requires:
  86. # - n/a
  87. # Optional:
  88. # - SDL_ALSA_SHARED opt
  89. # - HAVE_SDL_LOADSO opt
  90. macro(CheckALSA)
  91. if(SDL_ALSA)
  92. CHECK_INCLUDE_FILE(alsa/asoundlib.h HAVE_ASOUNDLIB_H)
  93. if(HAVE_ASOUNDLIB_H)
  94. CHECK_LIBRARY_EXISTS(asound snd_pcm_recover "" HAVE_LIBASOUND)
  95. endif()
  96. if(HAVE_LIBASOUND)
  97. set(HAVE_ALSA TRUE)
  98. file(GLOB ALSA_SOURCES ${SDL2_SOURCE_DIR}/src/audio/alsa/*.c)
  99. set(SOURCE_FILES ${SOURCE_FILES} ${ALSA_SOURCES})
  100. set(SDL_AUDIO_DRIVER_ALSA 1)
  101. if(SDL_ALSA_SHARED AND NOT HAVE_SDL_LOADSO)
  102. message_warn("You must have SDL_LoadObject() support for dynamic ALSA loading")
  103. endif()
  104. if(SDL_ALSA_SHARED AND HAVE_SDL_LOADSO)
  105. FindLibraryAndSONAME("asound")
  106. set(SDL_AUDIO_DRIVER_ALSA_DYNAMIC "\"${ASOUND_LIB_SONAME}\"")
  107. set(HAVE_ALSA_SHARED TRUE)
  108. else()
  109. list(APPEND EXTRA_LIBS asound)
  110. endif()
  111. set(HAVE_SDL_AUDIO TRUE)
  112. endif()
  113. endif()
  114. endmacro()
  115. # Requires:
  116. # - PkgCheckModules
  117. # Optional:
  118. # - SDL_PIPEWIRE_SHARED opt
  119. # - HAVE_SDL_LOADSO opt
  120. macro(CheckPipewire)
  121. if(SDL_PIPEWIRE)
  122. pkg_check_modules(PKG_PIPEWIRE libpipewire-0.3>=0.3.20)
  123. if(PKG_PIPEWIRE_FOUND)
  124. set(HAVE_PIPEWIRE TRUE)
  125. file(GLOB PIPEWIRE_SOURCES ${SDL2_SOURCE_DIR}/src/audio/pipewire/*.c)
  126. set(SOURCE_FILES ${SOURCE_FILES} ${PIPEWIRE_SOURCES})
  127. set(SDL_AUDIO_DRIVER_PIPEWIRE 1)
  128. list(APPEND EXTRA_CFLAGS ${PKG_PIPEWIRE_CFLAGS})
  129. if(SDL_PIPEWIRE_SHARED AND NOT HAVE_SDL_LOADSO)
  130. message_warn("You must have SDL_LoadObject() support for dynamic Pipewire loading")
  131. endif()
  132. if(SDL_PIPEWIRE_SHARED AND HAVE_SDL_LOADSO)
  133. FindLibraryAndSONAME("pipewire-0.3")
  134. set(SDL_AUDIO_DRIVER_PIPEWIRE_DYNAMIC "\"${PIPEWIRE_0.3_LIB_SONAME}\"")
  135. set(HAVE_PIPEWIRE_SHARED TRUE)
  136. else()
  137. list(APPEND EXTRA_LDFLAGS ${PKG_PIPEWIRE_LDFLAGS})
  138. endif()
  139. set(HAVE_SDL_AUDIO TRUE)
  140. endif()
  141. endif()
  142. endmacro()
  143. # Requires:
  144. # - PkgCheckModules
  145. # Optional:
  146. # - SDL_PULSEAUDIO_SHARED opt
  147. # - HAVE_SDL_LOADSO opt
  148. macro(CheckPulseAudio)
  149. if(SDL_PULSEAUDIO)
  150. pkg_check_modules(PKG_PULSEAUDIO libpulse-simple)
  151. if(PKG_PULSEAUDIO_FOUND)
  152. set(HAVE_PULSEAUDIO TRUE)
  153. file(GLOB PULSEAUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/pulseaudio/*.c)
  154. set(SOURCE_FILES ${SOURCE_FILES} ${PULSEAUDIO_SOURCES})
  155. set(SDL_AUDIO_DRIVER_PULSEAUDIO 1)
  156. list(APPEND EXTRA_CFLAGS ${PKG_PULSEAUDIO_CFLAGS})
  157. if(SDL_PULSEAUDIO_SHARED AND NOT HAVE_SDL_LOADSO)
  158. message_warn("You must have SDL_LoadObject() support for dynamic PulseAudio loading")
  159. endif()
  160. if(SDL_PULSEAUDIO_SHARED AND HAVE_SDL_LOADSO)
  161. FindLibraryAndSONAME("pulse-simple")
  162. set(SDL_AUDIO_DRIVER_PULSEAUDIO_DYNAMIC "\"${PULSE_SIMPLE_LIB_SONAME}\"")
  163. set(HAVE_PULSEAUDIO_SHARED TRUE)
  164. else()
  165. list(APPEND EXTRA_LDFLAGS ${PKG_PULSEAUDIO_LDFLAGS})
  166. endif()
  167. set(HAVE_SDL_AUDIO TRUE)
  168. endif()
  169. endif()
  170. endmacro()
  171. # Requires:
  172. # - PkgCheckModules
  173. # Optional:
  174. # - SDL_JACK_SHARED opt
  175. # - HAVE_SDL_LOADSO opt
  176. macro(CheckJACK)
  177. if(SDL_JACK)
  178. pkg_check_modules(PKG_JACK jack)
  179. if(PKG_JACK_FOUND)
  180. set(HAVE_JACK TRUE)
  181. file(GLOB JACK_SOURCES ${SDL2_SOURCE_DIR}/src/audio/jack/*.c)
  182. set(SOURCE_FILES ${SOURCE_FILES} ${JACK_SOURCES})
  183. set(SDL_AUDIO_DRIVER_JACK 1)
  184. list(APPEND EXTRA_CFLAGS ${PKG_JACK_CFLAGS})
  185. if(SDL_JACK_SHARED AND NOT HAVE_SDL_LOADSO)
  186. message_warn("You must have SDL_LoadObject() support for dynamic JACK audio loading")
  187. endif()
  188. if(SDL_JACK_SHARED AND HAVE_SDL_LOADSO)
  189. FindLibraryAndSONAME("jack")
  190. set(SDL_AUDIO_DRIVER_JACK_DYNAMIC "\"${JACK_LIB_SONAME}\"")
  191. set(HAVE_JACK_SHARED TRUE)
  192. else()
  193. list(APPEND EXTRA_LDFLAGS ${PKG_JACK_LDFLAGS})
  194. endif()
  195. set(HAVE_SDL_AUDIO TRUE)
  196. endif()
  197. endif()
  198. endmacro()
  199. # Requires:
  200. # - PkgCheckModules
  201. # Optional:
  202. # - SDL_ESD_SHARED opt
  203. # - HAVE_SDL_LOADSO opt
  204. macro(CheckESD)
  205. if(SDL_ESD)
  206. pkg_check_modules(PKG_ESD esound)
  207. if(PKG_ESD_FOUND)
  208. set(HAVE_ESD TRUE)
  209. file(GLOB ESD_SOURCES ${SDL2_SOURCE_DIR}/src/audio/esd/*.c)
  210. set(SOURCE_FILES ${SOURCE_FILES} ${ESD_SOURCES})
  211. set(SDL_AUDIO_DRIVER_ESD 1)
  212. list(APPEND EXTRA_CFLAGS ${PKG_ESD_CFLAGS})
  213. if(SDL_ESD_SHARED AND NOT HAVE_SDL_LOADSO)
  214. message_warn("You must have SDL_LoadObject() support for dynamic ESD loading")
  215. endif()
  216. if(SDL_ESD_SHARED AND HAVE_SDL_LOADSO)
  217. FindLibraryAndSONAME(esd)
  218. set(SDL_AUDIO_DRIVER_ESD_DYNAMIC "\"${ESD_LIB_SONAME}\"")
  219. set(HAVE_ESD_SHARED TRUE)
  220. else()
  221. list(APPEND EXTRA_LDFLAGS ${PKG_ESD_LDFLAGS})
  222. endif()
  223. set(HAVE_SDL_AUDIO TRUE)
  224. endif()
  225. endif()
  226. endmacro()
  227. # Requires:
  228. # - n/a
  229. # Optional:
  230. # - SDL_ARTS_SHARED opt
  231. # - HAVE_SDL_LOADSO opt
  232. macro(CheckARTS)
  233. if(SDL_ARTS)
  234. find_program(ARTS_CONFIG arts-config)
  235. if(ARTS_CONFIG)
  236. execute_process(CMD_ARTSCFLAGS ${ARTS_CONFIG} --cflags
  237. OUTPUT_VARIABLE ARTS_CFLAGS OUTPUT_STRIP_TRAILING_WHITESPACE)
  238. list(APPEND EXTRA_CFLAGS ${ARTS_CFLAGS})
  239. execute_process(CMD_ARTSLIBS ${ARTS_CONFIG} --libs
  240. OUTPUT_VARIABLE ARTS_LIBS OUTPUT_STRIP_TRAILING_WHITESPACE)
  241. file(GLOB ARTS_SOURCES ${SDL2_SOURCE_DIR}/src/audio/arts/*.c)
  242. set(SOURCE_FILES ${SOURCE_FILES} ${ARTS_SOURCES})
  243. set(SDL_AUDIO_DRIVER_ARTS 1)
  244. set(HAVE_ARTS TRUE)
  245. if(SDL_ARTS_SHARED AND NOT HAVE_SDL_LOADSO)
  246. message_warn("You must have SDL_LoadObject() support for dynamic ARTS loading")
  247. endif()
  248. if(SDL_ARTS_SHARED AND HAVE_SDL_LOADSO)
  249. # TODO
  250. FindLibraryAndSONAME(artsc)
  251. set(SDL_AUDIO_DRIVER_ARTS_DYNAMIC "\"${ARTSC_LIB_SONAME}\"")
  252. set(HAVE_ARTS_SHARED TRUE)
  253. else()
  254. list(APPEND EXTRA_LDFLAGS ${ARTS_LIBS})
  255. endif()
  256. set(HAVE_SDL_AUDIO TRUE)
  257. endif()
  258. endif()
  259. endmacro()
  260. # Requires:
  261. # - n/a
  262. # Optional:
  263. # - SDL_NAS_SHARED opt
  264. # - HAVE_SDL_LOADSO opt
  265. macro(CheckNAS)
  266. if(SDL_NAS)
  267. # TODO: set include paths properly, so the NAS headers are found
  268. check_include_file(audio/audiolib.h HAVE_NAS_H)
  269. find_library(D_NAS_LIB audio)
  270. if(HAVE_NAS_H AND D_NAS_LIB)
  271. set(HAVE_NAS TRUE)
  272. file(GLOB NAS_SOURCES ${SDL2_SOURCE_DIR}/src/audio/nas/*.c)
  273. set(SOURCE_FILES ${SOURCE_FILES} ${NAS_SOURCES})
  274. set(SDL_AUDIO_DRIVER_NAS 1)
  275. if(SDL_NAS_SHARED AND NOT HAVE_SDL_LOADSO)
  276. message_warn("You must have SDL_LoadObject() support for dynamic NAS loading")
  277. endif()
  278. if(SDL_NAS_SHARED AND HAVE_SDL_LOADSO)
  279. FindLibraryAndSONAME("audio")
  280. set(SDL_AUDIO_DRIVER_NAS_DYNAMIC "\"${AUDIO_LIB_SONAME}\"")
  281. set(HAVE_NAS_SHARED TRUE)
  282. else()
  283. list(APPEND EXTRA_LIBS ${D_NAS_LIB})
  284. endif()
  285. set(HAVE_SDL_AUDIO TRUE)
  286. endif()
  287. endif()
  288. endmacro()
  289. # Requires:
  290. # - n/a
  291. # Optional:
  292. # - SDL_SNDIO_SHARED opt
  293. # - HAVE_SDL_LOADSO opt
  294. macro(CheckSNDIO)
  295. if(SDL_SNDIO)
  296. # TODO: set include paths properly, so the sndio headers are found
  297. check_include_file(sndio.h HAVE_SNDIO_H)
  298. find_library(D_SNDIO_LIB sndio)
  299. if(HAVE_SNDIO_H AND D_SNDIO_LIB)
  300. set(HAVE_SNDIO TRUE)
  301. file(GLOB SNDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/sndio/*.c)
  302. set(SOURCE_FILES ${SOURCE_FILES} ${SNDIO_SOURCES})
  303. set(SDL_AUDIO_DRIVER_SNDIO 1)
  304. if(SDL_SNDIO_SHARED AND NOT HAVE_SDL_LOADSO)
  305. message_warn("You must have SDL_LoadObject() support for dynamic sndio loading")
  306. endif()
  307. if(SDL_SNDIO_SHARED AND HAVE_SDL_LOADSO)
  308. FindLibraryAndSONAME("sndio")
  309. set(SDL_AUDIO_DRIVER_SNDIO_DYNAMIC "\"${SNDIO_LIB_SONAME}\"")
  310. set(HAVE_SNDIO_SHARED TRUE)
  311. else()
  312. list(APPEND EXTRA_LIBS ${D_SNDIO_LIB})
  313. endif()
  314. set(HAVE_SDL_AUDIO TRUE)
  315. endif()
  316. endif()
  317. endmacro()
  318. # Requires:
  319. # - PkgCheckModules
  320. # Optional:
  321. # - FUSIONSOUND_SHARED opt
  322. # - HAVE_SDL_LOADSO opt
  323. macro(CheckFusionSound)
  324. if(FUSIONSOUND)
  325. pkg_check_modules(PKG_FUSIONSOUND fusionsound>=1.0.0)
  326. if(PKG_FUSIONSOUND_FOUND)
  327. set(HAVE_FUSIONSOUND TRUE)
  328. file(GLOB FUSIONSOUND_SOURCES ${SDL2_SOURCE_DIR}/src/audio/fusionsound/*.c)
  329. set(SOURCE_FILES ${SOURCE_FILES} ${FUSIONSOUND_SOURCES})
  330. set(SDL_AUDIO_DRIVER_FUSIONSOUND 1)
  331. list(APPEND EXTRA_CFLAGS ${PKG_FUSIONSOUND_CFLAGS})
  332. if(FUSIONSOUND_SHARED AND NOT HAVE_SDL_LOADSO)
  333. message_warn("You must have SDL_LoadObject() support for dynamic FusionSound loading")
  334. endif()
  335. if(FUSIONSOUND_SHARED AND HAVE_SDL_LOADSO)
  336. FindLibraryAndSONAME("fusionsound")
  337. set(SDL_AUDIO_DRIVER_FUSIONSOUND_DYNAMIC "\"${FUSIONSOUND_LIB_SONAME}\"")
  338. set(HAVE_FUSIONSOUND_SHARED TRUE)
  339. else()
  340. list(APPEND EXTRA_LDFLAGS ${PKG_FUSIONSOUND_LDFLAGS})
  341. endif()
  342. set(HAVE_SDL_AUDIO TRUE)
  343. endif()
  344. endif()
  345. endmacro()
  346. # Requires:
  347. # - SDL_LIBSAMPLERATE
  348. # Optional:
  349. # - SDL_LIBSAMPLERATE_SHARED opt
  350. # - HAVE_SDL_LOADSO opt
  351. macro(CheckLibSampleRate)
  352. if(SDL_LIBSAMPLERATE)
  353. check_include_file(samplerate.h HAVE_LIBSAMPLERATE_H)
  354. if(HAVE_LIBSAMPLERATE_H)
  355. set(HAVE_LIBSAMPLERATE TRUE)
  356. if(SDL_LIBSAMPLERATE_SHARED AND NOT HAVE_SDL_LOADSO)
  357. message_warn("You must have SDL_LoadObject() support for dynamic libsamplerate loading")
  358. endif()
  359. if(SDL_LIBSAMPLERATE_SHARED AND HAVE_SDL_LOADSO)
  360. FindLibraryAndSONAME("samplerate")
  361. set(SDL_LIBSAMPLERATE_DYNAMIC "\"${SAMPLERATE_LIB_SONAME}\"")
  362. set(HAVE_LIBSAMPLERATE_SHARED TRUE)
  363. else()
  364. list(APPEND EXTRA_LDFLAGS -lsamplerate)
  365. endif()
  366. endif()
  367. endif()
  368. endmacro()
  369. # Requires:
  370. # - n/a
  371. # Optional:
  372. # - SDL_X11_SHARED opt
  373. # - HAVE_SDL_LOADSO opt
  374. macro(CheckX11)
  375. if(SDL_X11)
  376. foreach(_LIB X11 Xext Xcursor Xinerama Xi Xfixes Xrandr Xrender Xss Xxf86vm)
  377. FindLibraryAndSONAME("${_LIB}")
  378. endforeach()
  379. find_path(X_INCLUDEDIR X11/Xlib.h
  380. /usr/pkg/xorg/include
  381. /usr/X11R6/include
  382. /usr/X11R7/include
  383. /usr/local/include/X11
  384. /usr/include/X11
  385. /usr/openwin/include
  386. /usr/openwin/share/include
  387. /opt/graphics/OpenGL/include
  388. /opt/X11/include
  389. )
  390. if(X_INCLUDEDIR)
  391. list(APPEND EXTRA_CFLAGS "-I${X_INCLUDEDIR}")
  392. list(APPEND CMAKE_REQUIRED_INCLUDES "${X_INCLUDEDIR}")
  393. endif()
  394. check_include_file(X11/Xcursor/Xcursor.h HAVE_XCURSOR_H)
  395. check_include_file(X11/extensions/Xinerama.h HAVE_XINERAMA_H)
  396. check_include_file(X11/extensions/XInput2.h HAVE_XINPUT2_H)
  397. check_include_file(X11/extensions/Xrandr.h HAVE_XRANDR_H)
  398. check_include_file(X11/extensions/Xfixes.h HAVE_XFIXES_H_)
  399. check_include_file(X11/extensions/Xrender.h HAVE_XRENDER_H)
  400. check_include_file(X11/extensions/scrnsaver.h HAVE_XSS_H)
  401. check_include_file(X11/extensions/shape.h HAVE_XSHAPE_H)
  402. check_include_files("X11/Xlib.h;X11/extensions/Xdbe.h" HAVE_XDBE_H)
  403. check_include_files("X11/Xlib.h;X11/extensions/xf86vmode.h" HAVE_XF86VM_H)
  404. check_include_files("X11/Xlib.h;X11/Xproto.h;X11/extensions/Xext.h" HAVE_XEXT_H)
  405. if(X11_LIB)
  406. if(NOT HAVE_XEXT_H)
  407. message_error("Missing Xext.h, maybe you need to install the libxext-dev package?")
  408. endif()
  409. set(HAVE_X11 TRUE)
  410. set(HAVE_SDL_VIDEO TRUE)
  411. file(GLOB X11_SOURCES ${SDL2_SOURCE_DIR}/src/video/x11/*.c)
  412. set(SOURCE_FILES ${SOURCE_FILES} ${X11_SOURCES})
  413. set(SDL_VIDEO_DRIVER_X11 1)
  414. # !!! FIXME: why is this disabled for Apple?
  415. if(APPLE)
  416. set(SDL_X11_SHARED OFF)
  417. endif()
  418. check_symbol_exists(shmat "sys/shm.h" HAVE_SHMAT)
  419. if(NOT HAVE_SHMAT)
  420. check_library_exists(ipc shmat "" HAVE_SHMAT)
  421. if(HAVE_SHMAT)
  422. list(APPEND EXTRA_LIBS ipc)
  423. endif()
  424. if(NOT HAVE_SHMAT)
  425. list(APPEND EXTRA_CFLAGS "-DNO_SHARED_MEMORY")
  426. endif()
  427. endif()
  428. if(SDL_X11_SHARED)
  429. if(NOT HAVE_SDL_LOADSO)
  430. message_warn("You must have SDL_LoadObject() support for dynamic X11 loading")
  431. set(HAVE_X11_SHARED FALSE)
  432. else()
  433. set(HAVE_X11_SHARED TRUE)
  434. endif()
  435. if(HAVE_X11_SHARED)
  436. set(SDL_VIDEO_DRIVER_X11_DYNAMIC "\"${X11_LIB_SONAME}\"")
  437. set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT "\"${XEXT_LIB_SONAME}\"")
  438. else()
  439. list(APPEND EXTRA_LIBS ${X11_LIB} ${XEXT_LIB})
  440. endif()
  441. else()
  442. list(APPEND EXTRA_LIBS ${X11_LIB} ${XEXT_LIB})
  443. endif()
  444. set(CMAKE_REQUIRED_LIBRARIES ${X11_LIB} ${X11_LIB})
  445. check_c_source_compiles("
  446. #include <X11/Xlib.h>
  447. int main(int argc, char **argv) {
  448. Display *display;
  449. XEvent event;
  450. XGenericEventCookie *cookie = &event.xcookie;
  451. XNextEvent(display, &event);
  452. XGetEventData(display, cookie);
  453. XFreeEventData(display, cookie);
  454. return 0; }" HAVE_XGENERICEVENT)
  455. if(HAVE_XGENERICEVENT)
  456. set(SDL_VIDEO_DRIVER_X11_SUPPORTS_GENERIC_EVENTS 1)
  457. endif()
  458. check_symbol_exists(XkbKeycodeToKeysym "X11/Xlib.h;X11/XKBlib.h" SDL_VIDEO_DRIVER_X11_HAS_XKBKEYCODETOKEYSYM)
  459. if(SDL_X11_XCURSOR AND HAVE_XCURSOR_H)
  460. set(HAVE_X11_XCURSOR TRUE)
  461. if(HAVE_X11_SHARED AND XCURSOR_LIB)
  462. set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XCURSOR "\"${XCURSOR_LIB_SONAME}\"")
  463. else()
  464. list(APPEND EXTRA_LIBS ${XCURSOR_LIB})
  465. endif()
  466. set(SDL_VIDEO_DRIVER_X11_XCURSOR 1)
  467. endif()
  468. if(SDL_X11_XDBE AND HAVE_XDBE_H)
  469. set(HAVE_X11_XDBE TRUE)
  470. set(SDL_VIDEO_DRIVER_X11_XDBE 1)
  471. endif()
  472. if(SDL_X11_XINERAMA AND HAVE_XINERAMA_H)
  473. set(HAVE_X11_XINERAMA TRUE)
  474. if(HAVE_X11_SHARED AND XINERAMA_LIB)
  475. set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XINERAMA "\"${XINERAMA_LIB_SONAME}\"")
  476. else()
  477. list(APPEND EXTRA_LIBS ${XINERAMA_LIB})
  478. endif()
  479. set(SDL_VIDEO_DRIVER_X11_XINERAMA 1)
  480. endif()
  481. if(SDL_X11_XINPUT AND HAVE_XINPUT2_H)
  482. set(HAVE_X11_XINPUT TRUE)
  483. if(HAVE_X11_SHARED AND XI_LIB)
  484. set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT2 "\"${XI_LIB_SONAME}\"")
  485. else()
  486. list(APPEND EXTRA_LIBS ${XI_LIB})
  487. endif()
  488. set(SDL_VIDEO_DRIVER_X11_XINPUT2 1)
  489. # Check for multitouch
  490. check_c_source_compiles("
  491. #include <X11/Xlib.h>
  492. #include <X11/Xproto.h>
  493. #include <X11/extensions/XInput2.h>
  494. int event_type = XI_TouchBegin;
  495. XITouchClassInfo *t;
  496. Status XIAllowTouchEvents(Display *a,int b,unsigned int c,Window d,int f) {
  497. return (Status)0;
  498. }
  499. int main(int argc, char **argv) { return 0; }" HAVE_XINPUT2_MULTITOUCH)
  500. if(HAVE_XINPUT2_MULTITOUCH)
  501. set(SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH 1)
  502. endif()
  503. endif()
  504. # check along with XInput2.h because we use Xfixes with XIBarrierReleasePointer
  505. if(SDL_X11_XFIXES AND HAVE_XFIXES_H_ AND HAVE_XINPUT2_H)
  506. check_c_source_compiles("
  507. #include <X11/Xlib.h>
  508. #include <X11/Xproto.h>
  509. #include <X11/extensions/XInput2.h>
  510. #include <X11/extensions/Xfixes.h>
  511. BarrierEventID b;
  512. int main(int argc, char **argv) { return 0; }" HAVE_XFIXES_H)
  513. endif()
  514. if(SDL_X11_XFIXES AND HAVE_XFIXES_H AND HAVE_XINPUT2_H)
  515. if(HAVE_X11_SHARED AND XFIXES_LIB)
  516. set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XFIXES "\"${XFIXES_LIB_SONAME}\"")
  517. else()
  518. list(APPEND EXTRA_LIBS ${XFIXES_LIB})
  519. endif()
  520. set(SDL_VIDEO_DRIVER_X11_XFIXES 1)
  521. set(HAVE_X11_XFIXES TRUE)
  522. endif()
  523. if(SDL_X11_XRANDR AND HAVE_XRANDR_H)
  524. if(HAVE_X11_SHARED AND XRANDR_LIB)
  525. set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR "\"${XRANDR_LIB_SONAME}\"")
  526. else()
  527. list(APPEND EXTRA_LIBS ${XRANDR_LIB})
  528. endif()
  529. set(SDL_VIDEO_DRIVER_X11_XRANDR 1)
  530. set(HAVE_X11_XRANDR TRUE)
  531. endif()
  532. if(SDL_X11_XSCRNSAVER AND HAVE_XSS_H)
  533. if(HAVE_X11_SHARED AND XSS_LIB)
  534. set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XSS "\"${XSS_LIB_SONAME}\"")
  535. else()
  536. list(APPEND EXTRA_LIBS ${XSS_LIB})
  537. endif()
  538. set(SDL_VIDEO_DRIVER_X11_XSCRNSAVER 1)
  539. set(HAVE_X11_XSCRNSAVER TRUE)
  540. endif()
  541. if(SDL_X11_XSHAPE AND HAVE_XSHAPE_H)
  542. set(SDL_VIDEO_DRIVER_X11_XSHAPE 1)
  543. set(HAVE_X11_XSHAPE TRUE)
  544. endif()
  545. if(SDL_X11_XVM AND HAVE_XF86VM_H)
  546. if(HAVE_X11_SHARED AND XXF86VM_LIB)
  547. set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XVIDMODE "\"${XXF86VM_LIB_SONAME}\"")
  548. else()
  549. list(APPEND EXTRA_LIBS ${XXF86VM_LIB})
  550. endif()
  551. set(SDL_VIDEO_DRIVER_X11_XVIDMODE 1)
  552. set(HAVE_X11_XVM TRUE)
  553. endif()
  554. set(CMAKE_REQUIRED_LIBRARIES)
  555. endif()
  556. endif()
  557. if(NOT HAVE_X11)
  558. # Prevent Mesa from including X11 headers
  559. list(APPEND EXTRA_CFLAGS "-DMESA_EGL_NO_X11_HEADERS -DEGL_NO_X11")
  560. endif()
  561. endmacro()
  562. macro(WaylandProtocolGen _SCANNER _CODE_MODE _XML _PROTL)
  563. set(_WAYLAND_PROT_C_CODE "${CMAKE_CURRENT_BINARY_DIR}/wayland-generated-protocols/${_PROTL}-protocol.c")
  564. set(_WAYLAND_PROT_H_CODE "${CMAKE_CURRENT_BINARY_DIR}/wayland-generated-protocols/${_PROTL}-client-protocol.h")
  565. add_custom_command(
  566. OUTPUT "${_WAYLAND_PROT_H_CODE}"
  567. DEPENDS "${_XML}"
  568. COMMAND "${_SCANNER}"
  569. ARGS client-header "${_XML}" "${_WAYLAND_PROT_H_CODE}"
  570. )
  571. add_custom_command(
  572. OUTPUT "${_WAYLAND_PROT_C_CODE}"
  573. DEPENDS "${_WAYLAND_PROT_H_CODE}"
  574. COMMAND "${_SCANNER}"
  575. ARGS "${_CODE_MODE}" "${_XML}" "${_WAYLAND_PROT_C_CODE}"
  576. )
  577. set(SOURCE_FILES ${SOURCE_FILES} "${_WAYLAND_PROT_C_CODE}")
  578. endmacro()
  579. # Requires:
  580. # - EGL
  581. # - PkgCheckModules
  582. # Optional:
  583. # - SDL_WAYLAND_SHARED opt
  584. # - HAVE_SDL_LOADSO opt
  585. macro(CheckWayland)
  586. if(SDL_WAYLAND)
  587. pkg_check_modules(WAYLAND "wayland-client>=1.18" wayland-egl wayland-cursor egl "xkbcommon>=0.5.0")
  588. if(WAYLAND_FOUND)
  589. find_program(WAYLAND_SCANNER NAMES wayland-scanner REQUIRED)
  590. execute_process(
  591. COMMAND ${WAYLAND_SCANNER} --version
  592. RESULT_VARIABLE WAYLAND_SCANNER_VERSION_RC
  593. ERROR_VARIABLE WAYLAND_SCANNER_VERSION
  594. ERROR_STRIP_TRAILING_WHITESPACE
  595. )
  596. if(NOT WAYLAND_SCANNER_VERSION_RC EQUAL 0)
  597. message(FATAL "Failed to get wayland-scanner version")
  598. set(WAYLAND_FOUND FALSE)
  599. endif()
  600. string(REPLACE "wayland-scanner " "" WAYLAND_SCANNER_VERSION ${WAYLAND_SCANNER_VERSION})
  601. string(COMPARE LESS ${WAYLAND_SCANNER_VERSION} "1.15.0" WAYLAND_SCANNER_PRE_1_15)
  602. if(WAYLAND_SCANNER_PRE_1_15)
  603. set(WAYLAND_SCANNER_CODE_MODE "code")
  604. else()
  605. set(WAYLAND_SCANNER_CODE_MODE "private-code")
  606. endif()
  607. endif()
  608. if(WAYLAND_FOUND)
  609. target_link_directories(sdl-build-options INTERFACE "${WAYLAND_LIBRARY_DIRS}")
  610. target_include_directories(sdl-build-options INTERFACE "${WAYLAND_INCLUDE_DIRS}")
  611. set(HAVE_WAYLAND TRUE)
  612. set(HAVE_SDL_VIDEO TRUE)
  613. file(GLOB WAYLAND_SOURCES ${SDL2_SOURCE_DIR}/src/video/wayland/*.c)
  614. set(SOURCE_FILES ${SOURCE_FILES} ${WAYLAND_SOURCES})
  615. # We have to generate some protocol interface code for some unstable Wayland features.
  616. file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/wayland-generated-protocols")
  617. target_include_directories(sdl-build-options INTERFACE "${CMAKE_CURRENT_BINARY_DIR}/wayland-generated-protocols")
  618. file(GLOB WAYLAND_PROTOCOLS_XML RELATIVE "${SDL2_SOURCE_DIR}/wayland-protocols/" "${SDL2_SOURCE_DIR}/wayland-protocols/*.xml")
  619. foreach(_XML ${WAYLAND_PROTOCOLS_XML})
  620. string(REGEX REPLACE "\\.xml$" "" _PROTL "${_XML}")
  621. WaylandProtocolGen("${WAYLAND_SCANNER}" "${WAYLAND_SCANNER_CODE_MODE}" "${SDL2_SOURCE_DIR}/wayland-protocols/${_XML}" "${_PROTL}")
  622. endforeach()
  623. if(SDL_WAYLAND_QT_TOUCH)
  624. set(HAVE_WAYLAND_QT_TOUCH TRUE)
  625. set(SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH 1)
  626. endif()
  627. if(SDL_WAYLAND_SHARED AND NOT HAVE_SDL_LOADSO)
  628. message_warn("You must have SDL_LoadObject() support for dynamic Wayland loading")
  629. endif()
  630. if(SDL_WAYLAND_SHARED AND HAVE_SDL_LOADSO)
  631. FindLibraryAndSONAME(wayland-client)
  632. FindLibraryAndSONAME(wayland-egl)
  633. FindLibraryAndSONAME(wayland-cursor)
  634. FindLibraryAndSONAME(xkbcommon)
  635. set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC "\"${WAYLAND_CLIENT_LIB_SONAME}\"")
  636. set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_EGL "\"${WAYLAND_EGL_LIB_SONAME}\"")
  637. set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_CURSOR "\"${WAYLAND_CURSOR_LIB_SONAME}\"")
  638. set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_XKBCOMMON "\"${XKBCOMMON_LIB_SONAME}\"")
  639. set(HAVE_WAYLAND_SHARED TRUE)
  640. else()
  641. set(EXTRA_LIBS ${WAYLAND_LIBRARIES} ${EXTRA_LIBS})
  642. endif()
  643. if(SDL_WAYLAND_LIBDECOR)
  644. pkg_check_modules(LIBDECOR libdecor-0)
  645. if(LIBDECOR_FOUND)
  646. set(HAVE_WAYLAND_LIBDECOR TRUE)
  647. set(HAVE_LIBDECOR_H 1)
  648. target_link_directories(sdl-build-options INTERFACE "${LIBDECOR_LIBRARY_DIRS}")
  649. target_include_directories(sdl-build-options INTERFACE "${LIBDECOR_INCLUDE_DIRS}")
  650. if(SDL_WAYLAND_LIBDECOR_SHARED AND NOT HAVE_SDL_LOADSO)
  651. message_warn("You must have SDL_LoadObject() support for dynamic libdecor loading")
  652. endif()
  653. if(SDL_WAYLAND_LIBDECOR_SHARED AND HAVE_SDL_LOADSO)
  654. set(HAVE_LIBDECOR_SHARED TRUE)
  655. FindLibraryAndSONAME(decor-0)
  656. set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_LIBDECOR "\"${DECOR_0_LIB_SONAME}\"")
  657. else()
  658. set(EXTRA_LIBS ${LIBDECOR_LIBRARIES} ${EXTRA_LIBS})
  659. endif()
  660. endif()
  661. endif()
  662. set(SDL_VIDEO_DRIVER_WAYLAND 1)
  663. endif()
  664. endif()
  665. endmacro()
  666. # Requires:
  667. # - n/a
  668. #
  669. macro(CheckCOCOA)
  670. if(SDL_COCOA)
  671. if(APPLE) # Apple always has Cocoa.
  672. set(HAVE_COCOA TRUE)
  673. endif()
  674. if(HAVE_COCOA)
  675. file(GLOB COCOA_SOURCES ${SDL2_SOURCE_DIR}/src/video/cocoa/*.m)
  676. set_source_files_properties(${COCOA_SOURCES} PROPERTIES LANGUAGE C)
  677. set(SOURCE_FILES ${SOURCE_FILES} ${COCOA_SOURCES})
  678. set(SDL_VIDEO_DRIVER_COCOA 1)
  679. set(HAVE_SDL_VIDEO TRUE)
  680. endif()
  681. endif()
  682. endmacro()
  683. # Requires:
  684. # - PkgCheckModules
  685. # Optional:
  686. # - DIRECTFB_SHARED opt
  687. # - HAVE_SDL_LOADSO opt
  688. macro(CheckDirectFB)
  689. if(SDL_DIRECTFB)
  690. pkg_check_modules(PKG_DIRECTFB directfb>=1.0.0)
  691. if(PKG_DIRECTFB_FOUND)
  692. set(HAVE_DIRECTFB TRUE)
  693. file(GLOB DIRECTFB_SOURCES ${SDL2_SOURCE_DIR}/src/video/directfb/*.c)
  694. set(SOURCE_FILES ${SOURCE_FILES} ${DIRECTFB_SOURCES})
  695. set(SDL_VIDEO_DRIVER_DIRECTFB 1)
  696. set(SDL_VIDEO_RENDER_DIRECTFB 1)
  697. list(APPEND EXTRA_CFLAGS ${PKG_DIRECTFB_CFLAGS})
  698. if(SDL_DIRECTFB_SHARED AND NOT HAVE_SDL_LOADSO)
  699. message_warn("You must have SDL_LoadObject() support for dynamic DirectFB loading")
  700. endif()
  701. if(SDL_DIRECTFB_SHARED AND HAVE_SDL_LOADSO)
  702. FindLibraryAndSONAME("directfb")
  703. set(SDL_VIDEO_DRIVER_DIRECTFB_DYNAMIC "\"${DIRECTFB_LIB_SONAME}\"")
  704. set(HAVE_DIRECTFB_SHARED TRUE)
  705. else()
  706. list(APPEND EXTRA_LDFLAGS ${PKG_DIRECTFB_LDFLAGS})
  707. endif()
  708. set(HAVE_SDL_VIDEO TRUE)
  709. endif()
  710. endif()
  711. endmacro()
  712. # Requires:
  713. # - n/a
  714. macro(CheckVivante)
  715. if(SDL_VIVANTE)
  716. check_c_source_compiles("
  717. #include <gc_vdk.h>
  718. int main(int argc, char** argv) { return 0; }" HAVE_VIVANTE_VDK)
  719. check_c_source_compiles("
  720. #define LINUX
  721. #define EGL_API_FB
  722. #include <EGL/eglvivante.h>
  723. int main(int argc, char** argv) { return 0; }" HAVE_VIVANTE_EGL_FB)
  724. if(HAVE_VIVANTE_VDK OR HAVE_VIVANTE_EGL_FB)
  725. set(HAVE_VIVANTE TRUE)
  726. set(HAVE_SDL_VIDEO TRUE)
  727. file(GLOB VIVANTE_SOURCES ${SDL2_SOURCE_DIR}/src/video/vivante/*.c)
  728. set(SOURCE_FILES ${SOURCE_FILES} ${VIVANTE_SOURCES})
  729. set(SDL_VIDEO_DRIVER_VIVANTE 1)
  730. if(HAVE_VIVANTE_VDK)
  731. set(SDL_VIDEO_DRIVER_VIVANTE_VDK 1)
  732. find_library(VIVANTE_LIBRARY REQUIRED NAMES VIVANTE vivante drm_vivante)
  733. find_library(VIVANTE_VDK_LIBRARY VDK REQUIRED)
  734. list(APPEND EXTRA_LIBS ${VIVANTE_LIBRARY} ${VIVANTE_VDK_LIBRARY})
  735. else()
  736. set(SDL_CFLAGS "${SDL_CFLAGS} -DLINUX -DEGL_API_FB")
  737. list(APPEND EXTRA_LIBS EGL)
  738. endif(HAVE_VIVANTE_VDK)
  739. endif()
  740. endif()
  741. endmacro()
  742. # Requires:
  743. # - nada
  744. macro(CheckGLX)
  745. if(SDL_OPENGL)
  746. check_c_source_compiles("
  747. #include <GL/glx.h>
  748. int main(int argc, char** argv) { return 0; }" HAVE_OPENGL_GLX)
  749. if(HAVE_OPENGL_GLX)
  750. set(SDL_VIDEO_OPENGL_GLX 1)
  751. endif()
  752. endif()
  753. endmacro()
  754. # Requires:
  755. # - PkgCheckModules
  756. macro(CheckEGL)
  757. if (SDL_OPENGL OR SDL_OPENGLES)
  758. pkg_check_modules(EGL egl)
  759. set(CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS} ${EGL_CFLAGS}")
  760. check_c_source_compiles("
  761. #define EGL_API_FB
  762. #define MESA_EGL_NO_X11_HEADERS
  763. #define EGL_NO_X11
  764. #include <EGL/egl.h>
  765. #include <EGL/eglext.h>
  766. int main (int argc, char** argv) { return 0; }" HAVE_OPENGL_EGL)
  767. if(HAVE_OPENGL_EGL)
  768. set(SDL_VIDEO_OPENGL_EGL 1)
  769. endif()
  770. endif()
  771. endmacro()
  772. # Requires:
  773. # - nada
  774. macro(CheckOpenGL)
  775. if(SDL_OPENGL)
  776. check_c_source_compiles("
  777. #include <GL/gl.h>
  778. #include <GL/glext.h>
  779. int main(int argc, char** argv) { return 0; }" HAVE_OPENGL)
  780. if(HAVE_OPENGL)
  781. set(SDL_VIDEO_OPENGL 1)
  782. set(SDL_VIDEO_RENDER_OGL 1)
  783. endif()
  784. endif()
  785. endmacro()
  786. # Requires:
  787. # - nada
  788. macro(CheckOpenGLES)
  789. if(SDL_OPENGLES)
  790. check_c_source_compiles("
  791. #include <GLES/gl.h>
  792. #include <GLES/glext.h>
  793. int main (int argc, char** argv) { return 0; }" HAVE_OPENGLES_V1)
  794. if(HAVE_OPENGLES_V1)
  795. set(HAVE_OPENGLES TRUE)
  796. set(SDL_VIDEO_OPENGL_ES 1)
  797. set(SDL_VIDEO_RENDER_OGL_ES 1)
  798. endif()
  799. check_c_source_compiles("
  800. #include <GLES2/gl2.h>
  801. #include <GLES2/gl2ext.h>
  802. int main (int argc, char** argv) { return 0; }" HAVE_OPENGLES_V2)
  803. if(HAVE_OPENGLES_V2)
  804. set(HAVE_OPENGLES TRUE)
  805. set(SDL_VIDEO_OPENGL_ES2 1)
  806. set(SDL_VIDEO_RENDER_OGL_ES2 1)
  807. endif()
  808. endif()
  809. endmacro()
  810. # Requires:
  811. # - nada
  812. # Optional:
  813. # - THREADS opt
  814. # Sets:
  815. # PTHREAD_CFLAGS
  816. # PTHREAD_LIBS
  817. macro(CheckPTHREAD)
  818. if(SDL_THREADS AND SDL_PTHREADS)
  819. if(ANDROID)
  820. # the android libc provides built-in support for pthreads, so no
  821. # additional linking or compile flags are necessary
  822. elseif(LINUX)
  823. set(PTHREAD_CFLAGS "-D_REENTRANT")
  824. set(PTHREAD_LDFLAGS "-pthread")
  825. elseif(BSDI)
  826. set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
  827. set(PTHREAD_LDFLAGS "")
  828. elseif(DARWIN)
  829. set(PTHREAD_CFLAGS "-D_THREAD_SAFE")
  830. # causes Carbon.p complaints?
  831. # set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
  832. set(PTHREAD_LDFLAGS "")
  833. elseif(FREEBSD)
  834. set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
  835. set(PTHREAD_LDFLAGS "-pthread")
  836. elseif(NETBSD)
  837. set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
  838. set(PTHREAD_LDFLAGS "-lpthread")
  839. elseif(OPENBSD)
  840. set(PTHREAD_CFLAGS "-D_REENTRANT")
  841. set(PTHREAD_LDFLAGS "-pthread")
  842. elseif(SOLARIS)
  843. set(PTHREAD_CFLAGS "-D_REENTRANT")
  844. set(PTHREAD_LDFLAGS "-pthread -lposix4")
  845. elseif(SYSV5)
  846. set(PTHREAD_CFLAGS "-D_REENTRANT -Kthread")
  847. set(PTHREAD_LDFLAGS "")
  848. elseif(AIX)
  849. set(PTHREAD_CFLAGS "-D_REENTRANT -mthreads")
  850. set(PTHREAD_LDFLAGS "-pthread")
  851. elseif(HPUX)
  852. set(PTHREAD_CFLAGS "-D_REENTRANT")
  853. set(PTHREAD_LDFLAGS "-L/usr/lib -pthread")
  854. elseif(HAIKU)
  855. set(PTHREAD_CFLAGS "-D_REENTRANT")
  856. set(PTHREAD_LDFLAGS "")
  857. elseif(EMSCRIPTEN)
  858. set(PTHREAD_CFLAGS "-D_REENTRANT -pthread")
  859. set(PTHREAD_LDFLAGS "-pthread")
  860. else()
  861. set(PTHREAD_CFLAGS "-D_REENTRANT")
  862. set(PTHREAD_LDFLAGS "-lpthread")
  863. endif()
  864. # Run some tests
  865. set(ORIG_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
  866. set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${PTHREAD_CFLAGS} ${PTHREAD_LDFLAGS}")
  867. check_c_source_compiles("
  868. #include <pthread.h>
  869. int main(int argc, char** argv) {
  870. pthread_attr_t type;
  871. pthread_attr_init(&type);
  872. return 0;
  873. }" HAVE_PTHREADS)
  874. if(HAVE_PTHREADS)
  875. set(SDL_THREAD_PTHREAD 1)
  876. list(APPEND EXTRA_CFLAGS ${PTHREAD_CFLAGS})
  877. list(APPEND EXTRA_LDFLAGS ${PTHREAD_LDFLAGS})
  878. set(SDL_CFLAGS "${SDL_CFLAGS} ${PTHREAD_CFLAGS}")
  879. list(APPEND SDL_LIBS ${PTHREAD_LDFLAGS})
  880. check_c_source_compiles("
  881. #define _GNU_SOURCE 1
  882. #include <pthread.h>
  883. int main(int argc, char **argv) {
  884. pthread_mutexattr_t attr;
  885. pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
  886. return 0;
  887. }" HAVE_RECURSIVE_MUTEXES)
  888. if(HAVE_RECURSIVE_MUTEXES)
  889. set(SDL_THREAD_PTHREAD_RECURSIVE_MUTEX 1)
  890. else()
  891. check_c_source_compiles("
  892. #define _GNU_SOURCE 1
  893. #include <pthread.h>
  894. int main(int argc, char **argv) {
  895. pthread_mutexattr_t attr;
  896. pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE_NP);
  897. return 0;
  898. }" HAVE_RECURSIVE_MUTEXES_NP)
  899. if(HAVE_RECURSIVE_MUTEXES_NP)
  900. set(SDL_THREAD_PTHREAD_RECURSIVE_MUTEX_NP 1)
  901. endif()
  902. endif()
  903. if(SDL_PTHREADS_SEM)
  904. check_c_source_compiles("#include <pthread.h>
  905. #include <semaphore.h>
  906. int main(int argc, char **argv) { return 0; }" HAVE_PTHREADS_SEM)
  907. if(HAVE_PTHREADS_SEM)
  908. check_c_source_compiles("
  909. #include <pthread.h>
  910. #include <semaphore.h>
  911. int main(int argc, char **argv) {
  912. sem_timedwait(NULL, NULL);
  913. return 0;
  914. }" HAVE_SEM_TIMEDWAIT)
  915. endif()
  916. endif()
  917. check_include_files("pthread.h" HAVE_PTHREAD_H)
  918. check_include_files("pthread_np.h" HAVE_PTHREAD_NP_H)
  919. if (HAVE_PTHREAD_H)
  920. check_c_source_compiles("
  921. #define _GNU_SOURCE 1
  922. #include <pthread.h>
  923. int main(int argc, char **argv) {
  924. pthread_setname_np(pthread_self(), \"\");
  925. return 0;
  926. }" HAVE_PTHREAD_SETNAME_NP)
  927. if (HAVE_PTHREAD_NP_H)
  928. check_symbol_exists(pthread_set_name_np "pthread.h;pthread_np.h" HAVE_PTHREAD_SET_NAME_NP)
  929. endif()
  930. endif()
  931. set(SOURCE_FILES ${SOURCE_FILES}
  932. ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_systhread.c
  933. ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_sysmutex.c # Can be faked, if necessary
  934. ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_syscond.c # Can be faked, if necessary
  935. ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_systls.c
  936. )
  937. if(HAVE_PTHREADS_SEM)
  938. set(SOURCE_FILES ${SOURCE_FILES}
  939. ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_syssem.c)
  940. else()
  941. set(SOURCE_FILES ${SOURCE_FILES}
  942. ${SDL2_SOURCE_DIR}/src/thread/generic/SDL_syssem.c)
  943. endif()
  944. set(HAVE_SDL_THREADS TRUE)
  945. endif()
  946. set(CMAKE_REQUIRED_FLAGS "${ORIG_CMAKE_REQUIRED_FLAGS}")
  947. endif()
  948. endmacro()
  949. # Requires
  950. # - nada
  951. # Optional:
  952. # Sets:
  953. # USB_LIBS
  954. # USB_CFLAGS
  955. macro(CheckUSBHID)
  956. check_library_exists(usbhid hid_init "" LIBUSBHID)
  957. if(LIBUSBHID)
  958. check_include_file(usbhid.h HAVE_USBHID_H)
  959. if(HAVE_USBHID_H)
  960. set(USB_CFLAGS "-DHAVE_USBHID_H")
  961. endif()
  962. check_include_file(libusbhid.h HAVE_LIBUSBHID_H)
  963. if(HAVE_LIBUSBHID_H)
  964. set(USB_CFLAGS "${USB_CFLAGS} -DHAVE_LIBUSBHID_H")
  965. endif()
  966. set(USB_LIBS ${USB_LIBS} usbhid)
  967. else()
  968. check_include_file(usb.h HAVE_USB_H)
  969. if(HAVE_USB_H)
  970. set(USB_CFLAGS "-DHAVE_USB_H")
  971. endif()
  972. check_include_file(libusb.h HAVE_LIBUSB_H)
  973. if(HAVE_LIBUSB_H)
  974. set(USB_CFLAGS "${USB_CFLAGS} -DHAVE_LIBUSB_H")
  975. endif()
  976. check_library_exists(usb hid_init "" LIBUSB)
  977. if(LIBUSB)
  978. set(USB_LIBS ${USB_LIBS} usb)
  979. endif()
  980. endif()
  981. set(ORIG_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
  982. set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${USB_CFLAGS}")
  983. set(CMAKE_REQUIRED_LIBRARIES "${USB_LIBS}")
  984. check_c_source_compiles("
  985. #include <sys/types.h>
  986. #if defined(HAVE_USB_H)
  987. #include <usb.h>
  988. #endif
  989. #ifdef __DragonFly__
  990. # include <bus/u4b/usb.h>
  991. # include <bus/u4b/usbhid.h>
  992. #else
  993. # include <dev/usb/usb.h>
  994. # include <dev/usb/usbhid.h>
  995. #endif
  996. #if defined(HAVE_USBHID_H)
  997. #include <usbhid.h>
  998. #elif defined(HAVE_LIBUSB_H)
  999. #include <libusb.h>
  1000. #elif defined(HAVE_LIBUSBHID_H)
  1001. #include <libusbhid.h>
  1002. #endif
  1003. int main(int argc, char **argv) {
  1004. struct report_desc *repdesc;
  1005. struct usb_ctl_report *repbuf;
  1006. hid_kind_t hidkind;
  1007. return 0;
  1008. }" HAVE_USBHID)
  1009. if(HAVE_USBHID)
  1010. check_c_source_compiles("
  1011. #include <sys/types.h>
  1012. #if defined(HAVE_USB_H)
  1013. #include <usb.h>
  1014. #endif
  1015. #ifdef __DragonFly__
  1016. # include <bus/u4b/usb.h>
  1017. # include <bus/u4b/usbhid.h>
  1018. #else
  1019. # include <dev/usb/usb.h>
  1020. # include <dev/usb/usbhid.h>
  1021. #endif
  1022. #if defined(HAVE_USBHID_H)
  1023. #include <usbhid.h>
  1024. #elif defined(HAVE_LIBUSB_H)
  1025. #include <libusb.h>
  1026. #elif defined(HAVE_LIBUSBHID_H)
  1027. #include <libusbhid.h>
  1028. #endif
  1029. int main(int argc, char** argv) {
  1030. struct usb_ctl_report buf;
  1031. if (buf.ucr_data) { }
  1032. return 0;
  1033. }" HAVE_USBHID_UCR_DATA)
  1034. if(HAVE_USBHID_UCR_DATA)
  1035. set(USB_CFLAGS "${USB_CFLAGS} -DUSBHID_UCR_DATA")
  1036. endif()
  1037. check_c_source_compiles("
  1038. #include <sys/types.h>
  1039. #if defined(HAVE_USB_H)
  1040. #include <usb.h>
  1041. #endif
  1042. #ifdef __DragonFly__
  1043. #include <bus/u4b/usb.h>
  1044. #include <bus/u4b/usbhid.h>
  1045. #else
  1046. #include <dev/usb/usb.h>
  1047. #include <dev/usb/usbhid.h>
  1048. #endif
  1049. #if defined(HAVE_USBHID_H)
  1050. #include <usbhid.h>
  1051. #elif defined(HAVE_LIBUSB_H)
  1052. #include <libusb.h>
  1053. #elif defined(HAVE_LIBUSBHID_H)
  1054. #include <libusbhid.h>
  1055. #endif
  1056. int main(int argc, char **argv) {
  1057. report_desc_t d;
  1058. hid_start_parse(d, 1, 1);
  1059. return 0;
  1060. }" HAVE_USBHID_NEW)
  1061. if(HAVE_USBHID_NEW)
  1062. set(USB_CFLAGS "${USB_CFLAGS} -DUSBHID_NEW")
  1063. endif()
  1064. check_c_source_compiles("
  1065. #include <machine/joystick.h>
  1066. int main(int argc, char** argv) {
  1067. struct joystick t;
  1068. return 0;
  1069. }" HAVE_MACHINE_JOYSTICK)
  1070. if(HAVE_MACHINE_JOYSTICK)
  1071. set(SDL_HAVE_MACHINE_JOYSTICK_H 1)
  1072. endif()
  1073. set(SDL_JOYSTICK_USBHID 1)
  1074. file(GLOB BSD_JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/bsd/*.c)
  1075. set(SOURCE_FILES ${SOURCE_FILES} ${BSD_JOYSTICK_SOURCES})
  1076. list(APPEND EXTRA_CFLAGS ${USB_CFLAGS})
  1077. list(APPEND EXTRA_LIBS ${USB_LIBS})
  1078. set(HAVE_SDL_JOYSTICK TRUE)
  1079. set(CMAKE_REQUIRED_LIBRARIES)
  1080. set(CMAKE_REQUIRED_FLAGS "${ORIG_CMAKE_REQUIRED_FLAGS}")
  1081. endif()
  1082. endmacro()
  1083. # Check for HIDAPI support
  1084. macro(CheckHIDAPI)
  1085. set(HAVE_HIDAPI TRUE)
  1086. if(NOT HIDAPI_SKIP_LIBUSB)
  1087. set(HAVE_LIBUSB FALSE)
  1088. pkg_check_modules(LIBUSB libusb-1.0)
  1089. if (LIBUSB_FOUND)
  1090. check_include_file(libusb.h HAVE_LIBUSB_H ${LIBUSB_CFLAGS})
  1091. if(HAVE_LIBUSB_H)
  1092. set(HAVE_LIBUSB TRUE)
  1093. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${LIBUSB_CFLAGS}")
  1094. if(HIDAPI_ONLY_LIBUSB)
  1095. list(APPEND EXTRA_LIBS ${LIBUSB_LIBS})
  1096. elseif(OS2)
  1097. set(SDL_LIBUSB_DYNAMIC "\"usb100.dll\"")
  1098. else()
  1099. # libusb is loaded dynamically, so don't add it to EXTRA_LIBS
  1100. FindLibraryAndSONAME("usb-1.0")
  1101. set(SDL_LIBUSB_DYNAMIC "\"${USB_1.0_LIB_SONAME}\"")
  1102. endif()
  1103. endif()
  1104. endif()
  1105. if(HIDAPI_ONLY_LIBUSB AND NOT HAVE_LIBUSB)
  1106. set(HAVE_HIDAPI FALSE)
  1107. endif()
  1108. endif()
  1109. if(HAVE_HIDAPI)
  1110. if(ANDROID)
  1111. set(SOURCE_FILES ${SOURCE_FILES} ${SDL2_SOURCE_DIR}/src/hidapi/android/hid.cpp)
  1112. endif()
  1113. if(IOS OR TVOS)
  1114. set(SOURCE_FILES ${SOURCE_FILES} ${SDL2_SOURCE_DIR}/src/hidapi/ios/hid.m)
  1115. set(SDL_FRAMEWORK_COREBLUETOOTH 1)
  1116. endif()
  1117. set(HAVE_SDL_HIDAPI TRUE)
  1118. if(SDL_JOYSTICK AND SDL_HIDAPI_JOYSTICK)
  1119. set(SDL_JOYSTICK_HIDAPI 1)
  1120. set(HAVE_SDL_JOYSTICK TRUE)
  1121. set(HAVE_HIDAPI_JOYSTICK TRUE)
  1122. file(GLOB HIDAPI_JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/hidapi/*.c)
  1123. set(SOURCE_FILES ${SOURCE_FILES} ${HIDAPI_JOYSTICK_SOURCES})
  1124. endif()
  1125. endif()
  1126. endmacro()
  1127. # Requires:
  1128. # - n/a
  1129. macro(CheckRPI)
  1130. if(SDL_RPI)
  1131. pkg_check_modules(VIDEO_RPI bcm_host brcmegl)
  1132. if (NOT VIDEO_RPI_FOUND)
  1133. set(VIDEO_RPI_INCLUDE_DIRS "/opt/vc/include" "/opt/vc/include/interface/vcos/pthreads" "/opt/vc/include/interface/vmcs_host/linux/" )
  1134. set(VIDEO_RPI_LIBRARY_DIRS "/opt/vc/lib" )
  1135. set(VIDEO_RPI_LIBRARIES bcm_host )
  1136. set(VIDEO_RPI_LDFLAGS "-Wl,-rpath,/opt/vc/lib")
  1137. endif()
  1138. listtostr(VIDEO_RPI_INCLUDE_DIRS VIDEO_RPI_INCLUDE_FLAGS "-I")
  1139. listtostr(VIDEO_RPI_LIBRARY_DIRS VIDEO_RPI_LIBRARY_FLAGS "-L")
  1140. set(ORIG_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
  1141. set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${VIDEO_RPI_INCLUDE_FLAGS} ${VIDEO_RPI_LIBRARY_FLAGS}")
  1142. set(CMAKE_REQUIRED_LIBRARIES "${VIDEO_RPI_LIBRARIES}")
  1143. check_c_source_compiles("
  1144. #include <bcm_host.h>
  1145. #include <EGL/eglplatform.h>
  1146. int main(int argc, char **argv) {
  1147. EGL_DISPMANX_WINDOW_T window;
  1148. bcm_host_init();
  1149. }" HAVE_RPI)
  1150. set(CMAKE_REQUIRED_FLAGS "${ORIG_CMAKE_REQUIRED_FLAGS}")
  1151. set(CMAKE_REQUIRED_LIBRARIES)
  1152. if(SDL_VIDEO AND HAVE_RPI)
  1153. set(HAVE_SDL_VIDEO TRUE)
  1154. set(SDL_VIDEO_DRIVER_RPI 1)
  1155. file(GLOB VIDEO_RPI_SOURCES ${SDL2_SOURCE_DIR}/src/video/raspberry/*.c)
  1156. set(SOURCE_FILES ${SOURCE_FILES} ${VIDEO_RPI_SOURCES})
  1157. list(APPEND EXTRA_LIBS ${VIDEO_RPI_LIBRARIES})
  1158. # !!! FIXME: shouldn't be using CMAKE_C_FLAGS, right?
  1159. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${VIDEO_RPI_INCLUDE_FLAGS} ${VIDEO_RPI_LIBRARY_FLAGS}")
  1160. list(APPEND EXTRA_LDFLAGS ${VIDEO_RPI_LDFLAGS})
  1161. endif()
  1162. endif()
  1163. endmacro()
  1164. # Requires:
  1165. # - EGL
  1166. # - PkgCheckModules
  1167. # Optional:
  1168. # - SDL_KMSDRM_SHARED opt
  1169. # - HAVE_SDL_LOADSO opt
  1170. macro(CheckKMSDRM)
  1171. if(SDL_KMSDRM)
  1172. pkg_check_modules(KMSDRM libdrm gbm egl)
  1173. if(KMSDRM_FOUND AND HAVE_OPENGL_EGL)
  1174. link_directories(
  1175. ${KMSDRM_LIBRARY_DIRS}
  1176. )
  1177. target_include_directories(sdl-build-options INTERFACE "${KMSDRM_INCLUDE_DIRS}")
  1178. set(HAVE_KMSDRM TRUE)
  1179. set(HAVE_SDL_VIDEO TRUE)
  1180. file(GLOB KMSDRM_SOURCES ${SDL2_SOURCE_DIR}/src/video/kmsdrm/*.c)
  1181. set(SOURCE_FILES ${SOURCE_FILES} ${KMSDRM_SOURCES})
  1182. list(APPEND EXTRA_CFLAGS ${KMSDRM_CFLAGS})
  1183. set(SDL_VIDEO_DRIVER_KMSDRM 1)
  1184. if(SDL_KMSDRM_SHARED AND NOT HAVE_SDL_LOADSO)
  1185. message_warn("You must have SDL_LoadObject() support for dynamic KMS/DRM loading")
  1186. endif()
  1187. if(SDL_KMSDRM_SHARED AND HAVE_SDL_LOADSO)
  1188. FindLibraryAndSONAME(drm)
  1189. FindLibraryAndSONAME(gbm)
  1190. set(SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC "\"${DRM_LIB_SONAME}\"")
  1191. set(SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC_GBM "\"${GBM_LIB_SONAME}\"")
  1192. set(HAVE_KMSDRM_SHARED TRUE)
  1193. else()
  1194. set(EXTRA_LIBS ${KMSDRM_LIBRARIES} ${EXTRA_LIBS})
  1195. endif()
  1196. endif()
  1197. endif()
  1198. endmacro()