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