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