cmake/sdlchecks.cmake
author Ryan C. Gordon
Tue, 19 Nov 2013 15:00:39 -0500
changeset 8016 3746af784462
parent 7981 6d538bc1b395
child 8017 d84a30e5cbd5
permissions -rw-r--r--
-fvisibility=hidden is no longer a requirement for dynamic X11.

We don't clash with Xlib symbols anymore.
     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        int main(int argc, char **argv) {
    22          void *handle = dlopen(\"\", RTLD_NOW);
    23          const char *loaderror = (char *) dlerror();
    24        }" 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     find_path(X_INCLUDEDIR X11/Xlib.h)
   308     if(X_INCLUDEDIR)
   309       set(X_CFLAGS "-I${X_INCLUDEDIR}")
   310     endif()
   311 
   312     check_include_file(X11/Xcursor/Xcursor.h HAVE_XCURSOR_H)
   313     check_include_file(X11/extensions/Xinerama.h HAVE_XINERAMA_H)
   314     check_include_file(X11/extensions/XInput2.h HAVE_XINPUT_H)
   315     check_include_file(X11/extensions/Xrandr.h HAVE_XRANDR_H)
   316     check_include_file(X11/extensions/Xrender.h HAVE_XRENDER_H)
   317     check_include_file(X11/extensions/scrnsaver.h HAVE_XSS_H)
   318     check_include_file(X11/extensions/shape.h HAVE_XSHAPE_H)
   319     check_include_files("X11/Xlib.h;X11/extensions/xf86vmode.h" HAVE_XF86VM_H)
   320     check_include_files("X11/Xlib.h;X11/Xproto.h;X11/extensions/Xext.h" HAVE_XEXT_H)
   321 
   322     if(X11_LIB)
   323       if(NOT HAVE_XEXT_H)
   324         message_error("Missing Xext.h, maybe you need to install the libxext-dev package?")
   325       endif()
   326 
   327       set(HAVE_VIDEO_X11 TRUE)
   328       set(HAVE_SDL_VIDEO TRUE)
   329 
   330       file(GLOB X11_SOURCES ${SDL2_SOURCE_DIR}/src/video/x11/*.c)
   331       set(SOURCE_FILES ${SOURCE_FILES} ${X11_SOURCES})
   332       set(SDL_VIDEO_DRIVER_X11 1)
   333 
   334       if(APPLE)
   335         set(X11_SHARED OFF)
   336       endif(APPLE)
   337 
   338       check_function_exists("shmat" HAVE_SHMAT)
   339       if(NOT HAVE_SHMAT)
   340         check_library_exists(ipc shmat "" HAVE_SHMAT)
   341         if(HAVE_SHMAT)
   342           list(APPEND EXTRA_LIBS ipc)
   343         endif(HAVE_SHMAT)
   344         if(NOT HAVE_SHMAT)
   345           add_definitions(-DNO_SHARED_MEMORY)
   346           set(X_CFLAGS "${X_CFLAGS} -DNO_SHARED_MEMORY")
   347         endif(NOT HAVE_SHMAT)
   348       endif(NOT HAVE_SHMAT)
   349 
   350       if(X11_SHARED)
   351         if(NOT HAVE_DLOPEN)
   352           message_warn("You must have SDL_LoadObject() support for dynamic X11 loading")
   353           set(HAVE_X11_SHARED FALSE)
   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(SDL_CFLAGS "${SDL_CFLAGS} ${X_CFLAGS}")
   366 
   367       set(CMAKE_REQUIRED_LIBRARIES ${X11_LIB} ${X11_LIB})
   368       check_c_source_compiles("
   369           #include <X11/Xlib.h>
   370           #include <X11/Xproto.h>
   371           #include <X11/extensions/Xext.h>
   372           #include <X11/extensions/extutil.h>
   373           extern XExtDisplayInfo* XextAddDisplay(XExtensionInfo* a,Display* b,_Xconst char* c,XExtensionHooks* d,int e,XPointer f);
   374           int main(int argc, char **argv) {}" HAVE_CONST_XEXT_ADDDISPLAY)
   375       if(HAVE_CONST_XEXT_ADDDISPLAY)
   376         set(SDL_VIDEO_DRIVER_X11_CONST_PARAM_XEXTADDDISPLAY 1)
   377       endif(HAVE_CONST_XEXT_ADDDISPLAY)
   378 
   379       check_c_source_compiles("
   380           #include <X11/Xlib.h>
   381           int main(int argc, char **argv) {
   382             Display *display;
   383             XEvent event;
   384             XGenericEventCookie *cookie = &event.xcookie;
   385             XNextEvent(display, &event);
   386             XGetEventData(display, cookie);
   387             XFreeEventData(display, cookie); }" HAVE_XGENERICEVENT)
   388       if(HAVE_XGENERICEVENT)
   389         set(SDL_VIDEO_DRIVER_X11_SUPPORTS_GENERIC_EVENTS 1)
   390       endif(HAVE_XGENERICEVENT)
   391 
   392       check_c_source_compiles("
   393           #include <X11/Xlibint.h>
   394           extern int _XData32(Display *dpy,register _Xconst long *data,unsigned len);
   395           int main(int argc, char **argv) {}" HAVE_CONST_XDATA32)
   396       if(HAVE_CONST_XDATA32)
   397         set(SDL_VIDEO_DRIVER_X11_CONST_PARAM_XDATA32 1)
   398       endif(HAVE_CONST_XDATA32)
   399 
   400       check_function_exists(XkbKeycodeToKeysym SDL_VIDEO_DRIVER_X11_HAS_XKBKEYCODETOKEYSYM)
   401 
   402       if(VIDEO_X11_XCURSOR AND HAVE_XCURSOR_H)
   403         set(HAVE_VIDEO_X11_XCURSOR TRUE)
   404         if(HAVE_X11_SHARED AND XCURSOR_LIB)
   405           set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XCURSOR "\"${XCURSOR_LIB}\"")
   406         else(HAVE_X11_SHARED AND XCURSOR_LIB)
   407           list(APPEND EXTRA_LIBS ${XCURSOR_LIB})
   408         endif(HAVE_X11_SHARED AND XCURSOR_LIB)
   409         set(SDL_VIDEO_DRIVER_X11_XCURSOR 1)
   410       endif(VIDEO_X11_XCURSOR AND HAVE_XCURSOR_H)
   411 
   412       if(VIDEO_X11_XINERAMA AND HAVE_XINERAMA_H)
   413         set(HAVE_VIDEO_X11_XINERAMA TRUE)
   414         if(HAVE_X11_SHARED AND XINERAMA_LIB)
   415           set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XINERAMA "\"${XINERAMA_LIB}\"")
   416         else(HAVE_X11_SHARED AND XINERAMA_LIB)
   417           list(APPEND EXTRA_LIBS ${XINERAMA_LIB})
   418         endif(HAVE_X11_SHARED AND XINERAMA_LIB)
   419         set(SDL_VIDEO_DRIVER_X11_XINERAMA 1)
   420       endif(VIDEO_X11_XINERAMA AND HAVE_XINERAMA_H)
   421 
   422       if(VIDEO_X11_XINPUT AND HAVE_XINPUT_H)
   423         set(HAVE_VIDEO_X11_XINPUT TRUE)
   424         if(HAVE_X11_SHARED AND XI_LIB)
   425           set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT2 "\"${XI_LIB}\"")
   426         else(HAVE_X11_SHARED AND XI_LIB)
   427           list(APPEND EXTRA_LIBS ${XI_LIB})
   428         endif(HAVE_X11_SHARED AND XI_LIB)
   429         set(SDL_VIDEO_DRIVER_X11_XINPUT2 1)
   430 
   431         # Check for multitouch
   432         check_c_source_compiles("
   433             #include <X11/Xlib.h>
   434             #include <X11/Xproto.h>
   435             #include <X11/extensions/XInput2.h>
   436             int event_type = XI_TouchBegin;
   437             XITouchClassInfo *t;
   438             Status XIAllowTouchEvents(Display *a,int b,unsigned int c,Window d,int f)
   439             {
   440               return (Status)0;
   441             }
   442             int main(int argc, char **argv) {}" HAVE_XINPUT2_MULTITOUCH)
   443         if(HAVE_XINPUT2_MULTITOUCH)
   444           set(SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH 1)
   445         endif(HAVE_XINPUT2_MULTITOUCH)
   446       endif(VIDEO_X11_XINPUT AND HAVE_XINPUT_H)
   447 
   448       if(VIDEO_X11_XRANDR AND HAVE_XRANDR_H)
   449         if(HAVE_X11_SHARED AND XRANDR_LIB)
   450           set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR "\"${XRANDR_LIB}\"")
   451         else(HAVE_X11_SHARED AND XRANDR_LIB)
   452           list(APPEND EXTRA_LIBS ${XRANDR_LIB})
   453         endif(HAVE_X11_SHARED AND XRANDR_LIB)
   454         set(SDL_VIDEO_DRIVER_X11_XRANDR 1)
   455         set(HAVE_VIDEO_X11_XRANDR TRUE)
   456       endif(VIDEO_X11_XRANDR AND HAVE_XRANDR_H)
   457 
   458       if(VIDEO_X11_XSCRNSAVER AND HAVE_XSS_H)
   459         if(HAVE_X11_SHARED AND XSS_LIB)
   460           set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XSS "\"${XSS_LIB}\"")
   461         else(HAVE_X11_SHARED AND XSS_LIB)
   462           list(APPEND EXTRA_LIBS ${XSS_LIB})
   463         endif(HAVE_X11_SHARED AND XSS_LIB)
   464         set(SDL_VIDEO_DRIVER_X11_XSCRNSAVER 1)
   465         set(HAVE_VIDEO_X11_XSCRNSAVER TRUE)
   466       endif(VIDEO_X11_XSCRNSAVER AND HAVE_XSS_H)
   467 
   468       if(VIDEO_X11_XSHAPE AND HAVE_XSHAPE_H)
   469         set(SDL_VIDEO_DRIVER_X11_XSHAPE 1)
   470         set(HAVE_VIDEO_X11_XSHAPE TRUE)
   471       endif(VIDEO_X11_XSHAPE AND HAVE_XSHAPE_H)
   472 
   473       if(VIDEO_X11_XVM AND HAVE_XF86VM_H)
   474         if(HAVE_X11_SHARED AND XF86VMODE_LIB)
   475           set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XVIDMODE "\"${XF86VMODE_LIB}\"")
   476         else(HAVE_X11_SHARED AND XF86VMODE_LIB)
   477           list(APPEND EXTRA_LIBS ${XF86VMODE_LIB})
   478         endif(HAVE_X11_SHARED AND XF86VMODE_LIB)
   479         set(SDL_VIDEO_DRIVER_X11_XVIDMODE 1)
   480         set(HAVE_VIDEO_X11_XVM TRUE)
   481       endif(VIDEO_X11_XVM AND HAVE_XF86VM_H)
   482 
   483       set(CMAKE_REQUIRED_LIBRARIES)
   484     endif(X11_LIB)
   485   endif(VIDEO_X11)
   486 endmacro(CheckX11)
   487 
   488 # Requires:
   489 # - n/a
   490 #
   491 macro(CheckCOCOA)
   492   if(VIDEO_COCOA)
   493     check_objc_source_compiles("
   494         #import <Cocoa/Cocoa.h>
   495         int main (int argc, char** argv) {}" HAVE_VIDEO_COCOA)
   496     if(HAVE_VIDEO_COCOA)
   497       file(GLOB COCOA_SOURCES ${SDL2_SOURCE_DIR}/src/video/cocoa/*.m)
   498       set_source_files_properties(${COCOA_SOURCES} PROPERTIES LANGUAGE C)
   499       set(SOURCE_FILES ${SOURCE_FILES} ${COCOA_SOURCES})
   500       set(SDL_VIDEO_DRIVER_COCOA 1)
   501       set(HAVE_SDL_VIDEO TRUE)
   502     endif(HAVE_VIDEO_COCOA)
   503   endif(VIDEO_COCOA)
   504 endmacro(CheckCOCOA)
   505 
   506 # Requires:
   507 # - PkgCheckModules
   508 # Optional:
   509 # - DIRECTFB_SHARED opt
   510 # - HAVE_DLOPEN opt
   511 macro(CheckDirectFB)
   512   if(VIDEO_DIRECTFB)
   513     pkg_check_modules(PKG_DIRECTFB directfb>=1.0.0)
   514     if(PKG_DIRECTFB_FOUND)
   515       set(HAVE_VIDEO_DIRECTFB TRUE)
   516       file(GLOB DIRECTFB_SOURCES ${SDL2_SOURCE_DIR}/src/video/directfb/*.c)
   517       set(SOURCE_FILES ${SOURCE_FILES} ${DIRECTFB_SOURCES})
   518       set(SDL_VIDEO_DRIVER_DIRECTFB 1)
   519       set(SDL_VIDEO_RENDER_DIRECTFB 1)
   520       list(APPEND EXTRA_CFLAGS ${PKG_DIRECTFB_CFLAGS})
   521       if(DIRECTFB_SHARED)
   522         if(NOT HAVE_DLOPEN)
   523           message_warn("You must have SDL_LoadObject() support for dynamic DirectFB loading")
   524         else()
   525           find_library(D_DIRECTFB_LIB directfb)
   526           get_filename_component(F_DIRECTFB_LIB ${D_DIRECTFB_LIB} NAME)
   527           set(SDL_VIDEO_DRIVER_DIRECTFB_DYNAMIC "\"${F_DIRECTFB_LIB}\"")
   528           set(HAVE_DIRECTFB_SHARED TRUE)
   529         endif(NOT HAVE_DLOPEN)
   530       else(DIRECTFB_SHARED)
   531         list(APPEND EXTRA_LDFLAGS ${PKG_DIRECTFB_LDFLAGS})
   532       endif(DIRECTFB_SHARED)
   533       set(HAVE_SDL_VIDEO TRUE)
   534     endif(PKG_DIRECTFB_FOUND)
   535   endif(VIDEO_DIRECTFB)
   536 endmacro(CheckDirectFB)
   537 
   538 # Requires:
   539 # - nada
   540 macro(CheckOpenGLX11)
   541   if(VIDEO_OPENGL)
   542     check_c_source_compiles("
   543         #include <GL/gl.h>
   544         #include <GL/glx.h>
   545         int main(int argc, char** argv) {}" HAVE_VIDEO_OPENGL)
   546 
   547     if(HAVE_VIDEO_OPENGL)
   548       set(HAVE_VIDEO_OPENGL TRUE)
   549       set(SDL_VIDEO_OPENGL 1)
   550       set(SDL_VIDEO_OPENGL_GLX 1)
   551       set(SDL_VIDEO_RENDER_OGL 1)
   552       list(APPEND EXTRA_LIBS GL)
   553     endif(HAVE_VIDEO_OPENGL)
   554   endif(VIDEO_OPENGL)
   555 endmacro(CheckOpenGLX11)
   556 
   557 # Requires:
   558 # - nada
   559 macro(CheckOpenGLESX11)
   560   if(VIDEO_OPENGLES)
   561     check_c_source_compiles("
   562         #include <EGL/egl.h>
   563         int main (int argc, char** argv) {}" HAVE_VIDEO_OPENGL_EGL)
   564     if(HAVE_VIDEO_OPENGL_EGL)
   565         set(SDL_VIDEO_OPENGL_EGL 1)
   566     endif(HAVE_VIDEO_OPENGL_EGL) 
   567     check_c_source_compiles("
   568       #include <GLES/gl.h>
   569       #include <GLES/glext.h>
   570       int main (int argc, char** argv) {}" HAVE_VIDEO_OPENGLES_V1)
   571     if(HAVE_VIDEO_OPENGLES_V1)
   572         set(HAVE_VIDEO_OPENGLES TRUE)
   573         set(SDL_VIDEO_OPENGL_ES 1)
   574         set(SDL_VIDEO_RENDER_OGL_ES 1)
   575     endif(HAVE_VIDEO_OPENGLES_V1)
   576     check_c_source_compiles("
   577       #include <GLES2/gl2.h>
   578       #include <GLES2/gl2ext.h>
   579       int main (int argc, char** argv) {}" HAVE_VIDEO_OPENGLES_V2)
   580     if(HAVE_VIDEO_OPENGLES_V2)
   581         set(HAVE_VIDEO_OPENGLES TRUE)
   582         set(SDL_VIDEO_OPENGL_ES2 1)
   583         set(SDL_VIDEO_RENDER_OGL_ES2 1)
   584     endif(HAVE_VIDEO_OPENGLES_V2)
   585 
   586   endif(VIDEO_OPENGLES)
   587 endmacro(CheckOpenGLESX11)
   588 
   589 # Rquires:
   590 # - nada
   591 # Optional:
   592 # - THREADS opt
   593 # Sets:
   594 # PTHREAD_CFLAGS
   595 # PTHREAD_LIBS
   596 macro(CheckPTHREAD)
   597   if(PTHREADS)
   598     if(LINUX)
   599       set(PTHREAD_CFLAGS "-D_REENTRANT")
   600       set(PTHREAD_LDFLAGS "-pthread")
   601     elseif(BSDI)
   602       set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
   603       set(PTHREAD_LDFLAGS "")
   604     elseif(DARWIN)
   605       set(PTHREAD_CFLAGS "-D_THREAD_SAFE")
   606       # causes Carbon.p complaints?
   607       # set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
   608       set(PTHREAD_LDFLAGS "")
   609     elseif(FREEBSD)
   610       set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
   611       set(PTHREAD_LDFLAGS "-pthread")
   612     elseif(NETBSD)
   613       set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
   614       set(PTHREAD_LDFLAGS "-lpthread")
   615     elseif(OPENBSD)
   616       set(PTHREAD_CFLAGS "-D_REENTRANT")
   617       set(PTHREAD_LDFLAGS "-pthread")
   618     elseif(SOLARIS)
   619       set(PTHREAD_CFLAGS "-D_REENTRANT")
   620       set(PTHREAD_LDFLAGS "-pthread -lposix4")
   621     elseif(SYSV5)
   622       set(PTHREAD_CFLAGS "-D_REENTRANT -Kthread")
   623       set(PTHREAD_LDFLAGS "")
   624     elseif(AIX)
   625       set(PTHREAD_CFLAGS "-D_REENTRANT -mthreads")
   626       set(PTHREAD_LDFLAGS "-pthread")
   627     elseif(HPUX)
   628       set(PTHREAD_CFLAGS "-D_REENTRANT")
   629       set(PTHREAD_LDFLAGS "-L/usr/lib -pthread")
   630     elseif(HAIKU)
   631       set(PTHREAD_CFLAGS "-D_REENTRANT")
   632       set(PTHREAD_LDFLAGS "")
   633     else()
   634       set(PTHREAD_CFLAGS "-D_REENTRANT")
   635       set(PTHREAD_LDFLAGS "-lpthread")
   636     endif(LINUX)
   637 
   638     # Run some tests
   639     set(CMAKE_REQUIRED_FLAGS "${PTHREAD_CFLAGS} ${PTHREAD_LDFLAGS}")
   640     check_c_source_runs("
   641         #include <pthread.h>
   642         int main(int argc, char** argv) {
   643           pthread_attr_t type;
   644           pthread_attr_init(&type);
   645           return 0;
   646         }" HAVE_PTHREADS)
   647     if(HAVE_PTHREADS)
   648       set(SDL_THREAD_PTHREAD 1)
   649       list(APPEND EXTRA_CFLAGS ${PTHREAD_CFLAGS})
   650       list(APPEND EXTRA_LDFLAGS ${PTHREAD_LDFLAGS})
   651       set(SDL_CFLAGS "${SDL_CFLAGS} ${PTHREAD_CFLAGS}")
   652       list(APPEND SDL_LIBS ${PTHREAD_LDFLAGS})
   653 
   654       check_c_source_compiles("
   655         #include <pthread.h>
   656         int main(int argc, char **argv) {
   657           pthread_mutexattr_t attr;
   658           pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
   659           return 0;
   660         }" HAVE_RECURSIVE_MUTEXES)
   661       if(HAVE_RECURSIVE_MUTEXES)
   662         set(SDL_THREAD_PTHREAD_RECURSIVE_MUTEX 1)
   663       else(HAVE_RECURSIVE_MUTEXES)
   664         check_c_source_compiles("
   665             #include <pthread.h>
   666             int main(int argc, char **argv) {
   667               pthread_mutexattr_t attr;
   668               pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
   669               return 0;
   670             }" HAVE_RECURSIVE_MUTEXES_NP)
   671         if(HAVE_RECURSIVE_MUTEXES_NP)
   672           set(SDL_THREAD_PTHREAD_RECURSIVE_MUTEX_NP 1)
   673         endif(HAVE_RECURSIVE_MUTEXES_NP)
   674       endif(HAVE_RECURSIVE_MUTEXES)
   675 
   676       if(PTHREADS_SEM)
   677         check_c_source_compiles("#include <pthread.h>
   678                                  #include <semaphore.h>
   679                                  int main(int argc, char **argv) { return 0; }" HAVE_PTHREADS_SEM)
   680         if(HAVE_PTHREADS_SEM)
   681           check_c_source_compiles("
   682               #include <pthread.h>
   683               #include <semaphore.h>
   684               int main(int argc, char **argv) {
   685                   sem_timedwait(NULL, NULL);
   686                   return 0;
   687               }" HAVE_SEM_TIMEDWAIT)
   688         endif(HAVE_PTHREADS_SEM)
   689       endif(PTHREADS_SEM)
   690 
   691       check_c_source_compiles("
   692           #include <pthread.h>
   693           int main(int argc, char** argv) {
   694               pthread_spin_trylock(NULL);
   695               return 0;
   696           }" HAVE_PTHREAD_SPINLOCK)
   697 
   698       check_c_source_compiles("
   699           #include <pthread.h>
   700           #include <pthread_np.h>
   701           int main(int argc, char** argv) { return 0; }" HAVE_PTHREAD_NP_H)
   702       check_function_exists(pthread_setname_np HAVE_PTHREAD_setNAME_NP)
   703       check_function_exists(pthread_set_name_np HAVE_PTHREAD_set_NAME_NP)
   704       set(CMAKE_REQUIRED_FLAGS)
   705 
   706       set(SOURCE_FILES ${SOURCE_FILES}
   707           ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_systhread.c
   708           ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_sysmutex.c   # Can be faked, if necessary
   709           ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_syscond.c    # Can be faked, if necessary
   710           ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_systls.c
   711           )
   712       if(HAVE_PTHREADS_SEM)
   713         set(SOURCE_FILES ${SOURCE_FILES}
   714             ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_syssem.c)
   715       else(HAVE_PTHREADS_SEM)
   716         set(SOURCE_FILES ${SOURCE_FILES}
   717             ${SDL2_SOURCE_DIR}/src/thread/generic/SDL_syssem.c)
   718       endif(HAVE_PTHREADS_SEM)
   719       set(HAVE_SDL_THREADS TRUE)
   720     endif(HAVE_PTHREADS)
   721   endif(PTHREADS)
   722 endmacro(CheckPTHREAD)
   723 
   724 # Requires
   725 # - nada
   726 # Optional:
   727 # Sets:
   728 # USB_LIBS
   729 # USB_CFLAGS
   730 macro(CheckUSBHID)
   731   check_library_exists(usbhid hid_init "" LIBUSBHID)
   732   if(LIBUSBHID)
   733     check_include_file(usbhid.h HAVE_USBHID_H)
   734     if(HAVE_USBHID_H)
   735       set(USB_CFLAGS "-DHAVE_USBHID_H")
   736     endif(HAVE_USBHID_H)
   737 
   738     check_include_file(libusbhid.h HAVE_LIBUSBHID_H)
   739     if(HAVE_LIBUSBHID_H)
   740       set(USB_CFLAGS "${USB_CFLAGS} -DHAVE_LIBUSBHID_H")
   741     endif(HAVE_LIBUSBHID_H)
   742     set(USB_LIBS ${USB_LIBS} usbhid)
   743   else(LIBUSBHID)
   744     check_include_file(usb.h HAVE_USB_H)
   745     if(HAVE_USB_H)
   746       set(USB_CFLAGS "-DHAVE_USB_H")
   747     endif(HAVE_USB_H)
   748     check_include_file(libusb.h HAVE_LIBUSB_H)
   749     if(HAVE_LIBUSB_H)
   750       set(USB_CFLAGS "${USB_CFLAGS} -DHAVE_LIBUSB_H")
   751     endif(HAVE_LIBUSB_H)
   752     check_library_exists(usb hid_init "" LIBUSB)
   753     if(LIBUSB)
   754       set(USB_LIBS ${USB_LIBS} usb)
   755     endif(LIBUSB)
   756   endif(LIBUSBHID)
   757 
   758   set(CMAKE_REQUIRED_FLAGS "${USB_CFLAGS}")
   759   set(CMAKE_REQUIRED_LIBRARIES "${USB_LIBS}")
   760   check_c_source_compiles("
   761        #include <sys/types.h>
   762         #if defined(HAVE_USB_H)
   763         #include <usb.h>
   764         #endif
   765         #ifdef __DragonFly__
   766         # include <bus/usb/usb.h>
   767         # include <bus/usb/usbhid.h>
   768         #else
   769         # include <dev/usb/usb.h>
   770         # include <dev/usb/usbhid.h>
   771         #endif
   772         #if defined(HAVE_USBHID_H)
   773         #include <usbhid.h>
   774         #elif defined(HAVE_LIBUSB_H)
   775         #include <libusb.h>
   776         #elif defined(HAVE_LIBUSBHID_H)
   777         #include <libusbhid.h>
   778         #endif
   779         int main(int argc, char **argv) {
   780           struct report_desc *repdesc;
   781           struct usb_ctl_report *repbuf;
   782           hid_kind_t hidkind;
   783           return 0;
   784         }" HAVE_USBHID)
   785   if(HAVE_USBHID)
   786     check_c_source_compiles("
   787           #include <sys/types.h>
   788           #if defined(HAVE_USB_H)
   789           #include <usb.h>
   790           #endif
   791           #ifdef __DragonFly__
   792           # include <bus/usb/usb.h>
   793           # include <bus/usb/usbhid.h>
   794           #else
   795           # include <dev/usb/usb.h>
   796           # include <dev/usb/usbhid.h>
   797           #endif
   798           #if defined(HAVE_USBHID_H)
   799           #include <usbhid.h>
   800           #elif defined(HAVE_LIBUSB_H)
   801           #include <libusb.h>
   802           #elif defined(HAVE_LIBUSBHID_H)
   803           #include <libusbhid.h>
   804           #endif
   805           int main(int argc, char** argv) {
   806             struct usb_ctl_report buf;
   807             if (buf.ucr_data) { }
   808             return 0;
   809           }" HAVE_USBHID_UCR_DATA)
   810     if(HAVE_USBHID_UCR_DATA)
   811       set(USB_CFLAGS "${USB_CFLAGS} -DUSBHID_UCR_DATA")
   812     endif(HAVE_USBHID_UCR_DATA)
   813 
   814     check_c_source_compiles("
   815           #include <sys/types.h>
   816           #if defined(HAVE_USB_H)
   817           #include <usb.h>
   818           #endif
   819           #ifdef __DragonFly__
   820           #include <bus/usb/usb.h>
   821           #include <bus/usb/usbhid.h>
   822           #else
   823           #include <dev/usb/usb.h>
   824           #include <dev/usb/usbhid.h>
   825           #endif
   826           #if defined(HAVE_USBHID_H)
   827           #include <usbhid.h>
   828           #elif defined(HAVE_LIBUSB_H)
   829           #include <libusb.h>
   830           #elif defined(HAVE_LIBUSBHID_H)
   831           #include <libusbhid.h>
   832           #endif
   833           int main(int argc, char **argv) {
   834             report_desc_t d;
   835             hid_start_parse(d, 1, 1);
   836             return 0;
   837           }" HAVE_USBHID_NEW)
   838     if(HAVE_USBHID_NEW)
   839       set(USB_CFLAGS "${USB_CFLAGS} -DUSBHID_NEW")
   840     endif(HAVE_USBHID_NEW)
   841 
   842     check_c_source_compiles("
   843         #include <machine/joystick.h>
   844         int main(int argc, char** argv) {
   845             struct joystick t;
   846             return 0;
   847         }" HAVE_MACHINE_JOYSTICK)
   848     if(HAVE_MACHINE_JOYSTICK)
   849       set(SDL_JOYSTICK_USBHID_MACHINE_JOYSTICK_H 1)
   850     endif(HAVE_MACHINE_JOYSTICK)
   851     set(SDL_JOYSTICK_USBHID 1)
   852     file(GLOB BSD_JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/bsd/*.c)
   853     set(SOURCE_FILES ${SOURCE_FILES} ${BSD_JOYSTICK_SOURCES})
   854     list(APPEND EXTRA_CFLAGS ${USB_CFLAGS})
   855     list(APPEND EXTRA_LIBS ${USB_LIBS})
   856     set(HAVE_SDL_JOYSTICK TRUE)
   857 
   858     set(CMAKE_REQUIRED_LIBRARIES)
   859     set(CMAKE_REQUIRED_FLAGS)
   860   endif(HAVE_USBHID)
   861 endmacro(CheckUSBHID)