cmake/sdlchecks.cmake
author Sam Lantinga <slouken@libsdl.org>
Fri, 18 Oct 2013 00:49:59 -0700
changeset 7835 4be86f76e710
parent 7690 76d7b6007a64
child 7977 5272ae8fccd7
permissions -rw-r--r--
Fixed bug 2108 - CMake does not set X11 includes properly for sdl2-config and friends

Marcus von Appen

The autotools-based code uses X_CFLAGS and some hackish x_includes code to add some necessary includes to SDL_CFLAGS for proper X11 and OpenGL include handling.

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