cmake: enable disabing hidapi
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 13fbe81..c8840b1 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -515,10 +515,12 @@ set_option(SDL_INSTALL_TESTS "Install test-cases" OFF)
set(HAVE_STATIC_PIC "${SDL_STATIC_PIC}")
-if(HIDAPI_ONLY_LIBUSB)
- set(SDL_HIDAPI_LIBUSB ON CACHE BOOL "" FORCE)
-elseif(HIDAPI_SKIP_LIBUSB)
- set(SDL_HIDAPI_LIBUSB OFF CACHE BOOL "" FORCE)
+if(SDL_HIDAPI)
+ if(HIDAPI_ONLY_LIBUSB)
+ set(SDL_HIDAPI_LIBUSB ON CACHE BOOL "" FORCE)
+ elseif(HIDAPI_SKIP_LIBUSB)
+ set(SDL_HIDAPI_LIBUSB OFF CACHE BOOL "" FORCE)
+ endif()
endif()
if(VITA)
diff --git a/cmake/sdlchecks.cmake b/cmake/sdlchecks.cmake
index 198a7e9..7e25075 100644
--- a/cmake/sdlchecks.cmake
+++ b/cmake/sdlchecks.cmake
@@ -1176,49 +1176,53 @@ endmacro()
# Check for HIDAPI support
macro(CheckHIDAPI)
set(HAVE_HIDAPI TRUE)
- if(SDL_HIDAPI_LIBUSB)
- set(HAVE_LIBUSB FALSE)
- pkg_check_modules(LIBUSB libusb-1.0)
- if(LIBUSB_FOUND)
- check_include_file(libusb.h HAVE_LIBUSB_H ${LIBUSB_CFLAGS})
- if(HAVE_LIBUSB_H)
- set(HAVE_LIBUSB TRUE)
- set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${LIBUSB_CFLAGS}")
- if(HIDAPI_ONLY_LIBUSB)
- list(APPEND EXTRA_LIBS ${LIBUSB_LIBS})
- elseif(OS2)
- set(SDL_LIBUSB_DYNAMIC "\"usb100.dll\"")
- else()
- # libusb is loaded dynamically, so don't add it to EXTRA_LIBS
- FindLibraryAndSONAME("usb-1.0")
- if(USB_1.0_LIB)
- set(SDL_LIBUSB_DYNAMIC "\"${USB_1.0_LIB_SONAME}\"")
+ if(SDL_HIDAPI)
+ if(SDL_HIDAPI_LIBUSB)
+ set(HAVE_LIBUSB FALSE)
+ pkg_check_modules(LIBUSB libusb-1.0)
+ if(LIBUSB_FOUND)
+ check_include_file(libusb.h HAVE_LIBUSB_H ${LIBUSB_CFLAGS})
+ if(HAVE_LIBUSB_H)
+ set(HAVE_LIBUSB TRUE)
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${LIBUSB_CFLAGS}")
+ if(HIDAPI_ONLY_LIBUSB)
+ list(APPEND EXTRA_LIBS ${LIBUSB_LIBS})
+ elseif(OS2)
+ set(SDL_LIBUSB_DYNAMIC "\"usb100.dll\"")
+ else()
+ # libusb is loaded dynamically, so don't add it to EXTRA_LIBS
+ FindLibraryAndSONAME("usb-1.0")
+ if(USB_1.0_LIB)
+ set(SDL_LIBUSB_DYNAMIC "\"${USB_1.0_LIB_SONAME}\"")
+ endif()
endif()
endif()
endif()
+ if(HIDAPI_ONLY_LIBUSB AND NOT HAVE_LIBUSB)
+ set(HAVE_HIDAPI FALSE)
+ endif()
endif()
- if(HIDAPI_ONLY_LIBUSB AND NOT HAVE_LIBUSB)
- set(HAVE_HIDAPI FALSE)
- endif()
- endif()
- if(HAVE_HIDAPI)
- if(ANDROID)
- list(APPEND SOURCE_FILES ${SDL2_SOURCE_DIR}/src/hidapi/android/hid.cpp)
- endif()
- if(IOS OR TVOS)
- list(APPEND SOURCE_FILES ${SDL2_SOURCE_DIR}/src/hidapi/ios/hid.m)
- set(SDL_FRAMEWORK_COREBLUETOOTH 1)
- endif()
- set(HAVE_SDL_HIDAPI TRUE)
-
- if(SDL_JOYSTICK AND SDL_HIDAPI_JOYSTICK)
- set(SDL_JOYSTICK_HIDAPI 1)
- set(HAVE_SDL_JOYSTICK TRUE)
- set(HAVE_HIDAPI_JOYSTICK TRUE)
- file(GLOB HIDAPI_JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/hidapi/*.c)
- list(APPEND SOURCE_FILES ${HIDAPI_JOYSTICK_SOURCES})
+ if(HAVE_HIDAPI)
+ if(ANDROID)
+ list(APPEND SOURCE_FILES ${SDL2_SOURCE_DIR}/src/hidapi/android/hid.cpp)
+ endif()
+ if(IOS OR TVOS)
+ list(APPEND SOURCE_FILES ${SDL2_SOURCE_DIR}/src/hidapi/ios/hid.m)
+ set(SDL_FRAMEWORK_COREBLUETOOTH 1)
+ endif()
+ set(HAVE_SDL_HIDAPI TRUE)
+
+ if(SDL_JOYSTICK AND SDL_HIDAPI_JOYSTICK)
+ set(SDL_JOYSTICK_HIDAPI 1)
+ set(HAVE_SDL_JOYSTICK TRUE)
+ set(HAVE_HIDAPI_JOYSTICK TRUE)
+ file(GLOB HIDAPI_JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/hidapi/*.c)
+ list(APPEND SOURCE_FILES ${HIDAPI_JOYSTICK_SOURCES})
+ endif()
endif()
+ else()
+ set(SDL_HIDAPI_DISABLED 1)
endif()
endmacro()