CMakeLists.txt
changeset 12932 800524378309
parent 12901 5cbf6472a916
child 12938 165d577cdc63
     1.1 --- a/CMakeLists.txt	Mon Jul 08 16:08:16 2019 -0400
     1.2 +++ b/CMakeLists.txt	Mon Jul 08 16:46:52 2019 -0400
     1.3 @@ -155,6 +155,20 @@
     1.4    set(OPT_DEF_LIBC ON)
     1.5  endif()
     1.6  
     1.7 +# The hidraw support doesn't catch Xbox, PS4 and Nintendo controllers,
     1.8 +#  so we'll just use libusb when it's available. Except that libusb
     1.9 +#  requires root permissions to open devices, so that's not generally
    1.10 +#  useful, and we'll disable this by default on Unix. Windows and macOS
    1.11 +#  can use it without root access, though, so enable by default there.
    1.12 +if(WINDOWS OR APPLE OR ANDROID)
    1.13 +  set(HIDAPI_SKIP_LIBUSB TRUE)
    1.14 +else()
    1.15 +  set(HIDAPI_SKIP_LIBUSB FALSE)
    1.16 +endif()
    1.17 +if (HIDAPI_SKIP_LIBUSB)
    1.18 +  set(OPT_DEF_HIDAPI ON)
    1.19 +endif()
    1.20 +
    1.21  # Compiler info
    1.22  if(CMAKE_COMPILER_IS_GNUCC)
    1.23    set(USE_GCC TRUE)
    1.24 @@ -358,6 +372,7 @@
    1.25  dep_option(KMSDRM_SHARED       "Dynamically load KMS DRM support" ON "VIDEO_KMSDRM" OFF)
    1.26  option_string(BACKGROUNDING_SIGNAL "number to use for magic backgrounding signal or 'OFF'" "OFF")
    1.27  option_string(FOREGROUNDING_SIGNAL "number to use for magic foregrounding signal or 'OFF'" "OFF")
    1.28 +set_option(HIDAPI              "Use HIDAPI for low level joystick drivers" ${OPT_DEF_HIDAPI})
    1.29  
    1.30  set(SDL_SHARED ${SDL_SHARED_ENABLED_BY_DEFAULT} CACHE BOOL "Build a shared version of the library")
    1.31  set(SDL_STATIC ${SDL_STATIC_ENABLED_BY_DEFAULT} CACHE BOOL "Build a static version of the library")
    1.32 @@ -828,6 +843,7 @@
    1.33    endif()
    1.34  endif()
    1.35  
    1.36 +# Platform-specific options and settings
    1.37  if(ANDROID)
    1.38    file(GLOB ANDROID_CORE_SOURCES ${SDL2_SOURCE_DIR}/src/core/android/*.c)
    1.39    set(SOURCE_FILES ${SOURCE_FILES} ${ANDROID_CORE_SOURCES})
    1.40 @@ -863,6 +879,7 @@
    1.41      set(HAVE_SDL_HAPTIC TRUE)
    1.42    endif()
    1.43    if(SDL_JOYSTICK)
    1.44 +    CheckHIDAPI()
    1.45      set(SDL_JOYSTICK_ANDROID 1)
    1.46      file(GLOB ANDROID_JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/android/*.c ${SDL2_SOURCE_DIR}/src/joystick/steam/*.c)
    1.47      set(SOURCE_FILES ${SOURCE_FILES} ${ANDROID_JOYSTICK_SOURCES})
    1.48 @@ -934,14 +951,9 @@
    1.49      endif()
    1.50    endif()
    1.51  
    1.52 -  file(GLOB ANDROID_HIDAPI_SOURCES ${SDL2_SOURCE_DIR}/src/hidapi/android/*.cpp)
    1.53 -
    1.54    CheckPTHREAD()
    1.55  
    1.56 -endif()
    1.57 -
    1.58 -# Platform-specific options and settings
    1.59 -if(EMSCRIPTEN)
    1.60 +elseif(EMSCRIPTEN)
    1.61    # Hide noisy warnings that intend to aid mostly during initial stages of porting a new
    1.62    # project. Uncomment at will for verbose cross-compiling -I/../ path info.
    1.63    add_definitions(-Wno-warn-absolute-paths)
    1.64 @@ -993,6 +1005,7 @@
    1.65        set(SDL_VIDEO_RENDER_OGL_ES2 1)
    1.66      endif()
    1.67    endif()
    1.68 +
    1.69  elseif(UNIX AND NOT APPLE AND NOT ANDROID)
    1.70    if(SDL_AUDIO)
    1.71      if(SYSV5 OR SOLARIS OR HPUX)
    1.72 @@ -1116,6 +1129,7 @@
    1.73  
    1.74    if(SDL_JOYSTICK)
    1.75      CheckUSBHID()   # seems to be BSD specific - limit the test to BSD only?
    1.76 +    CheckHIDAPI()
    1.77      if(LINUX AND NOT ANDROID)
    1.78        set(SDL_JOYSTICK_LINUX 1)
    1.79        file(GLOB JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/linux/*.c ${SDL2_SOURCE_DIR}/src/joystick/steam/*.c)
    1.80 @@ -1359,6 +1373,10 @@
    1.81    endif()
    1.82  
    1.83    if(SDL_JOYSTICK)
    1.84 +    CheckHIDAPI()
    1.85 +    if(HAVE_HIDAPI)
    1.86 +      set(SOURCE_FILES ${SOURCE_FILES} ${SDL2_SOURCE_DIR}/src/hidapi/windows/hid.c)
    1.87 +    endif()
    1.88      file(GLOB JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/windows/*.c)
    1.89      set(SOURCE_FILES ${SOURCE_FILES} ${JOYSTICK_SOURCES})
    1.90      if(HAVE_DINPUT_H)
    1.91 @@ -1404,6 +1422,7 @@
    1.92      set(SDL_CFLAGS "${SDL_CFLAGS} -Dmain=SDL_main")
    1.93      list(APPEND SDL_LIBS "-lmingw32" "-lSDL2main" "-mwindows")
    1.94    endif()
    1.95 +
    1.96  elseif(APPLE)
    1.97    # TODO: rework this all for proper MacOS X, iOS and Darwin support
    1.98  
    1.99 @@ -1441,6 +1460,14 @@
   1.100    endif()
   1.101  
   1.102    if(SDL_JOYSTICK)
   1.103 +    CheckHIDAPI()
   1.104 +    if(HAVE_HIDAPI)
   1.105 +      if(IOS)
   1.106 +        set(SOURCE_FILES ${SOURCE_FILES} ${SDL2_SOURCE_DIR}/src/hidapi/ios/hid.m)
   1.107 +      else()
   1.108 +        set(SOURCE_FILES ${SOURCE_FILES} ${SDL2_SOURCE_DIR}/src/hidapi/mac/hid.c)
   1.109 +      endif()
   1.110 +    endif()
   1.111      set(SDL_JOYSTICK_IOKIT 1)
   1.112      if (IOS)
   1.113        file(GLOB JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/iphoneos/*.m ${SDL2_SOURCE_DIR}/src/joystick/steam/*.c)
   1.114 @@ -1553,6 +1580,7 @@
   1.115    endif()
   1.116  
   1.117    CheckPTHREAD()
   1.118 +
   1.119  elseif(HAIKU)
   1.120    if(SDL_VIDEO)
   1.121      set(SDL_VIDEO_DRIVER_HAIKU 1)
   1.122 @@ -1799,7 +1827,10 @@
   1.123  endif()
   1.124  
   1.125  if(ANDROID)
   1.126 -  add_library(hidapi SHARED ${ANDROID_HIDAPI_SOURCES})
   1.127 +  if(HAVE_HIDAPI)
   1.128 +    add_library(hidapi SHARED ${SDL2_SOURCE_DIR}/src/hidapi/android/hid.cpp)
   1.129 +  endif()
   1.130 +
   1.131    if(MSVC AND NOT LIBC)
   1.132      # Don't try to link with the default set of libraries.
   1.133      set_target_properties(hidapi PROPERTIES LINK_FLAGS_RELEASE "/NODEFAULTLIB")