cmake/sdlchecks.cmake
author Ryan C. Gordon <icculus@icculus.org>
Sun, 24 Jun 2018 15:12:18 -0400
changeset 12030 c0c4ba22a685
parent 11871 c207c3ab46ee
child 12035 1a7dec71e8e0
permissions -rw-r--r--
cmake: Look in popular places for X11 headers, export this info properly.

Fixes CMake not being able to find X11 on FreeBSD (which generally has the
headers in /usr/local/include/X11).

List of other popular places borrowed from CMake's FindX11 module.

This worked on the configure script because of magic in the AC_PATH_X macro.

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