cmake/sdlchecks.cmake
author Sam Lantinga
Tue, 10 Jan 2017 08:54:33 -0800
changeset 10806 36f40b8cc979
parent 10777 2883d23b5a28
child 11081 eea7f98a37e4
permissions -rw-r--r--
Fixed bugs 2570, 3145, improved OpenGL ES context support on Windows and X11

Mark Callow

The attached patch does the following for the X11 and Windows platforms, the only ones where SDL attempts to use context_create_es_profile:

- Adds SDL_HINT_OPENGL_ES_DRIVER by which the application can
say to use the OpenGL ES driver & EGL rather than the Open GL
driver. (For bug #2570)
- Adds code to {WIN,X11}_GL_InitExtensions to determine the maximum
OpenGL ES version supported by the OpenGL driver (for bug #3145)
- Modifies the test that determines whether to use the OpenGL
driver or the real OpenGL ES driver to take into account the
hint, the requested and supported ES version and whether ES 1.X
is being requested. (For bug #2570 & bug #3145)
- Enables the testgles2 test for __WINDOWS__ and __LINUX__ and adds
the test to the VisualC projects.

With the fix in place I have run testdraw2, testgl and testgles2 without any issues and have run my own apps that use OpenGL, OpenGL ES 3 and OpenGL ES 1.1.
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()
icculus@9277
    42
      endif()
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()
icculus@9277
    66
endmacro()
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)
icculus@9277
    81
    endif()
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)
icculus@9277
    88
      endif()
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)
icculus@9277
    93
      endif()
gabomdq@6674
    94
      set(HAVE_SDL_AUDIO TRUE)
icculus@9277
    95
    endif()
icculus@9277
    96
  endif()
icculus@9277
    97
endmacro()
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)
slouken@10490
   108
      CHECK_LIBRARY_EXISTS(asound snd_pcm_recover "" HAVE_LIBASOUND)
slouken@10490
   109
    endif()
slouken@10490
   110
    if(HAVE_LIBASOUND)
gabomdq@6674
   111
      set(HAVE_ALSA TRUE)
