Skip to content

Commit 5573eea

Browse files
committed
add LIBUSB_ENABLE_WINDOWS_HOTPLUG option in windows
1 parent 000e06e commit 5573eea

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ function(generate_config_file)
7070
set(ENABLE_DEBUG_LOGGING ${LIBUSB_ENABLE_DEBUG_LOGGING})
7171
endif()
7272

73+
if(WIN32 AND LIBUSB_ENABLE_WINDOWS_HOTPLUG)
74+
set(LIBUSB_WINDOWS_HOTPLUG 1)
75+
endif()
76+
7377
if(CMAKE_C_COMPILER_ID MATCHES "Clang" OR CMAKE_C_COMPILER_ID STREQUAL "GNU")
7478
check_c_compiler_flag("-fvisibility=hidden" HAVE_VISIBILITY)
7579
endif()
@@ -104,6 +108,10 @@ if(CMAKE_SYSTEM_NAME MATCHES "Linux")
104108
option(LIBUSB_ENABLE_UDEV "Enable udev backend for device enumeration" ON)
105109
endif()
106110

111+
if(WIN32)
112+
option(LIBUSB_ENABLE_WINDOWS_HOTPLUG "Enable Windows hotplug support" OFF)
113+
endif()
114+
107115
set(LIBUSB_GEN_INCLUDES "${CMAKE_CURRENT_BINARY_DIR}/gen_include")
108116
generate_config_file()
109117

@@ -160,6 +168,13 @@ if(WIN32)
160168
)
161169
target_compile_definitions(usb-1.0 PRIVATE $<$<C_COMPILER_ID:MSVC>:_CRT_SECURE_NO_WARNINGS=1>)
162170
target_link_libraries(usb-1.0 PRIVATE windowsapp)
171+
if(LIBUSB_ENABLE_WINDOWS_HOTPLUG)
172+
target_sources(usb-1.0 PRIVATE
173+
"${LIBUSB_ROOT}/os/windows_hotplug.c"
174+
"${LIBUSB_ROOT}/os/windows_hotplug.h"
175+
)
176+
target_compile_definitions(usb-1.0 PRIVATE LIBUSB_WINDOWS_HOTPLUG=1)
177+
endif()
163178
set_target_properties(usb-1.0 PROPERTIES UNITY_BUILD OFF)
164179
else()
165180
# common POSIX/non-Windows sources

config.h.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@
5252
/* #define to 1 if compiling for a Windows platform. */
5353
#cmakedefine PLATFORM_WINDOWS 1
5454

55+
/* #define to 1 to enable Windows hotplug support. */
56+
#cmakedefine LIBUSB_WINDOWS_HOTPLUG 1
57+
5558

5659
#if defined(__GNUC__)
5760
#define PRINTF_FORMAT(a, b) __attribute__ ((format (__printf__, a, b)))

0 commit comments

Comments
 (0)