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