From ee0d79ef64c807648f8d652315a0192fc586e48e Mon Sep 17 00:00:00 2001 From: emiyl Date: Mon, 20 Apr 2026 21:58:07 +0100 Subject: [PATCH] add ENABLE_LIBUSB option --- CMakeLists.txt | 7 ++++ src/CMakeLists.txt | 20 +++++++---- src/Cafe/CMakeLists.txt | 33 +++++++++++-------- .../OS/libs/nsyshid/AttachDefaultBackends.cpp | 4 +++ src/Cafe/OS/libs/nsyshid/BackendEmulated.cpp | 2 ++ src/Cafe/OS/libs/nsyshid/SkylanderXbox360.cpp | 2 ++ src/Cafe/OS/libs/nsyshid/SkylanderXbox360.h | 4 +++ src/input/CMakeLists.txt | 13 +++++--- src/input/ControllerFactory.cpp | 4 +-- src/input/InputManager.cpp | 2 +- src/input/api/GameCube/GameCubeController.cpp | 2 +- src/input/api/GameCube/GameCubeController.h | 2 +- .../GameCube/GameCubeControllerProvider.cpp | 2 +- .../api/GameCube/GameCubeControllerProvider.h | 5 +-- src/util/CMakeLists.txt | 9 +++-- 15 files changed, 77 insertions(+), 34 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a00879fe..38630217 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -128,6 +128,13 @@ endif() option(ENABLE_HIDAPI "Build with HIDAPI" ON) option(ENABLE_SDL "Enables the SDLController backend" ON) +option(ENABLE_LIBUSB "Build with libusb support" ON) + +if (ENABLE_LIBUSB) + add_compile_definitions(HAS_LIBUSB=1) +else() + add_compile_definitions(HAS_LIBUSB=0) +endif() # audio backends if (WIN32) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b7fd67fe..e7723e50 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -113,10 +113,12 @@ if (MACOS_BUNDLE) COMMAND ${CMAKE_COMMAND} ARGS -E copy_directory "${CMAKE_SOURCE_DIR}/bin/${folder}" "${CMAKE_SOURCE_DIR}/bin/${OUTPUT_NAME}.app/Contents/SharedSupport/${folder}") endforeach(folder) - if(CMAKE_BUILD_TYPE STREQUAL "Debug") - set(LIBUSB_PATH "${CMAKE_BINARY_DIR}/vcpkg_installed/${VCPKG_TARGET_TRIPLET}/debug/lib/libusb-1.0.0.dylib") - else() - set(LIBUSB_PATH "${CMAKE_BINARY_DIR}/vcpkg_installed/${VCPKG_TARGET_TRIPLET}/lib/libusb-1.0.0.dylib") + if (ENABLE_LIBUSB) + if(CMAKE_BUILD_TYPE STREQUAL "Debug") + set(LIBUSB_PATH "${CMAKE_BINARY_DIR}/vcpkg_installed/${VCPKG_TARGET_TRIPLET}/debug/lib/libusb-1.0.0.dylib") + else() + set(LIBUSB_PATH "${CMAKE_BINARY_DIR}/vcpkg_installed/${VCPKG_TARGET_TRIPLET}/lib/libusb-1.0.0.dylib") + endif() endif() if (EXISTS "/usr/local/lib/libMoltenVK.dylib") @@ -129,10 +131,14 @@ if (MACOS_BUNDLE) add_custom_command (TARGET CemuBin POST_BUILD COMMAND ${CMAKE_COMMAND} ARGS -E copy "${MOLTENVK_PATH}" "${CMAKE_SOURCE_DIR}/bin/${OUTPUT_NAME}.app/Contents/Frameworks/libMoltenVK.dylib" - COMMAND ${CMAKE_COMMAND} ARGS -E copy "${LIBUSB_PATH}" "${CMAKE_SOURCE_DIR}/bin/${OUTPUT_NAME}.app/Contents/Frameworks/libusb-1.0.0.dylib" COMMAND ${CMAKE_COMMAND} ARGS -E copy "${CMAKE_SOURCE_DIR}/src/resource/update.sh" "${CMAKE_SOURCE_DIR}/bin/${OUTPUT_NAME}.app/Contents/MacOS/update.sh" - COMMAND bash -c "install_name_tool -add_rpath @executable_path/../Frameworks ${CMAKE_SOURCE_DIR}/bin/${OUTPUT_NAME}.app/Contents/MacOS/${OUTPUT_NAME}" - COMMAND install_name_tool -change @rpath/libusb-1.0.0.dylib @executable_path/../Frameworks/libusb-1.0.0.dylib ${CMAKE_SOURCE_DIR}/bin/${OUTPUT_NAME}.app/Contents/MacOS/${OUTPUT_NAME}) + COMMAND bash -c "install_name_tool -add_rpath @executable_path/../Frameworks ${CMAKE_SOURCE_DIR}/bin/${OUTPUT_NAME}.app/Contents/MacOS/${OUTPUT_NAME}") + + if (ENABLE_LIBUSB) + add_custom_command (TARGET CemuBin POST_BUILD + COMMAND ${CMAKE_COMMAND} ARGS -E copy "${LIBUSB_PATH}" "${CMAKE_SOURCE_DIR}/bin/${OUTPUT_NAME}.app/Contents/Frameworks/libusb-1.0.0.dylib" + COMMAND install_name_tool -change @rpath/libusb-1.0.0.dylib @executable_path/../Frameworks/libusb-1.0.0.dylib ${CMAKE_SOURCE_DIR}/bin/${OUTPUT_NAME}.app/Contents/MacOS/${OUTPUT_NAME}) + endif() else() if(APPLE) find_library(MOLTENVK_LIBRARY diff --git a/src/Cafe/CMakeLists.txt b/src/Cafe/CMakeLists.txt index 78a8cce0..e5e41143 100644 --- a/src/Cafe/CMakeLists.txt +++ b/src/Cafe/CMakeLists.txt @@ -471,8 +471,6 @@ add_library(CemuCafe OS/libs/nsyshid/Whitelist.h OS/libs/nsyshid/BackendEmulated.cpp OS/libs/nsyshid/BackendEmulated.h - OS/libs/nsyshid/BackendLibusb.cpp - OS/libs/nsyshid/BackendLibusb.h OS/libs/nsyshid/Dimensions.cpp OS/libs/nsyshid/Dimensions.h OS/libs/nsyshid/Infinity.cpp @@ -617,6 +615,13 @@ set_property(TARGET CemuCafe PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$(); @@ -15,6 +18,7 @@ namespace nsyshid::backend AttachBackend(backendLibusb); } } + #endif // add emulated backend { auto backendEmulated = std::make_shared(); diff --git a/src/Cafe/OS/libs/nsyshid/BackendEmulated.cpp b/src/Cafe/OS/libs/nsyshid/BackendEmulated.cpp index a5eb95c1..93ea8e5a 100644 --- a/src/Cafe/OS/libs/nsyshid/BackendEmulated.cpp +++ b/src/Cafe/OS/libs/nsyshid/BackendEmulated.cpp @@ -29,6 +29,7 @@ namespace nsyshid::backend::emulated auto device = std::make_shared(); AttachDevice(device); } + #if HAS_LIBUSB else if (auto usb_portal = FindDeviceById(0x1430, 0x1F17)) { cemuLog_logDebug(LogType::Force, "Attaching Xbox 360 Portal"); @@ -36,6 +37,7 @@ namespace nsyshid::backend::emulated auto device = std::make_shared(usb_portal); AttachDevice(device); } + #endif if (GetConfig().emulated_usb_devices.emulate_infinity_base && !FindDeviceById(0x0E6F, 0x0129)) { cemuLog_logDebug(LogType::Force, "Attaching Emulated Base"); diff --git a/src/Cafe/OS/libs/nsyshid/SkylanderXbox360.cpp b/src/Cafe/OS/libs/nsyshid/SkylanderXbox360.cpp index eba8ff9e..2227ff17 100644 --- a/src/Cafe/OS/libs/nsyshid/SkylanderXbox360.cpp +++ b/src/Cafe/OS/libs/nsyshid/SkylanderXbox360.cpp @@ -2,6 +2,7 @@ namespace nsyshid { + #if HAS_LIBUSB SkylanderXbox360PortalLibusb::SkylanderXbox360PortalLibusb(std::shared_ptr usbPortal) : Device(0x1430, 0x0150, 1, 2, 0) { @@ -157,4 +158,5 @@ namespace nsyshid { return true; } + #endif } // namespace nsyshid \ No newline at end of file diff --git a/src/Cafe/OS/libs/nsyshid/SkylanderXbox360.h b/src/Cafe/OS/libs/nsyshid/SkylanderXbox360.h index 901c63f9..21476255 100644 --- a/src/Cafe/OS/libs/nsyshid/SkylanderXbox360.h +++ b/src/Cafe/OS/libs/nsyshid/SkylanderXbox360.h @@ -1,11 +1,14 @@ #pragma once #include "nsyshid.h" +#if HAS_LIBUSB #include "BackendLibusb.h" #include "g721/g721.h" +#endif namespace nsyshid { + #if HAS_LIBUSB class SkylanderXbox360PortalLibusb final : public Device { public: SkylanderXbox360PortalLibusb(std::shared_ptr usbPortal); @@ -40,6 +43,7 @@ namespace nsyshid bool m_IsOpened; struct g72x_state m_state; }; + #endif constexpr uint8 XBOX_DATA_HEADER[] = { 0x0B, 0x14 }; constexpr uint8 XBOX_AUDIO_DATA_HEADER[] = { 0x0B, 0x17 }; diff --git a/src/input/CMakeLists.txt b/src/input/CMakeLists.txt index d24a5ca0..4e5a990f 100644 --- a/src/input/CMakeLists.txt +++ b/src/input/CMakeLists.txt @@ -23,10 +23,6 @@ add_library(CemuInput api/Keyboard/KeyboardControllerProvider.cpp api/Keyboard/KeyboardController.cpp api/Keyboard/KeyboardController.h - api/GameCube/GameCubeController.cpp - api/GameCube/GameCubeControllerProvider.h - api/GameCube/GameCubeControllerProvider.cpp - api/GameCube/GameCubeController.h emulated/ProController.cpp emulated/EmulatedController.h emulated/EmulatedController.cpp @@ -45,6 +41,15 @@ set_property(TARGET CemuInput PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$(index); } #endif -#if HAS_GAMECUBE +#if defined(HAS_GAMECUBE) && HAS_GAMECUBE && HAS_LIBUSB case InputAPI::GameCube: { const auto index = uuid.find_first_of('_'); @@ -165,7 +165,7 @@ ControllerProviderPtr ControllerFactory::CreateControllerProvider(InputAPI::Type } #endif -#if HAS_GAMECUBE +#if defined(HAS_GAMECUBE) && HAS_GAMECUBE && HAS_LIBUSB case InputAPI::GameCube: return std::make_shared(); #endif diff --git a/src/input/InputManager.cpp b/src/input/InputManager.cpp index 64b238fc..d5ef26dd 100644 --- a/src/input/InputManager.cpp +++ b/src/input/InputManager.cpp @@ -40,7 +40,7 @@ InputManager::InputManager() #if HAS_DSU create_provider(); #endif -#if HAS_GAMECUBE +#if defined(HAS_GAMECUBE) && HAS_GAMECUBE && HAS_LIBUSB create_provider(); #endif #if HAS_WIIMOTE diff --git a/src/input/api/GameCube/GameCubeController.cpp b/src/input/api/GameCube/GameCubeController.cpp index 538e6241..76c27cbe 100644 --- a/src/input/api/GameCube/GameCubeController.cpp +++ b/src/input/api/GameCube/GameCubeController.cpp @@ -1,6 +1,6 @@ #include "input/api/GameCube/GameCubeController.h" -#ifdef HAS_GAMECUBE +#if defined(HAS_GAMECUBE) && HAS_GAMECUBE && HAS_LIBUSB GameCubeController::GameCubeController(uint32 adapter, uint32 index) : base_type(fmt::format("{}_{}", adapter, index), fmt::format("Controller {}", index + 1)), m_adapter(adapter), diff --git a/src/input/api/GameCube/GameCubeController.h b/src/input/api/GameCube/GameCubeController.h index fd7fe237..fb97944e 100644 --- a/src/input/api/GameCube/GameCubeController.h +++ b/src/input/api/GameCube/GameCubeController.h @@ -3,7 +3,7 @@ #include "input/api/Controller.h" #include "input/api/GameCube/GameCubeControllerProvider.h" -#ifdef HAS_GAMECUBE +#if defined(HAS_GAMECUBE) && HAS_GAMECUBE && HAS_LIBUSB class GameCubeController : public Controller { diff --git a/src/input/api/GameCube/GameCubeControllerProvider.cpp b/src/input/api/GameCube/GameCubeControllerProvider.cpp index f3a2f20d..57b53272 100644 --- a/src/input/api/GameCube/GameCubeControllerProvider.cpp +++ b/src/input/api/GameCube/GameCubeControllerProvider.cpp @@ -2,7 +2,7 @@ #include "input/api/GameCube/GameCubeController.h" #include "util/libusbWrapper/libusbWrapper.h" -#if HAS_GAMECUBE +#if defined(HAS_GAMECUBE) && HAS_GAMECUBE && HAS_LIBUSB constexpr uint16_t kVendorId = 0x57e, kProductId = 0x337; diff --git a/src/input/api/GameCube/GameCubeControllerProvider.h b/src/input/api/GameCube/GameCubeControllerProvider.h index 08f847a0..c7ca94be 100644 --- a/src/input/api/GameCube/GameCubeControllerProvider.h +++ b/src/input/api/GameCube/GameCubeControllerProvider.h @@ -1,9 +1,10 @@ #pragma once -#include "util/libusbWrapper/libusbWrapper.h" #include "input/api/ControllerProvider.h" -#ifdef HAS_GAMECUBE +#if defined(HAS_GAMECUBE) && HAS_GAMECUBE && HAS_LIBUSB + +#include "util/libusbWrapper/libusbWrapper.h" class GameCubeControllerProvider : public ControllerProviderBase { diff --git a/src/util/CMakeLists.txt b/src/util/CMakeLists.txt index 390e9c10..c170adc5 100644 --- a/src/util/CMakeLists.txt +++ b/src/util/CMakeLists.txt @@ -43,8 +43,6 @@ add_library(CemuUtil ImageWriter/tga.h IniParser/IniParser.cpp IniParser/IniParser.h - libusbWrapper/libusbWrapper.cpp - libusbWrapper/libusbWrapper.h math/glm.h math/quaternion.h math/vector2.h @@ -91,6 +89,13 @@ set_property(TARGET CemuUtil PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$