cscg22-gearboy

CSCG 2022 Challenge 'Gearboy'
git clone https://git.sinitax.com/sinitax/cscg22-gearboy
Log | Files | Refs | sfeed.txt

sdlchecks.cmake (33572B)


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