From eb443dcd64c5ceab11b3181483d75ff6e23b89ab Mon Sep 17 00:00:00 2001 From: Ihor Dutchak Date: Mon, 23 Mar 2026 13:58:10 +0200 Subject: [PATCH] Workaround to fix compilation with older Windows SDK - as a backward compatibility Fixes: #41 --- CMakeLists.txt | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ecaa95e..9357e49 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,7 +22,7 @@ if(EMSCRIPTEN) enable_language(CXX) endif() -message("Building usb-1.0 for: ${CMAKE_SYSTEM_NAME}") +message(STATUS "Building usb-1.0 for: ${CMAKE_SYSTEM_NAME}") # This function generates all the local variables what end up getting written to config. # We use a function as any vars set in this context don't mess with the rest of the file. @@ -192,7 +192,19 @@ if(WIN32) $<$:${LIBUSB_ROOT}/libusb-1.0.rc> ) target_compile_definitions(usb-1.0 PRIVATE $<$:_CRT_SECURE_NO_WARNINGS=1>) - target_link_libraries(usb-1.0 PRIVATE windowsapp) + + include(CheckCSourceCompiles) + set(CMAKE_REQUIRED_LIBRARIES windowsapp) + check_c_source_compiles("int main(void) { return 0; }" HAVE_WINDOWSAPP_LIB) + unset(CMAKE_REQUIRED_LIBRARIES) + + if(HAVE_WINDOWSAPP_LIB) + target_link_libraries(usb-1.0 PRIVATE windowsapp) + else() + message(WARNING "You're targeting old no longer supported version of Windows SDK, consider building against a newer SDK to get better support for Windows 10/11 and avoid vulnerabilities in older SDKs") + target_link_libraries(usb-1.0 PRIVATE kernel32 user32) + endif() + if(LIBUSB_ENABLE_WINDOWS_HOTPLUG) target_sources(usb-1.0 PRIVATE "${LIBUSB_ROOT}/os/windows_hotplug.c"