gabomdq@6674
   112
      file(GLOB ALSA_SOURCES ${SDL2_SOURCE_DIR}/src/audio/alsa/*.c)
gabomdq@6674
   113
      set(SOURCE_FILES ${SOURCE_FILES} ${ALSA_SOURCES})
gabomdq@6674
   114
      set(SDL_AUDIO_DRIVER_ALSA 1)
gabomdq@6674
   115
      if(ALSA_SHARED)
gabomdq@6674
   116
        if(NOT HAVE_DLOPEN)
gabomdq@6674
   117
          message_warn("You must have SDL_LoadObject() support for dynamic ALSA loading")
gabomdq@6674
   118
        else()
icculus@8017
   119
          FindLibraryAndSONAME("asound")
icculus@8017
   120
          set(SDL_AUDIO_DRIVER_ALSA_DYNAMIC "\"${ASOUND_LIB_SONAME}\"")
gabomdq@6674
   121
          set(HAVE_ALSA_SHARED TRUE)
icculus@9277
   122
        endif()
icculus@9277
   123
      else()
gabomdq@6674
   124
        list(APPEND EXTRA_LIBS asound)
icculus@9277
   125
      endif()
gabomdq@6674
   126
      set(HAVE_SDL_AUDIO TRUE)
icculus@9277
   127
    endif()
icculus@9277
   128
  endif()
icculus@9277
   129
endmacro()
gabomdq@6674
   130
gabomdq@6674
   131
# Requires:
gabomdq@6674
   132
# - PkgCheckModules
gabomdq@6674
   133
# Optional:
gabomdq@6674
   134
# - PULSEAUDIO_SHARED opt
gabomdq@6674
   135
# - HAVE_DLOPEN opt
gabomdq@6674
   136
macro(CheckPulseAudio)
gabomdq@6674
   137
  if(PULSEAUDIO)
gabomdq@6674
   138
    pkg_check_modules(PKG_PULSEAUDIO libpulse-simple)
gabomdq@6674
   139
    if(PKG_PULSEAUDIO_FOUND)
gabomdq@6674
   140
      set(HAVE_PULSEAUDIO TRUE)
gabomdq@6674
   141
      file(GLOB PULSEAUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/pulseaudio/*.c)
gabomdq@6674
   142
      set(SOURCE_FILES ${SOURCE_FILES} ${PULSEAUDIO_SOURCES})
gabomdq@6674
   143
      set(SDL_AUDIO_DRIVER_PULSEAUDIO 1)
gabomdq@6674
   144
      list(APPEND EXTRA_CFLAGS ${PKG_PULSEAUDIO_CFLAGS})
gabomdq@6674
   145
      if(PULSEAUDIO_SHARED)
gabomdq@6674
   146
        if(NOT HAVE_DLOPEN)
gabomdq@6674
   147
          message_warn("You must have SDL_LoadObject() support for dynamic PulseAudio loading")
gabomdq@6674
   148
        else()
icculus@8017
   149
          FindLibraryAndSONAME("pulse-simple")
icculus@8017
   150
          set(SDL_AUDIO_DRIVER_PULSEAUDIO_DYNAMIC "\"${PULSE_SIMPLE_LIB_SONAME}\"")
gabomdq@6674
   151
          set(HAVE_PULSEAUDIO_SHARED TRUE)
icculus@9277
   152
        endif()
icculus@9277
   153
      else()
gabomdq@6674
   154
        list(APPEND EXTRA_LDFLAGS ${PKG_PULSEAUDIO_LDFLAGS})
icculus@9277
   155
      endif()
gabomdq@6674
   156
      set(HAVE_SDL_AUDIO TRUE)
icculus@9277
   157
    endif()
icculus@9277
   158
  endif()
icculus@9277
   159
endmacro()
gabomdq@6674
   160
gabomdq@6674
   161
# Requires:
gabomdq@6674
   162
# - PkgCheckModules
gabomdq@6674
   163
# Optional:
gabomdq@6674
   164
# - ESD_SHARED opt
gabomdq@6674
   165
# - HAVE_DLOPEN opt
gabomdq@6674
   166
macro(CheckESD)
gabomdq@6674
   167
  if(ESD)
gabomdq@6674
   168
    pkg_check_modules(PKG_ESD esound)
gabomdq@6674
   169
    if(PKG_ESD_FOUND)
gabomdq@6674
   170
      set(HAVE_ESD TRUE)
gabomdq@6674
   171
      file(GLOB ESD_SOURCES ${SDL2_SOURCE_DIR}/src/audio/esd/*.c)
gabomdq@6674
   172
      set(SOURCE_FILES ${SOURCE_FILES} ${ESD_SOURCES})
gabomdq@6674
   173
      set(SDL_AUDIO_DRIVER_ESD 1)
gabomdq@6674
   174
      list(APPEND EXTRA_CFLAGS ${PKG_ESD_CFLAGS})
gabomdq@6674
   175
      if(ESD_SHARED)
gabomdq@6674
   176
        if(NOT HAVE_DLOPEN)
gabomdq@6674
   177
          message_warn("You must have SDL_LoadObject() support for dynamic ESD loading")
gabomdq@6674
   178
        else()
icculus@8017
   179
          FindLibraryAndSONAME(esd)
icculus@8017
   180
          set(SDL_AUDIO_DRIVER_ESD_DYNAMIC "\"${ESD_LIB_SONAME}\"")
gabomdq@6674
   181
          set(HAVE_ESD_SHARED TRUE)
icculus@9277
   182
        endif()
icculus@9277
   183
      else()
gabomdq@6674
   184
        list(APPEND EXTRA_LDFLAGS ${PKG_ESD_LDFLAGS})
icculus@9277
   185
      endif()
gabomdq@6674
   186
      set(HAVE_SDL_AUDIO TRUE)
icculus@9277
   187
    endif()
icculus@9277
   188
  endif()
icculus@9277
   189
endmacro()
gabomdq@6674
   190
gabomdq@6674
   191
# Requires:
gabomdq@6674
   192
# - n/a
gabomdq@6674
   193
# Optional:
gabomdq@6674
   194
# - ARTS_SHARED opt
gabomdq@6674
   195
# - HAVE_DLOPEN opt
gabomdq@6674
   196
macro(CheckARTS)
gabomdq@6674
   197
  if(ARTS)
gabomdq@6674
   198
    find_program(ARTS_CONFIG arts-config)
gabomdq@6674
   199
    if(ARTS_CONFIG)
gabomdq@6674
   200
      execute_process(CMD_ARTSCFLAGS ${ARTS_CONFIG} --cflags
gabomdq@6674
   201
        OUTPUT_VARIABLE ARTS_CFLAGS OUTPUT_STRIP_TRAILING_WHITESPACE)
gabomdq@6674
   202
      list(APPEND EXTRA_CFLAGS ${ARTS_CFLAGS})
gabomdq@6674
   203
      execute_process(CMD_ARTSLIBS ${ARTS_CONFIG} --libs
gabomdq@6674
   204
        OUTPUT_VARIABLE ARTS_LIBS OUTPUT_STRIP_TRAILING_WHITESPACE)
gabomdq@6674
   205
      file(GLOB ARTS_SOURCES ${SDL2_SOURCE_DIR}/src/audio/arts/*.c)
gabomdq@6674
   206
      set(SOURCE_FILES ${SOURCE_FILES} ${ARTS_SOURCES})
gabomdq@6674
   207
      set(SDL_AUDIO_DRIVER_ARTS 1)
gabomdq@6674
   208
      set(HAVE_ARTS TRUE)
gabomdq@6674
   209
      if(ARTS_SHARED)
gabomdq@6674
   210
        if(NOT HAVE_DLOPEN)
gabomdq@6674
   211
          message_warn("You must have SDL_LoadObject() support for dynamic ARTS loading")
gabomdq@6674
   212
        else()
gabomdq@6674
   213
          # TODO
icculus@8017
   214
          FindLibraryAndSONAME(artsc)
icculus@8017
   215
          set(SDL_AUDIO_DRIVER_ARTS_DYNAMIC "\"${ARTSC_LIB_SONAME}\"")
gabomdq@6674
   216
          set(HAVE_ARTS_SHARED TRUE)
icculus@9277
   217
        endif()
icculus@9277
   218
      else()
gabomdq@6674
   219
        list(APPEND EXTRA_LDFLAGS ${ARTS_LIBS})
icculus@9277
   220
      endif()
gabomdq@6674
   221
      set(HAVE_SDL_AUDIO TRUE)
icculus@9277
   222
    endif()
icculus@9277
   223
  endif()
icculus@9277
   224
endmacro()
gabomdq@6674
   225
gabomdq@6674
   226
# Requires:
gabomdq@6674
   227
# - n/a
gabomdq@6674
   228
# Optional:
gabomdq@6674
   229
# - NAS_SHARED opt
gabomdq@6674
   230
# - HAVE_DLOPEN opt
gabomdq@6674
   231
macro(CheckNAS)
gabomdq@6674
   232
  if(NAS)
gabomdq@6674
   233
    # TODO: set include paths properly, so the NAS headers are found
gabomdq@6674
   234
    check_include_file(audio/audiolib.h HAVE_NAS_H)
gabomdq@6674
   235
    find_library(D_NAS_LIB audio)
gabomdq@6674
   236
    if(HAVE_NAS_H AND D_NAS_LIB)
gabomdq@6674
   237
      set(HAVE_NAS TRUE)
gabomdq@6674
   238
      file(GLOB NAS_SOURCES ${SDL2_SOURCE_DIR}/src/audio/nas/*.c)
gabomdq@6674
   239
      set(SOURCE_FILES ${SOURCE_FILES} ${NAS_SOURCES})
gabomdq@6674
   240
      set(SDL_AUDIO_DRIVER_NAS 1)
gabomdq@6674
   241
      if(NAS_SHARED)
gabomdq@6674
   242
        if(NOT HAVE_DLOPEN)
gabomdq@6674
   243
          message_warn("You must have SDL_LoadObject() support for dynamic NAS loading")
gabomdq@6674
   244
        else()
icculus@8017
   245
          FindLibraryAndSONAME("audio")
icculus@8017
   246
          set(SDL_AUDIO_DRIVER_NAS_DYNAMIC "\"${AUDIO_LIB_SONAME}\"")
gabomdq@6674
   247
          set(HAVE_NAS_SHARED TRUE)
icculus@9277
   248
        endif()
icculus@9277
   249
      else()
gabomdq@6674
   250
        list(APPEND EXTRA_LIBS ${D_NAS_LIB})
icculus@9277
   251
      endif()
gabomdq@6674
   252
      set(HAVE_SDL_AUDIO TRUE)
icculus@9277
   253
    endif()
icculus@9277
   254
  endif()
icculus@9277
   255
endmacro()
gabomdq@6674
   256
gabomdq@6674
   257
# Requires:
icculus@7367
   258
# - n/a
icculus@7367
   259
# Optional:
icculus@7367
   260
# - SNDIO_SHARED opt
icculus@7367
   261
# - HAVE_DLOPEN opt
icculus@7367
   262
macro(CheckSNDIO)
icculus@7367
   263
  if(SNDIO)
icculus@7367
   264
    # TODO: set include paths properly, so the sndio headers are found
icculus@7367
   265
    check_include_file(sndio.h HAVE_SNDIO_H)
icculus@8017
   266
    find_library(D_SNDIO_LIB sndio)
icculus@7367
   267
    if(HAVE_SNDIO_H AND D_SNDIO_LIB)
icculus@7367
   268
      set(HAVE_SNDIO TRUE)
icculus@7367
   269
      file(GLOB SNDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/sndio/*.c)
icculus@7367
   270
      set(SOURCE_FILES ${SOURCE_FILES} ${SNDIO_SOURCES})
icculus@7367
   271
      set(SDL_AUDIO_DRIVER_SNDIO 1)
icculus@7367
   272
      if(SNDIO_SHARED)
icculus@7367
   273
        if(NOT HAVE_DLOPEN)
icculus@7367
   274
          message_warn("You must have SDL_LoadObject() support for dynamic sndio loading")
icculus@7367
   275
        else()
icculus@8017
   276
          FindLibraryAndSONAME("sndio")
icculus@8017
   277
          set(SDL_AUDIO_DRIVER_SNDIO_DYNAMIC "\"${SNDIO_LIB_SONAME}\"")
icculus@7367
   278
          set(HAVE_SNDIO_SHARED TRUE)
icculus@9277
   279
        endif()
icculus@9277
   280
      else()
icculus@7367
   281
        list(APPEND EXTRA_LIBS ${D_SNDIO_LIB})
icculus@9277
   282
      endif()
icculus@7367
   283
      set(HAVE_SDL_AUDIO TRUE)
icculus@9277
   284
    endif()
icculus@9277
   285
  endif()
icculus@9277
   286
endmacro()
icculus@7367
   287
icculus@7367
   288
# Requires:
gabomdq@6674
   289
# - PkgCheckModules
gabomdq@6674
   290
# Optional:
gabomdq@6674
   291
# - FUSIONSOUND_SHARED opt
gabomdq@6674
   292
# - HAVE_DLOPEN opt
gabomdq@6674
   293
macro(CheckFusionSound)
gabomdq@6674
   294
  if(FUSIONSOUND)
gabomdq@6674
   295
    pkg_check_modules(PKG_FUSIONSOUND fusionsound>=1.0.0)
gabomdq@6674
   296
    if(PKG_FUSIONSOUND_FOUND)
gabomdq@6674
   297
      set(HAVE_FUSIONSOUND TRUE)
gabomdq@6674
   298
      file(GLOB FUSIONSOUND_SOURCES ${SDL2_SOURCE_DIR}/src/audio/fusionsound/*.c)
gabomdq@6674
   299
      set(SOURCE_FILES ${SOURCE_FILES} ${FUSIONSOUND_SOURCES})
gabomdq@6674
   300
      set(SDL_AUDIO_DRIVER_FUSIONSOUND 1)
gabomdq@6674
   301
      list(APPEND EXTRA_CFLAGS ${PKG_FUSIONSOUND_CFLAGS})
gabomdq@6674
   302
      if(FUSIONSOUND_SHARED)
gabomdq@6674
   303
        if(NOT HAVE_DLOPEN)
gabomdq@6674
   304
          message_warn("You must have SDL_LoadObject() support for dynamic FusionSound loading")
gabomdq@6674
   305
        else()
icculus@8017
   306
          FindLibraryAndSONAME("fusionsound")
icculus@8017
   307
          set(SDL_AUDIO_DRIVER_FUSIONSOUND_DYNAMIC "\"${FUSIONSOUND_LIB_SONAME}\"")
gabomdq@6674
   308
          set(HAVE_FUSIONSOUND_SHARED TRUE)
icculus@9277
   309
        endif()
icculus@9277
   310
      else()
gabomdq@6674
   311
        list(APPEND EXTRA_LDFLAGS ${PKG_FUSIONSOUND_LDFLAGS})
icculus@9277
   312
      endif()
gabomdq@6674
   313
      set(HAVE_SDL_AUDIO TRUE)
icculus@9277
   314
    endif()
icculus@9277
   315
  endif()
icculus@9277
   316
endmacro()
gabomdq@6674
   317
gabomdq@6674
   318
# Requires:
slouken@10777
   319
# - LIBSAMPLERATE
slouken@10777
   320
# Optional:
slouken@10777
   321
# - LIBSAMPLERATE_SHARED opt
slouken@10777
   322
# - HAVE_DLOPEN opt
slouken@10777
   323
macro(CheckLibSampleRate)
slouken@10777
   324
  if(LIBSAMPLERATE)
slouken@10777
   325
    check_include_file(samplerate.h HAVE_LIBSAMPLERATE_H)
slouken@10777
   326
    if(HAVE_LIBSAMPLERATE_H)
slouken@10777
   327
      if(LIBSAMPLERATE_SHARED)
slouken@10777
   328
        if(NOT HAVE_DLOPEN)
slouken@10777
   329
          message_warn("You must have SDL_LoadObject() support for dynamic libsamplerate loading")
slouken@10777
   330
        else()
slouken@10777
   331
          FindLibraryAndSONAME("samplerate")
slouken@10777
   332
          set(SDL_LIBSAMPLERATE_DYNAMIC "\"${SAMPLERATE_LIB_SONAME}\"")
slouken@10777
   333
        endif()
slouken@10777
   334
      else()
slouken@10777
   335
        list(APPEND EXTRA_LDFLAGS -lsamplerate)
slouken@10777
   336
      endif()
slouken@10777
   337
    endif()
slouken@10777
   338
  endif()
slouken@10777
   339
endmacro()
slouken@10777
   340
slouken@10777
   341
# Requires:
gabomdq@6674
   342
# - n/a
gabomdq@6674
   343
# Optional:
gabomdq@6674
   344
# - X11_SHARED opt
gabomdq@6674
   345
# - HAVE_DLOPEN opt
gabomdq@6674
   346
macro(CheckX11)
gabomdq@6674
   347
  if(VIDEO_X11)
gabomdq@6674
   348
    foreach(_LIB X11 Xext Xcursor Xinerama Xi Xrandr Xrender Xss Xxf86vm)
icculus@8017
   349
        FindLibraryAndSONAME("${_LIB}")
gabomdq@6674
   350
    endforeach()
gabomdq@6674
   351
slouken@7835
   352
    find_path(X_INCLUDEDIR X11/Xlib.h)
slouken@7835
   353
    if(X_INCLUDEDIR)
slouken@7835
   354
      set(X_CFLAGS "-I${X_INCLUDEDIR}")
slouken@7835
   355
    endif()
slouken@7835
   356
gabomdq@6674
   357
    check_include_file(X11/Xcursor/Xcursor.h HAVE_XCURSOR_H)
gabomdq@6674
   358
    check_include_file(X11/extensions/Xinerama.h HAVE_XINERAMA_H)
gabomdq@6674
   359
    check_include_file(X11/extensions/XInput2.h HAVE_XINPUT_H)
gabomdq@6674
   360
    check_include_file(X11/extensions/Xrandr.h HAVE_XRANDR_H)
gabomdq@6674
   361
    check_include_file(X11/extensions/Xrender.h HAVE_XRENDER_H)
gabomdq@6674
   362
    check_include_file(X11/extensions/scrnsaver.h HAVE_XSS_H)
gabomdq@6674
   363
    check_include_file(X11/extensions/shape.h HAVE_XSHAPE_H)
gabomdq@6674
   364
    check_include_files("X11/Xlib.h;X11/extensions/xf86vmode.h" HAVE_XF86VM_H)
icculus@7438
   365
    check_include_files("X11/Xlib.h;X11/Xproto.h;X11/extensions/Xext.h" HAVE_XEXT_H)
gabomdq@6674
   366
gabomdq@6674
   367
    if(X11_LIB)
icculus@7438
   368
      if(NOT HAVE_XEXT_H)
icculus@7438
   369
        message_error("Missing Xext.h, maybe you need to install the libxext-dev package?")
icculus@7438
   370
      endif()
icculus@7438
   371
gabomdq@6674
   372
      set(HAVE_VIDEO_X11 TRUE)
gabomdq@6674
   373
      set(HAVE_SDL_VIDEO TRUE)
gabomdq@6674
   374
gabomdq@6674
   375
      file(GLOB X11_SOURCES ${SDL2_SOURCE_DIR}/src/video/x11/*.c)
gabomdq@6674
   376
      set(SOURCE_FILES ${SOURCE_FILES} ${X11_SOURCES})
gabomdq@6674
   377
      set(SDL_VIDEO_DRIVER_X11 1)
gabomdq@6674
   378
gabomdq@6674
   379
      if(APPLE)
gabomdq@6674
   380
        set(X11_SHARED OFF)
icculus@9277
   381
      endif()
gabomdq@6674
   382
gabomdq@6674
   383
      check_function_exists("shmat" HAVE_SHMAT)
gabomdq@6674
   384
      if(NOT HAVE_SHMAT)
gabomdq@6674
   385
        check_library_exists(ipc shmat "" HAVE_SHMAT)
gabomdq@6674
   386
        if(HAVE_SHMAT)
gabomdq@6674
   387
          list(APPEND EXTRA_LIBS ipc)
icculus@9277
   388
        endif()
gabomdq@6674
   389
        if(NOT HAVE_SHMAT)
gabomdq@6674
   390
          add_definitions(-DNO_SHARED_MEMORY)
slouken@7835
   391
          set(X_CFLAGS "${X_CFLAGS} -DNO_SHARED_MEMORY")
icculus@9277
   392
        endif()
icculus@9277
   393
      endif()
gabomdq@6674
   394
gabomdq@6674
   395
      if(X11_SHARED)
gabomdq@6674
   396
        if(NOT HAVE_DLOPEN)
gabomdq@6674
   397
          message_warn("You must have SDL_LoadObject() support for dynamic X11 loading")
gabomdq@6674
   398
          set(HAVE_X11_SHARED FALSE)
icculus@9277
   399
        else()
gabomdq@6674
   400
          set(HAVE_X11_SHARED TRUE)
gabomdq@6674
   401
        endif()
gabomdq@6674
   402
        if(HAVE_X11_SHARED)
icculus@8017
   403
          set(SDL_VIDEO_DRIVER_X11_DYNAMIC "\"${X11_LIB_SONAME}\"")
icculus@8017
   404
          set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT "\"${XEXT_LIB_SONAME}\"")
icculus@9277
   405
        else()
gabomdq@6674
   406
          list(APPEND EXTRA_LIBS ${X11_LIB} ${XEXT_LIB})
icculus@9277
   407
        endif()
icculus@9277
   408
      endif()
gabomdq@6674
   409
slouken@7835
   410
      set(SDL_CFLAGS "${SDL_CFLAGS} ${X_CFLAGS}")
slouken@7835
   411
gabomdq@6674
   412
      set(CMAKE_REQUIRED_LIBRARIES ${X11_LIB} ${X11_LIB})
gabomdq@6674
   413
      check_c_source_compiles("
gabomdq@6674
   414
          #include <X11/Xlib.h>
gabomdq@6674
   415
          #include <X11/Xproto.h>
gabomdq@6674
   416
          #include <X11/extensions/Xext.h>
gabomdq@6674
   417
          #include <X11/extensions/extutil.h>
gabomdq@6674
   418
          extern XExtDisplayInfo* XextAddDisplay(XExtensionInfo* a,Display* b,_Xconst char* c,XExtensionHooks* d,int e,XPointer f);
gabomdq@6674
   419
          int main(int argc, char **argv) {}" HAVE_CONST_XEXT_ADDDISPLAY)
gabomdq@6674
   420
      if(HAVE_CONST_XEXT_ADDDISPLAY)
gabomdq@6674
   421
        set(SDL_VIDEO_DRIVER_X11_CONST_PARAM_XEXTADDDISPLAY 1)
icculus@9277
   422
      endif()
gabomdq@6674
   423
gabomdq@6674
   424
      check_c_source_compiles("
gabomdq@6674
   425
          #include <X11/Xlib.h>
gabomdq@6674
   426
          int main(int argc, char **argv) {
gabomdq@6674
   427
            Display *display;
gabomdq@6674
   428
            XEvent event;
gabomdq@6674
   429
            XGenericEventCookie *cookie = &event.xcookie;
gabomdq@6674
   430
            XNextEvent(display, &event);
gabomdq@6674
   431
            XGetEventData(display, cookie);
gabomdq@6674
   432
            XFreeEventData(display, cookie); }" HAVE_XGENERICEVENT)
gabomdq@6674
   433
      if(HAVE_XGENERICEVENT)
gabomdq@6674
   434
        set(SDL_VIDEO_DRIVER_X11_SUPPORTS_GENERIC_EVENTS 1)
icculus@9277
   435
      endif()
gabomdq@6674
   436
gabomdq@6674
   437
      check_function_exists(XkbKeycodeToKeysym SDL_VIDEO_DRIVER_X11_HAS_XKBKEYCODETOKEYSYM)
gabomdq@6674
   438
gabomdq@6674
   439
      if(VIDEO_X11_XCURSOR AND HAVE_XCURSOR_H)
gabomdq@6674
   440
        set(HAVE_VIDEO_X11_XCURSOR TRUE)
gabomdq@6674
   441
        if(HAVE_X11_SHARED AND XCURSOR_LIB)
icculus@8017
   442
          set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XCURSOR "\"${XCURSOR_LIB_SONAME}\"")
icculus@9277
   443
        else()
gabomdq@6674
   444
          list(APPEND EXTRA_LIBS ${XCURSOR_LIB})
icculus@9277
   445
        endif()
gabomdq@6674
   446
        set(SDL_VIDEO_DRIVER_X11_XCURSOR 1)
icculus@9277
   447
      endif()
gabomdq@6674
   448
gabomdq@6674
   449
      if(VIDEO_X11_XINERAMA AND HAVE_XINERAMA_H)
gabomdq@6674
   450
        set(HAVE_VIDEO_X11_XINERAMA TRUE)
gabomdq@6674
   451
        if(HAVE_X11_SHARED AND XINERAMA_LIB)
icculus@8017
   452
          set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XINERAMA "\"${XINERAMA_LIB_SONAME}\"")
icculus@9277
   453
        else()
gabomdq@6674
   454
          list(APPEND EXTRA_LIBS ${XINERAMA_LIB})
icculus@9277
   455
        endif()
gabomdq@6674
   456
        set(SDL_VIDEO_DRIVER_X11_XINERAMA 1)
icculus@9277
   457
      endif()
gabomdq@6674
   458
gabomdq@6674
   459
      if(VIDEO_X11_XINPUT AND HAVE_XINPUT_H)
gabomdq@6674
   460
        set(HAVE_VIDEO_X11_XINPUT TRUE)
gabomdq@6674
   461
        if(HAVE_X11_SHARED AND XI_LIB)
icculus@8017
   462
          set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT2 "\"${XI_LIB_SONAME}\"")
icculus@9277
   463
        else()
gabomdq@6674
   464
          list(APPEND EXTRA_LIBS ${XI_LIB})
icculus@9277
   465
        endif()
gabomdq@6674
   466
        set(SDL_VIDEO_DRIVER_X11_XINPUT2 1)
gabomdq@6674
   467
gabomdq@6674
   468
        # Check for multitouch
gabomdq@6674
   469
        check_c_source_compiles("
gabomdq@6674
   470
            #include <X11/Xlib.h>
gabomdq@6674
   471
            #include <X11/Xproto.h>
gabomdq@6674
   472
            #include <X11/extensions/XInput2.h>
gabomdq@6674
   473
            int event_type = XI_TouchBegin;
gabomdq@6674
   474
            XITouchClassInfo *t;
gabomdq@6674
   475
            Status XIAllowTouchEvents(Display *a,int b,unsigned int c,Window d,int f)
gabomdq@6674
   476
            {
gabomdq@6674
   477
              return (Status)0;
gabomdq@6674
   478
            }
gabomdq@6674
   479
            int main(int argc, char **argv) {}" HAVE_XINPUT2_MULTITOUCH)
gabomdq@6674
   480
        if(HAVE_XINPUT2_MULTITOUCH)
gabomdq@6674
   481
          set(SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH 1)
icculus@9277
   482
        endif()
icculus@9277
   483
      endif()
gabomdq@6674
   484
gabomdq@6674
   485
      if(VIDEO_X11_XRANDR AND HAVE_XRANDR_H)
gabomdq@6674
   486
        if(HAVE_X11_SHARED AND XRANDR_LIB)
icculus@8017
   487
          set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR "\"${XRANDR_LIB_SONAME}\"")
icculus@9277
   488
        else()
gabomdq@6674
   489
          list(APPEND EXTRA_LIBS ${XRANDR_LIB})
icculus@9277
   490
        endif()
gabomdq@6674
   491
        set(SDL_VIDEO_DRIVER_X11_XRANDR 1)
gabomdq@6674
   492
        set(HAVE_VIDEO_X11_XRANDR TRUE)
icculus@9277
   493
      endif()
gabomdq@6674
   494
gabomdq@6674
   495
      if(VIDEO_X11_XSCRNSAVER AND HAVE_XSS_H)
gabomdq@6674
   496
        if(HAVE_X11_SHARED AND XSS_LIB)
icculus@8017
   497
          set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XSS "\"${XSS_LIB_SONAME}\"")
icculus@9277
   498
        else()
gabomdq@6674
   499
          list(APPEND EXTRA_LIBS ${XSS_LIB})
icculus@9277
   500
        endif()
gabomdq@6674
   501
        set(SDL_VIDEO_DRIVER_X11_XSCRNSAVER 1)
gabomdq@6674
   502
        set(HAVE_VIDEO_X11_XSCRNSAVER TRUE)
icculus@9277
   503
      endif()
gabomdq@6674
   504
gabomdq@6674
   505
      if(VIDEO_X11_XSHAPE AND HAVE_XSHAPE_H)
gabomdq@6674
   506
        set(SDL_VIDEO_DRIVER_X11_XSHAPE 1)
gabomdq@6674
   507
        set(HAVE_VIDEO_X11_XSHAPE TRUE)
icculus@9277
   508
      endif()
gabomdq@6674
   509
gabomdq@6674
   510
      if(VIDEO_X11_XVM AND HAVE_XF86VM_H)
icculus@8120
   511
        if(HAVE_X11_SHARED AND XXF86VM_LIB)
icculus@8120
   512
          set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XVIDMODE "\"${XXF86VM_LIB_SONAME}\"")
icculus@9277
   513
        else()
icculus@8120
   514
          list(APPEND EXTRA_LIBS ${XXF86VM_LIB})
icculus@9277
   515
        endif()
gabomdq@6674
   516
        set(SDL_VIDEO_DRIVER_X11_XVIDMODE 1)
gabomdq@6674
   517
        set(HAVE_VIDEO_X11_XVM TRUE)
icculus@9277
   518
      endif()
gabomdq@6674
   519
gabomdq@6674
   520
      set(CMAKE_REQUIRED_LIBRARIES)
icculus@9277
   521
    endif()
icculus@9277
   522
  endif()
icculus@9277
   523
endmacro()
gabomdq@6674
   524
icculus@9409
   525
# Requires:
icculus@9409
   526
# - EGL
icculus@9409
   527
# - PkgCheckModules
icculus@9409
   528
# Optional:
icculus@9409
   529
# - MIR_SHARED opt
icculus@9409
   530
# - HAVE_DLOPEN opt
icculus@8153
   531
macro(CheckMir)
icculus@8153
   532
    if(VIDEO_MIR)
icculus@8153
   533
        find_library(MIR_LIB mirclient mircommon egl)
icculus@8153
   534
        pkg_check_modules(MIR_TOOLKIT mirclient mircommon)
icculus@8153
   535
        pkg_check_modules(EGL egl)
icculus@8153
   536
        pkg_check_modules(XKB xkbcommon)
icculus@8153
   537
icculus@8153
   538
        if (MIR_LIB AND MIR_TOOLKIT_FOUND AND EGL_FOUND AND XKB_FOUND)
icculus@8153
   539
            set(HAVE_VIDEO_MIR TRUE)
icculus@8153
   540
            set(HAVE_SDL_VIDEO TRUE)
icculus@8153
   541
icculus@8153
   542
            file(GLOB MIR_SOURCES ${SDL2_SOURCE_DIR}/src/video/mir/*.c)
icculus@8153
   543
            set(SOURCE_FILES ${SOURCE_FILES} ${MIR_SOURCES})
icculus@8153
   544
            set(SDL_VIDEO_DRIVER_MIR 1)
icculus@8153
   545
icculus@8153
   546
            list(APPEND EXTRA_CFLAGS ${MIR_TOOLKIT_CFLAGS} ${EGL_CLFAGS} ${XKB_CLFLAGS})
icculus@9409
   547
icculus@9409
   548
            if(MIR_SHARED)
icculus@9409
   549
                if(NOT HAVE_DLOPEN)
icculus@9409
   550
                    message_warn("You must have SDL_LoadObject() support for dynamic Mir loading")
icculus@9409
   551
                else()
icculus@9409
   552
                    FindLibraryAndSONAME(mirclient)
icculus@9409
   553
                    FindLibraryAndSONAME(xkbcommon)
icculus@9409
   554
                    set(SDL_VIDEO_DRIVER_MIR_DYNAMIC "\"${MIRCLIENT_LIB_SONAME}\"")
icculus@9409
   555
                    set(SDL_VIDEO_DRIVER_MIR_DYNAMIC_XKBCOMMON "\"${XKBCOMMON_LIB_SONAME}\"")
icculus@9409
   556
                    set(HAVE_MIR_SHARED TRUE)
icculus@9409
   557
                endif()
icculus@9409
   558
            else()
icculus@9409
   559
                set(EXTRA_LIBS ${MIR_TOOLKIT_LIBRARIES} ${EXTRA_LIBS})
icculus@9409
   560
            endif()
icculus@9409
   561
        endif()
icculus@9277
   562
    endif()
icculus@9277
   563
endmacro()
icculus@8153
   564
icculus@10511
   565
macro(WaylandProtocolGen _SCANNER _XML _PROTL)
icculus@10511
   566
    set(_WAYLAND_PROT_C_CODE "${CMAKE_CURRENT_BINARY_DIR}/wayland-generated-protocols/${_PROTL}-protocol.c")
icculus@10511
   567
    set(_WAYLAND_PROT_H_CODE "${CMAKE_CURRENT_BINARY_DIR}/wayland-generated-protocols/${_PROTL}-client-protocol.h")
icculus@10511
   568
icculus@10511
   569
    add_custom_command(
icculus@10511
   570
        OUTPUT "${_WAYLAND_PROT_H_CODE}"
icculus@10511
   571
        DEPENDS "${_XML}"
icculus@10511
   572
        COMMAND "${_SCANNER}"
icculus@10511
   573
        ARGS client-header "${_XML}" "${_WAYLAND_PROT_H_CODE}"
icculus@10511
   574
    )
icculus@10511
   575
icculus@10511
   576
    add_custom_command(
icculus@10511
   577
        OUTPUT "${_WAYLAND_PROT_C_CODE}"
icculus@10511
   578
        DEPENDS "${_WAYLAND_PROT_H_CODE}"
icculus@10511
   579
        COMMAND "${_SCANNER}"
icculus@10511
   580
        ARGS code "${_XML}" "${_WAYLAND_PROT_C_CODE}"
icculus@10511
   581
    )
icculus@10511
   582
icculus@10511
   583
    set(SOURCE_FILES ${SOURCE_FILES} "${CMAKE_CURRENT_BINARY_DIR}/wayland-generated-protocols/${_PROTL}-protocol.c")
icculus@10511
   584
endmacro()
icculus@10511
   585
gabomdq@6674
   586
# Requires:
gabomdq@8062
   587
# - EGL
icculus@9409
   588
# - PkgCheckModules
icculus@9409
   589
# Optional:
icculus@9409
   590
# - WAYLAND_SHARED opt
icculus@9409
   591
# - HAVE_DLOPEN opt
gabomdq@8062
   592
macro(CheckWayland)
gabomdq@8062
   593
  if(VIDEO_WAYLAND)
icculus@10511
   594
    pkg_check_modules(WAYLAND wayland-client wayland-scanner wayland-protocols wayland-egl wayland-cursor egl xkbcommon)
icculus@10511
   595
icculus@10511
   596
    # We have to generate some protocol interface code for some various Wayland features.
icculus@10511
   597
    if(WAYLAND_FOUND)
icculus@10511
   598
      execute_process(
icculus@10511
   599
        COMMAND ${PKG_CONFIG_EXECUTABLE} --variable=pkgdatadir wayland-client
icculus@10511
   600
        WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
icculus@10511
   601
        RESULT_VARIABLE WAYLAND_CORE_PROTOCOL_DIR_RC
icculus@10511
   602
        OUTPUT_VARIABLE WAYLAND_CORE_PROTOCOL_DIR
icculus@10511
   603
        ERROR_QUIET
icculus@10511
   604
        OUTPUT_STRIP_TRAILING_WHITESPACE
icculus@10511
   605
      )
icculus@10511
   606
      if(NOT WAYLAND_CORE_PROTOCOL_DIR_RC EQUAL 0)
icculus@10511
   607
        set(WAYLAND_FOUND FALSE)
icculus@10511
   608
      endif()
icculus@10511
   609
    endif()
icculus@10511
   610
icculus@10511
   611
    if(WAYLAND_FOUND)
icculus@10511
   612
      execute_process(
icculus@10511
   613
        COMMAND ${PKG_CONFIG_EXECUTABLE} --variable=pkgdatadir wayland-protocols
icculus@10511
   614
        WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
icculus@10511
   615
        RESULT_VARIABLE WAYLAND_PROTOCOLS_DIR_RC
icculus@10511
   616
        OUTPUT_VARIABLE WAYLAND_PROTOCOLS_DIR
icculus@10511
   617
        ERROR_QUIET
icculus@10511
   618
        OUTPUT_STRIP_TRAILING_WHITESPACE
icculus@10511
   619
      )
icculus@10511
   620
      if(NOT WAYLAND_PROTOCOLS_DIR_RC EQUAL 0)
icculus@10511
   621
        set(WAYLAND_FOUND FALSE)
icculus@10511
   622
      endif()
icculus@10511
   623
    endif()
icculus@10511
   624
icculus@10511
   625
    if(WAYLAND_FOUND)
icculus@10511
   626
      execute_process(
icculus@10511
   627
        COMMAND ${PKG_CONFIG_EXECUTABLE} --variable=wayland_scanner wayland-scanner
icculus@10511
   628
        WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
icculus@10511
   629
        RESULT_VARIABLE WAYLAND_SCANNER_RC
icculus@10511
   630
        OUTPUT_VARIABLE WAYLAND_SCANNER
icculus@10511
   631
        ERROR_QUIET
icculus@10511
   632
        OUTPUT_STRIP_TRAILING_WHITESPACE
icculus@10511
   633
      )
icculus@10511
   634
      if(NOT WAYLAND_SCANNER_RC EQUAL 0)
icculus@10511
   635
        set(WAYLAND_FOUND FALSE)
icculus@10511
   636
      endif()
icculus@10511
   637
    endif()
icculus@10511
   638
gabomdq@8062
   639
    if(WAYLAND_FOUND)
gabomdq@8062
   640
      link_directories(
gabomdq@8062
   641
          ${WAYLAND_LIBRARY_DIRS}
gabomdq@8062
   642
      )
gabomdq@8062
   643
      include_directories(
gabomdq@8062
   644
          ${WAYLAND_INCLUDE_DIRS}
gabomdq@8062
   645
      )
gabomdq@8062
   646
      set(HAVE_VIDEO_WAYLAND TRUE)
gabomdq@8062
   647
      set(HAVE_SDL_VIDEO TRUE)
gabomdq@8062
   648
gabomdq@8062
   649
      file(GLOB WAYLAND_SOURCES ${SDL2_SOURCE_DIR}/src/video/wayland/*.c)
gabomdq@8062
   650
      set(SOURCE_FILES ${SOURCE_FILES} ${WAYLAND_SOURCES})
icculus@9409
   651
icculus@10511
   652
      # We have to generate some protocol interface code for some unstable Wayland features.
icculus@10511
   653
      file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/wayland-generated-protocols")
icculus@10511
   654
      include_directories("${CMAKE_CURRENT_BINARY_DIR}/wayland-generated-protocols")
icculus@10511
   655
icculus@10511
   656
      WaylandProtocolGen("${WAYLAND_SCANNER}" "${WAYLAND_CORE_PROTOCOL_DIR}/wayland.xml" "wayland")
icculus@10511
   657
icculus@10511
   658
      foreach(_PROTL relative-pointer-unstable-v1 pointer-constraints-unstable-v1)
icculus@10511
   659
        string(REGEX REPLACE "\\-unstable\\-.*$" "" PROTSUBDIR ${_PROTL})
icculus@10511
   660
        WaylandProtocolGen("${WAYLAND_SCANNER}" "${WAYLAND_PROTOCOLS_DIR}/unstable/${PROTSUBDIR}/${_PROTL}.xml" "${_PROTL}")
icculus@10511
   661
      endforeach()
icculus@10511
   662
icculus@9409
   663
      if(VIDEO_WAYLAND_QT_TOUCH)
icculus@9409
   664
          set(SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH 1)
icculus@9409
   665
      endif()
icculus@9409
   666
icculus@9409
   667
      if(WAYLAND_SHARED)
icculus@9409
   668
        if(NOT HAVE_DLOPEN)
icculus@9409
   669
          message_warn("You must have SDL_LoadObject() support for dynamic Wayland loading")
icculus@9409
   670
        else()
icculus@9409
   671
          FindLibraryAndSONAME(wayland-client)
icculus@9409
   672
          FindLibraryAndSONAME(wayland-egl)
icculus@9409
   673
          FindLibraryAndSONAME(wayland-cursor)
icculus@9409
   674
          FindLibraryAndSONAME(xkbcommon)
icculus@9409
   675
          set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC "\"${WAYLAND_CLIENT_LIB_SONAME}\"")
icculus@9409
   676
          set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_EGL "\"${WAYLAND_EGL_LIB_SONAME}\"")
icculus@9409
   677
          set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_CURSOR "\"${WAYLAND_CURSOR_LIB_SONAME}\"")
icculus@9409
   678
          set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_XKBCOMMON "\"${XKBCOMMON_LIB_SONAME}\"")
icculus@9409
   679
          set(HAVE_WAYLAND_SHARED TRUE)
icculus@9409
   680
        endif()
icculus@9409
   681
      else()
icculus@9409
   682
        set(EXTRA_LIBS ${WAYLAND_LIBRARIES} ${EXTRA_LIBS})
icculus@9409
   683
      endif()
icculus@9409
   684
gabomdq@8062
   685
      set(SDL_VIDEO_DRIVER_WAYLAND 1)
icculus@9277
   686
    endif()
icculus@9277
   687
  endif()
icculus@9277
   688
endmacro()
gabomdq@8062
   689
gabomdq@8062
   690
# Requires:
gabomdq@6674
   691
# - n/a
gabomdq@6674
   692
#
gabomdq@6674
   693
macro(CheckCOCOA)
gabomdq@6674
   694
  if(VIDEO_COCOA)
icculus@8244
   695
    if(APPLE) # Apple always has Cocoa.
icculus@8244
   696
      set(HAVE_VIDEO_COCOA TRUE)
icculus@9277
   697
    endif()
gabomdq@6674
   698
    if(HAVE_VIDEO_COCOA)
gabomdq@6674
   699
      file(GLOB COCOA_SOURCES ${SDL2_SOURCE_DIR}/src/video/cocoa/*.m)
slouken@7182
   700
      set_source_files_properties(${COCOA_SOURCES} PROPERTIES LANGUAGE C)
gabomdq@6674
   701
      set(SOURCE_FILES ${SOURCE_FILES} ${COCOA_SOURCES})
gabomdq@6674
   702
      set(SDL_VIDEO_DRIVER_COCOA 1)
gabomdq@6674
   703
      set(HAVE_SDL_VIDEO TRUE)
icculus@9277
   704
    endif()
icculus@9277
   705
  endif()
icculus@9277
   706
endmacro()
gabomdq@6674
   707
gabomdq@6674
   708
# Requires:
gabomdq@6674
   709
# - PkgCheckModules
gabomdq@6674
   710
# Optional:
gabomdq@6674
   711
# - DIRECTFB_SHARED opt
gabomdq@6674
   712
# - HAVE_DLOPEN opt
gabomdq@6674
   713
macro(CheckDirectFB)
gabomdq@6674
   714
  if(VIDEO_DIRECTFB)
gabomdq@6674
   715
    pkg_check_modules(PKG_DIRECTFB directfb>=1.0.0)
gabomdq@6674
   716
    if(PKG_DIRECTFB_FOUND)
gabomdq@6674
   717
      set(HAVE_VIDEO_DIRECTFB TRUE)
gabomdq@6674
   718
      file(GLOB DIRECTFB_SOURCES ${SDL2_SOURCE_DIR}/src/video/directfb/*.c)
gabomdq@6674
   719
      set(SOURCE_FILES ${SOURCE_FILES} ${DIRECTFB_SOURCES})
gabomdq@6674
   720
      set(SDL_VIDEO_DRIVER_DIRECTFB 1)
gabomdq@6674
   721
      set(SDL_VIDEO_RENDER_DIRECTFB 1)
gabomdq@6674
   722
      list(APPEND EXTRA_CFLAGS ${PKG_DIRECTFB_CFLAGS})
gabomdq@6674
   723
      if(DIRECTFB_SHARED)
gabomdq@6674
   724
        if(NOT HAVE_DLOPEN)
gabomdq@6674
   725
          message_warn("You must have SDL_LoadObject() support for dynamic DirectFB loading")
gabomdq@6674
   726
        else()
icculus@8017
   727
          FindLibraryAndSONAME("directfb")
icculus@8017
   728
          set(SDL_VIDEO_DRIVER_DIRECTFB_DYNAMIC "\"${DIRECTFB_LIB_SONAME}\"")
gabomdq@6674
   729
          set(HAVE_DIRECTFB_SHARED TRUE)
icculus@9277
   730
        endif()
icculus@9277
   731
      else()
gabomdq@6674
   732
        list(APPEND EXTRA_LDFLAGS ${PKG_DIRECTFB_LDFLAGS})
icculus@9277
   733
      endif()
gabomdq@6674
   734
      set(HAVE_SDL_VIDEO TRUE)
icculus@9277
   735
    endif()
icculus@9277
   736
  endif()
icculus@9277
   737
endmacro()
gabomdq@6674
   738
gabomdq@6674
   739
# Requires:
denis@9127
   740
# - n/a
slouken@9164
   741
macro(CheckVivante)
slouken@9164
   742
  if(VIDEO_VIVANTE)
denis@9127
   743
    check_c_source_compiles("
slouken@9164
   744
        #include <gc_vdk.h>
slouken@9164
   745
        int main(int argc, char** argv) {}" HAVE_VIDEO_VIVANTE_VDK)
slouken@9164
   746
    check_c_source_compiles("
slouken@9164
   747
        #define LINUX
denis@9127
   748
        #define EGL_API_FB
denis@9127
   749
        #include <EGL/eglvivante.h>
slouken@9164
   750
        int main(int argc, char** argv) {}" HAVE_VIDEO_VIVANTE_EGL_FB)
slouken@9164
   751
    if(HAVE_VIDEO_VIVANTE_VDK OR HAVE_VIDEO_VIVANTE_EGL_FB)
slouken@9164
   752
      set(HAVE_VIDEO_VIVANTE TRUE)
denis@9127
   753
      set(HAVE_SDL_VIDEO TRUE)
denis@9127
   754
slouken@9164
   755
      file(GLOB VIVANTE_SOURCES ${SDL2_SOURCE_DIR}/src/video/vivante/*.c)
slouken@9164
   756
      set(SOURCE_FILES ${SOURCE_FILES} ${VIVANTE_SOURCES})
slouken@9164
   757
      set(SDL_VIDEO_DRIVER_VIVANTE 1)
slouken@9164
   758
      if(HAVE_VIDEO_VIVANTE_VDK)
slouken@9164
   759
        set(SDL_VIDEO_DRIVER_VIVANTE_VDK 1)
slouken@9164
   760
        list(APPEND EXTRA_LIBS VDK VIVANTE)
philipp@9170
   761
      else()
slouken@9164
   762
        set(SDL_CFLAGS "${SDL_CFLAGS} -DLINUX -DEGL_API_FB")
slouken@9164
   763
        list(APPEND EXTRA_LIBS EGL)
slouken@9164
   764
      endif(HAVE_VIDEO_VIVANTE_VDK)
slouken@9164
   765
    endif(HAVE_VIDEO_VIVANTE_VDK OR HAVE_VIDEO_VIVANTE_EGL_FB)
slouken@9164
   766
  endif(VIDEO_VIVANTE)
slouken@9164
   767
endmacro(CheckVivante)
denis@9127
   768
denis@9127
   769
# Requires:
gabomdq@6674
   770
# - nada
gabomdq@6674
   771
macro(CheckOpenGLX11)
gabomdq@6674
   772
  if(VIDEO_OPENGL)
gabomdq@6674
   773
    check_c_source_compiles("
gabomdq@6674
   774
        #include <GL/gl.h>
gabomdq@6674
   775
        #include <GL/glx.h>
gabomdq@6674
   776
        int main(int argc, char** argv) {}" HAVE_VIDEO_OPENGL)
gabomdq@6674
   777
gabomdq@6674
   778
    if(HAVE_VIDEO_OPENGL)
gabomdq@6674
   779
      set(HAVE_VIDEO_OPENGL TRUE)
gabomdq@6674
   780
      set(SDL_VIDEO_OPENGL 1)
gabomdq@6674
   781
      set(SDL_VIDEO_OPENGL_GLX 1)
gabomdq@6674
   782
      set(SDL_VIDEO_RENDER_OGL 1)
icculus@9277
   783
    endif()
icculus@9277
   784
  endif()
icculus@9277
   785
endmacro()
gabomdq@6674
   786
gabomdq@6674
   787
# Requires:
gabomdq@6674
   788
# - nada
gabomdq@6674
   789
macro(CheckOpenGLESX11)
gabomdq@6674
   790
  if(VIDEO_OPENGLES)
gabomdq@6674
   791
    check_c_source_compiles("
denis@9127
   792
        #define EGL_API_FB
gabomdq@6674
   793
        #include <EGL/egl.h>
gabomdq@7690
   794
        int main (int argc, char** argv) {}" HAVE_VIDEO_OPENGL_EGL)
gabomdq@7690
   795
    if(HAVE_VIDEO_OPENGL_EGL)
gabomdq@7690
   796
        set(SDL_VIDEO_OPENGL_EGL 1)
icculus@9277
   797
    endif()
gabomdq@7690
   798
    check_c_source_compiles("
gabomdq@7690
   799
      #include <GLES/gl.h>
gabomdq@7690
   800
      #include <GLES/glext.h>
gabomdq@7690
   801
      int main (int argc, char** argv) {}" HAVE_VIDEO_OPENGLES_V1)
gabomdq@7690
   802
    if(HAVE_VIDEO_OPENGLES_V1)
gabomdq@7690
   803
        set(HAVE_VIDEO_OPENGLES TRUE)
gabomdq@6674
   804
        set(SDL_VIDEO_OPENGL_ES 1)
gabomdq@6674
   805
        set(SDL_VIDEO_RENDER_OGL_ES 1)
icculus@9277
   806
    endif()
gabomdq@7690
   807
    check_c_source_compiles("
gabomdq@7690
   808
      #include <GLES2/gl2.h>
gabomdq@7690
   809
      #include <GLES2/gl2ext.h>
gabomdq@7690
   810
      int main (int argc, char** argv) {}" HAVE_VIDEO_OPENGLES_V2)
gabomdq@7690
   811
    if(HAVE_VIDEO_OPENGLES_V2)
gabomdq@7690
   812
        set(HAVE_VIDEO_OPENGLES TRUE)
gabomdq@6674
   813
        set(SDL_VIDEO_OPENGL_ES2 1)
gabomdq@6674
   814
        set(SDL_VIDEO_RENDER_OGL_ES2 1)
icculus@9277
   815
    endif()
gabomdq@7690
   816
icculus@9277
   817
  endif()
icculus@9277
   818
endmacro()
gabomdq@6674
   819
icculus@9414
   820
# Requires:
gabomdq@6674
   821
# - nada
gabomdq@6674
   822
# Optional:
gabomdq@6674
   823
# - THREADS opt
gabomdq@6674
   824
# Sets:
gabomdq@6674
   825
# PTHREAD_CFLAGS
gabomdq@6674
   826
# PTHREAD_LIBS
gabomdq@6674
   827
macro(CheckPTHREAD)
gabomdq@6674
   828
  if(PTHREADS)
gabomdq@6674
   829
    if(LINUX)
gabomdq@6674
   830
      set(PTHREAD_CFLAGS "-D_REENTRANT")
gabomdq@7078
   831
      set(PTHREAD_LDFLAGS "-pthread")
gabomdq@6674
   832
    elseif(BSDI)
gabomdq@6674
   833
      set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
gabomdq@6674
   834
      set(PTHREAD_LDFLAGS "")
gabomdq@6674
   835
    elseif(DARWIN)
gabomdq@6674
   836
      set(PTHREAD_CFLAGS "-D_THREAD_SAFE")
gabomdq@6674
   837
      # causes Carbon.p complaints?
gabomdq@6674
   838
      # set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
gabomdq@6674
   839
      set(PTHREAD_LDFLAGS "")
gabomdq@6674
   840
    elseif(FREEBSD)
gabomdq@6674
   841
      set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
gabomdq@6674
   842
      set(PTHREAD_LDFLAGS "-pthread")
gabomdq@6674
   843
    elseif(NETBSD)
gabomdq@6674
   844
      set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
gabomdq@6674
   845
      set(PTHREAD_LDFLAGS "-lpthread")
gabomdq@6674
   846
    elseif(OPENBSD)
gabomdq@6674
   847
      set(PTHREAD_CFLAGS "-D_REENTRANT")
gabomdq@6674
   848
      set(PTHREAD_LDFLAGS "-pthread")
gabomdq@6674
   849
    elseif(SOLARIS)
gabomdq@6674
   850
      set(PTHREAD_CFLAGS "-D_REENTRANT")
gabomdq@6674
   851
      set(PTHREAD_LDFLAGS "-pthread -lposix4")
gabomdq@6674
   852
    elseif(SYSV5)
gabomdq@6674
   853
      set(PTHREAD_CFLAGS "-D_REENTRANT -Kthread")
gabomdq@6674
   854
      set(PTHREAD_LDFLAGS "")
gabomdq@6674
   855
    elseif(AIX)
gabomdq@6674
   856
      set(PTHREAD_CFLAGS "-D_REENTRANT -mthreads")
gabomdq@6674
   857
      set(PTHREAD_LDFLAGS "-pthread")
gabomdq@6674
   858
    elseif(HPUX)
gabomdq@6674
   859
      set(PTHREAD_CFLAGS "-D_REENTRANT")
gabomdq@6674
   860
      set(PTHREAD_LDFLAGS "-L/usr/lib -pthread")
icculus@7981
   861
    elseif(HAIKU)
icculus@7977
   862
      set(PTHREAD_CFLAGS "-D_REENTRANT")
icculus@7977
   863
      set(PTHREAD_LDFLAGS "")
gabomdq@6674
   864
    else()
gabomdq@6674
   865
      set(PTHREAD_CFLAGS "-D_REENTRANT")
gabomdq@6674
   866
      set(PTHREAD_LDFLAGS "-lpthread")
icculus@9277
   867
    endif()
gabomdq@6674
   868
gabomdq@6674
   869
    # Run some tests
jujjyl@10329
   870
    set(ORIG_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
jujjyl@10329
   871
    set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${PTHREAD_CFLAGS} ${PTHREAD_LDFLAGS}")
icculus@9414
   872
    if(CMAKE_CROSSCOMPILING)
icculus@9414
   873
      set(HAVE_PTHREADS 1)
icculus@9414
   874
    else()
icculus@9414
   875
      check_c_source_runs("
gabomdq@6674
   876
        #include <pthread.h>
gabomdq@6674
   877
        int main(int argc, char** argv) {
gabomdq@6674
   878
          pthread_attr_t type;
gabomdq@6674
   879
          pthread_attr_init(&type);
gabomdq@6674
   880
          return 0;
gabomdq@6674
   881
        }" HAVE_PTHREADS)
icculus@9414
   882
    endif()
gabomdq@6674
   883
    if(HAVE_PTHREADS)
gabomdq@6674
   884
      set(SDL_THREAD_PTHREAD 1)
gabomdq@6674
   885
      list(APPEND EXTRA_CFLAGS ${PTHREAD_CFLAGS})
gabomdq@6674
   886
      list(APPEND EXTRA_LDFLAGS ${PTHREAD_LDFLAGS})
gabomdq@6674
   887
      set(SDL_CFLAGS "${SDL_CFLAGS} ${PTHREAD_CFLAGS}")
gabomdq@6674
   888
      list(APPEND SDL_LIBS ${PTHREAD_LDFLAGS})
gabomdq@6674
   889
gabomdq@6674
   890
      check_c_source_compiles("
gabomdq@6674
   891
        #include <pthread.h>
gabomdq@6674
   892
        int main(int argc, char **argv) {
gabomdq@6674
   893
          pthread_mutexattr_t attr;
gabomdq@6674
   894
          pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
gabomdq@7078
   895
          return 0;
gabomdq@6674
   896
        }" HAVE_RECURSIVE_MUTEXES)
gabomdq@6674
   897
      if(HAVE_RECURSIVE_MUTEXES)
gabomdq@6674
   898
        set(SDL_THREAD_PTHREAD_RECURSIVE_MUTEX 1)
icculus@9277
   899
      else()
gabomdq@6674
   900
        check_c_source_compiles("
gabomdq@6674
   901
            #include <pthread.h>
gabomdq@6674
   902
            int main(int argc, char **argv) {
gabomdq@6674
   903
              pthread_mutexattr_t attr;
gabomdq@6674
   904
              pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
gabomdq@7078
   905
              return 0;
gabomdq@6674
   906
            }" HAVE_RECURSIVE_MUTEXES_NP)
gabomdq@6674
   907
        if(HAVE_RECURSIVE_MUTEXES_NP)
gabomdq@6674
   908
          set(SDL_THREAD_PTHREAD_RECURSIVE_MUTEX_NP 1)
icculus@9277
   909
        endif()
icculus@9277
   910
      endif()
gabomdq@6674
   911
gabomdq@6674
   912
      if(PTHREADS_SEM)
gabomdq@6674
   913
        check_c_source_compiles("#include <pthread.h>
gabomdq@7078
   914
                                 #include <semaphore.h>
gabomdq@7078
   915
                                 int main(int argc, char **argv) { return 0; }" HAVE_PTHREADS_SEM)
gabomdq@6674
   916
        if(HAVE_PTHREADS_SEM)
gabomdq@6674
   917
          check_c_source_compiles("
gabomdq@6674
   918
              #include <pthread.h>
gabomdq@6674
   919
              #include <semaphore.h>
gabomdq@6674
   920
              int main(int argc, char **argv) {
gabomdq@6674
   921
                  sem_timedwait(NULL, NULL);
gabomdq@6674
   922
                  return 0;
gabomdq@6674
   923
              }" HAVE_SEM_TIMEDWAIT)
icculus@9277
   924
        endif()
icculus@9277
   925
      endif()
gabomdq@6674
   926
gabomdq@6674
   927
      check_c_source_compiles("
gabomdq@6674
   928
          #include <pthread.h>
gabomdq@6674
   929
          #include <pthread_np.h>
gabomdq@6674
   930
          int main(int argc, char** argv) { return 0; }" HAVE_PTHREAD_NP_H)
icculus@9414
   931
      check_function_exists(pthread_setname_np HAVE_PTHREAD_SETNAME_NP)
icculus@9415
   932
      check_function_exists(pthread_set_name_np HAVE_PTHREAD_SET_NAME_NP)
jujjyl@10329
   933
      set(CMAKE_REQUIRED_FLAGS "${ORIG_CMAKE_REQUIRED_FLAGS}")
gabomdq@6674
   934
gabomdq@6674
   935
      set(SOURCE_FILES ${SOURCE_FILES}
gabomdq@6674
   936
          ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_systhread.c
gabomdq@6674
   937
          ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_sysmutex.c   # Can be faked, if necessary
gabomdq@6674
   938
          ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_syscond.c    # Can be faked, if necessary
icculus@7400
   939
          ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_systls.c
gabomdq@6674
   940
          )
gabomdq@6674
   941
      if(HAVE_PTHREADS_SEM)
gabomdq@6674
   942
        set(SOURCE_FILES ${SOURCE_FILES}
gabomdq@6674
   943
            ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_syssem.c)
icculus@9277
   944
      else()
gabomdq@6674
   945
        set(SOURCE_FILES ${SOURCE_FILES}
gabomdq@6674
   946
            ${SDL2_SOURCE_DIR}/src/thread/generic/SDL_syssem.c)
icculus@9277
   947
      endif()
gabomdq@6674
   948
      set(HAVE_SDL_THREADS TRUE)
icculus@9277
   949
    endif()
icculus@9277
   950
  endif()
icculus@9277
   951
endmacro()
gabomdq@6674
   952
gabomdq@6674
   953
# Requires
gabomdq@6674
   954
# - nada
gabomdq@6674
   955
# Optional:
gabomdq@6674
   956
# Sets:
gabomdq@6674
   957
# USB_LIBS
gabomdq@6674
   958
# USB_CFLAGS
gabomdq@6674
   959
macro(CheckUSBHID)
gabomdq@6674
   960
  check_library_exists(usbhid hid_init "" LIBUSBHID)
gabomdq@6674
   961
  if(LIBUSBHID)
gabomdq@6674
   962
    check_include_file(usbhid.h HAVE_USBHID_H)
gabomdq@6674
   963
    if(HAVE_USBHID_H)
gabomdq@6674
   964
      set(USB_CFLAGS "-DHAVE_USBHID_H")
icculus@9277
   965
    endif()
gabomdq@6674
   966
gabomdq@6674
   967
    check_include_file(libusbhid.h HAVE_LIBUSBHID_H)
gabomdq@6674
   968
    if(HAVE_LIBUSBHID_H)
gabomdq@6674
   969
      set(USB_CFLAGS "${USB_CFLAGS} -DHAVE_LIBUSBHID_H")
icculus@9277
   970
    endif()
gabomdq@6674
   971
    set(USB_LIBS ${USB_LIBS} usbhid)
icculus@9277
   972
  else()
gabomdq@6674
   973
    check_include_file(usb.h HAVE_USB_H)
gabomdq@6674
   974
    if(HAVE_USB_H)
gabomdq@6674
   975
      set(USB_CFLAGS "-DHAVE_USB_H")
icculus@9277
   976
    endif()
gabomdq@6674
   977
    check_include_file(libusb.h HAVE_LIBUSB_H)
gabomdq@6674
   978
    if(HAVE_LIBUSB_H)
gabomdq@6674
   979
      set(USB_CFLAGS "${USB_CFLAGS} -DHAVE_LIBUSB_H")
icculus@9277
   980
    endif()
gabomdq@6674
   981
    check_library_exists(usb hid_init "" LIBUSB)
gabomdq@6674
   982
    if(LIBUSB)
gabomdq@6674
   983
      set(USB_LIBS ${USB_LIBS} usb)
icculus@9277
   984
    endif()
icculus@9277
   985
  endif()
gabomdq@6674
   986
jujjyl@10329
   987
  set(ORIG_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
jujjyl@10329
   988
  set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${USB_CFLAGS}")
gabomdq@6674
   989
  set(CMAKE_REQUIRED_LIBRARIES "${USB_LIBS}")
gabomdq@6674
   990
  check_c_source_compiles("
gabomdq@6674
   991
       #include <sys/types.h>
gabomdq@6674
   992
        #if defined(HAVE_USB_H)
gabomdq@6674
   993
        #include <usb.h>
gabomdq@6674
   994
        #endif
gabomdq@6674
   995
        #ifdef __DragonFly__
gabomdq@6674
   996
        # include <bus/usb/usb.h>
gabomdq@6674
   997
        # include <bus/usb/usbhid.h>
gabomdq@6674
   998
        #else
gabomdq@6674
   999
        # include <dev/usb/usb.h>
gabomdq@6674
  1000
        # include <dev/usb/usbhid.h>
gabomdq@6674
  1001
        #endif
gabomdq@6674
  1002
        #if defined(HAVE_USBHID_H)
gabomdq@6674
  1003
        #include <usbhid.h>
gabomdq@6674
  1004
        #elif defined(HAVE_LIBUSB_H)
gabomdq@6674
  1005
        #include <libusb.h>
gabomdq@6674
  1006
        #elif defined(HAVE_LIBUSBHID_H)
gabomdq@6674
  1007
        #include <libusbhid.h>
gabomdq@6674
  1008
        #endif
gabomdq@6674
  1009
        int main(int argc, char **argv) {
gabomdq@6674
  1010
          struct report_desc *repdesc;
gabomdq@6674
  1011
          struct usb_ctl_report *repbuf;
gabomdq@6674
  1012
          hid_kind_t hidkind;
gabomdq@6674
  1013
          return 0;
gabomdq@6674
  1014
        }" HAVE_USBHID)
gabomdq@6674
  1015
  if(HAVE_USBHID)
gabomdq@6674
  1016
    check_c_source_compiles("
gabomdq@6674
  1017
          #include <sys/types.h>
gabomdq@6674
  1018
          #if defined(HAVE_USB_H)
gabomdq@6674
  1019
          #include <usb.h>
gabomdq@6674
  1020
          #endif
gabomdq@6674
  1021
          #ifdef __DragonFly__
gabomdq@6674
  1022
          # include <bus/usb/usb.h>
gabomdq@6674
  1023
          # include <bus/usb/usbhid.h>
gabomdq@6674
  1024
          #else
gabomdq@6674
  1025
          # include <dev/usb/usb.h>
gabomdq@6674
  1026
          # include <dev/usb/usbhid.h>
gabomdq@6674
  1027
          #endif
gabomdq@6674
  1028
          #if defined(HAVE_USBHID_H)
gabomdq@6674
  1029
          #include <usbhid.h>
gabomdq@6674
  1030
          #elif defined(HAVE_LIBUSB_H)
gabomdq@6674
  1031
          #include <libusb.h>
gabomdq@6674
  1032
          #elif defined(HAVE_LIBUSBHID_H)
gabomdq@6674
  1033
          #include <libusbhid.h>
gabomdq@6674
  1034
          #endif
gabomdq@6674
  1035
          int main(int argc, char** argv) {
gabomdq@6674
  1036
            struct usb_ctl_report buf;
gabomdq@6674
  1037
            if (buf.ucr_data) { }
gabomdq@6674
  1038
            return 0;
gabomdq@6674
  1039
          }" HAVE_USBHID_UCR_DATA)
gabomdq@6674
  1040
    if(HAVE_USBHID_UCR_DATA)
gabomdq@6674
  1041
      set(USB_CFLAGS "${USB_CFLAGS} -DUSBHID_UCR_DATA")
icculus@9277
  1042
    endif()
gabomdq@6674
  1043
gabomdq@6674
  1044
    check_c_source_compiles("
gabomdq@6674
  1045
          #include <sys/types.h>
gabomdq@6674
  1046
          #if defined(HAVE_USB_H)
gabomdq@6674
  1047
          #include <usb.h>
gabomdq@6674
  1048
          #endif
gabomdq@6674
  1049
          #ifdef __DragonFly__
gabomdq@6674
  1050
          #include <bus/usb/usb.h>
gabomdq@6674
  1051
          #include <bus/usb/usbhid.h>
gabomdq@6674
  1052
          #else
gabomdq@6674
  1053
          #include <dev/usb/usb.h>
gabomdq@6674
  1054
          #include <dev/usb/usbhid.h>
gabomdq@6674
  1055
          #endif
gabomdq@6674
  1056
          #if defined(HAVE_USBHID_H)
gabomdq@6674
  1057
          #include <usbhid.h>
gabomdq@6674
  1058
          #elif defined(HAVE_LIBUSB_H)
gabomdq@6674
  1059
          #include <libusb.h>
gabomdq@6674
  1060
          #elif defined(HAVE_LIBUSBHID_H)
gabomdq@6674
  1061
          #include <libusbhid.h>
gabomdq@6674
  1062
          #endif
gabomdq@6674
  1063
          int main(int argc, char **argv) {
gabomdq@6674
  1064
            report_desc_t d;
gabomdq@6674
  1065
            hid_start_parse(d, 1, 1);
gabomdq@6674
  1066
            return 0;
gabomdq@6674
  1067
          }" HAVE_USBHID_NEW)
gabomdq@6674
  1068
    if(HAVE_USBHID_NEW)
gabomdq@6674
  1069
      set(USB_CFLAGS "${USB_CFLAGS} -DUSBHID_NEW")
icculus@9277
  1070
    endif()
gabomdq@6674
  1071
gabomdq@6674
  1072
    check_c_source_compiles("
gabomdq@6674
  1073
        #include <machine/joystick.h>
gabomdq@6674
  1074
        int main(int argc, char** argv) {
gabomdq@6674
  1075
            struct joystick t;
gabomdq@6674
  1076
            return 0;
gabomdq@6674
  1077
        }" HAVE_MACHINE_JOYSTICK)
gabomdq@6674
  1078
    if(HAVE_MACHINE_JOYSTICK)
gabomdq@6674
  1079
      set(SDL_JOYSTICK_USBHID_MACHINE_JOYSTICK_H 1)
icculus@9277
  1080
    endif()
gabomdq@6674
  1081
    set(SDL_JOYSTICK_USBHID 1)
gabomdq@6674
  1082
    file(GLOB BSD_JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/bsd/*.c)
gabomdq@6674
  1083
    set(SOURCE_FILES ${SOURCE_FILES} ${BSD_JOYSTICK_SOURCES})
gabomdq@6674
  1084
    list(APPEND EXTRA_CFLAGS ${USB_CFLAGS})
gabomdq@6674
  1085
    list(APPEND EXTRA_LIBS ${USB_LIBS})
gabomdq@6674
  1086
    set(HAVE_SDL_JOYSTICK TRUE)
gabomdq@6674
  1087
gabomdq@6674
  1088
    set(CMAKE_REQUIRED_LIBRARIES)
jujjyl@10329
  1089
    set(CMAKE_REQUIRED_FLAGS "${ORIG_CMAKE_REQUIRED_FLAGS}")
icculus@9277
  1090
  endif()
icculus@9277
  1091
endmacro()
slouken@9077
  1092
slouken@9077
  1093
# Requires:
slouken@9077
  1094
# - n/a
slouken@9077
  1095
macro(CheckRPI)
slouken@9077
  1096
  if(VIDEO_RPI)
slouken@9077
  1097
    set(VIDEO_RPI_INCLUDE_DIRS "/opt/vc/include" "/opt/vc/include/interface/vcos/pthreads" "/opt/vc/include/interface/vmcs_host/linux/" )
slouken@9077
  1098
    set(VIDEO_RPI_LIBRARY_DIRS "/opt/vc/lib" )
slouken@9077
  1099
    set(VIDEO_RPI_LIBS bcm_host )
slouken@9077
  1100
    listtostr(VIDEO_RPI_INCLUDE_DIRS VIDEO_RPI_INCLUDE_FLAGS "-I")
slouken@9077
  1101
    listtostr(VIDEO_RPI_LIBRARY_DIRS VIDEO_RPI_LIBRARY_FLAGS "-L")
slouken@9077
  1102
jujjyl@10329
  1103
    set(ORIG_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
jujjyl@10329
  1104
    set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${VIDEO_RPI_INCLUDE_FLAGS} ${VIDEO_RPI_LIBRARY_FLAGS}")
slouken@9077
  1105
    set(CMAKE_REQUIRED_LIBRARIES "${VIDEO_RPI_LIBS}")
slouken@9077
  1106
    check_c_source_compiles("
slouken@9077
  1107
        #include <bcm_host.h>
slouken@9077
  1108
        int main(int argc, char **argv) {}" HAVE_VIDEO_RPI)
jujjyl@10329
  1109
    set(CMAKE_REQUIRED_FLAGS "${ORIG_CMAKE_REQUIRED_FLAGS}")
slouken@9077
  1110
    set(CMAKE_REQUIRED_LIBRARIES)
slouken@9077
  1111
slouken@9077
  1112
    if(SDL_VIDEO AND HAVE_VIDEO_RPI)
slouken@9077
  1113
      set(HAVE_SDL_VIDEO TRUE)
slouken@9077
  1114
      set(SDL_VIDEO_DRIVER_RPI 1)
slouken@9077
  1115
      file(GLOB VIDEO_RPI_SOURCES ${SDL2_SOURCE_DIR}/src/video/raspberry/*.c)
slouken@9077
  1116
      set(SOURCE_FILES ${SOURCE_FILES} ${VIDEO_RPI_SOURCES})
slouken@9077
  1117
      list(APPEND EXTRA_LIBS ${VIDEO_RPI_LIBS})
slouken@9077
  1118
      set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${VIDEO_RPI_INCLUDE_FLAGS} ${VIDEO_RPI_LIBRARY_FLAGS}")
slouken@9077
  1119
    endif(SDL_VIDEO AND HAVE_VIDEO_RPI)
slouken@9077
  1120
  endif(VIDEO_RPI)
slouken@9077
  1121
endmacro(CheckRPI)