cmake/sdlchecks.cmake
author Sam Lantinga <slouken@libsdl.org>
Fri, 28 Nov 2014 04:51:33 -0800
changeset 9246 a761913e5e91
parent 9170 872d1b4b34a1
child 9277 f0bd40782fc7
permissions -rw-r--r--
Fixed bug 2786 - "UCS-2-INTERNAL" iconv encoding is not supported everywhere, use UTF-16LE instead

Jonas Kulla

src/main/windows/SDL_windows_main.c:137:
cmdline = SDL_iconv_string("UTF-8", "UCS-2-INTERNAL", (char *)(text), (SDL_wcslen(text)+1)*sizeof(WCHAR));

I'm trying to compile an SDL2 application for windows using the mingw-w64 32bit toolchain provided by my distro (Fedora 19). However, even the simplest test program that does nothing at all fails to startup with a "Fatal error - out of memory" message because the mingw iconv library provided by my distro does not support the "UCS-2-INTERNAL" encoding and the conversion returns null.

From my little bit of research, it turns out that even though this encoding is supported by the external GNU libiconv library, some glibc versions (?) don't support it with their internal iconv routines, and will instead provide the native endian encoding when "UCS-2" is specified.

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