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

1293 lines
43 KiB

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