diff --git a/BUILD.md b/BUILD.md index a23ea66a..458ffba1 100644 --- a/BUILD.md +++ b/BUILD.md @@ -250,6 +250,7 @@ Example usage: `cmake -S . -B build -DCMAKE_BUILD_TYPE=release -DENABLE_SDL=ON - | ENABLE_VCPKG | | Use VCPKG package manager to obtain dependencies | ON | | | ENABLE_VULKAN | | Enable the Vulkan graphics backend | ON | | | ENABLE_WXWIDGETS | | Enable wxWidgets UI | ON | Currently required | +| ENABLE_LIBUSB | | Enable libusb | ON | | ### Windows | Flag | Description | Default | Note | diff --git a/CMakeLists.txt b/CMakeLists.txt index 7b1e86d5..f04ab816 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -132,6 +132,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) +else() + add_compile_definitions(HAS_LIBUSB) +endif() # audio backends if (WIN32) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 291cc612..b266a6c6 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -119,10 +119,12 @@ if (MACOS_BUNDLE) COMMAND ${CMAKE_COMMAND} ARGS -E copy_directory "${CMAKE_SOURCE_DIR}/bin/${folder}" "$/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") @@ -142,9 +144,11 @@ if (MACOS_BUNDLE) COMMAND ${CMAKE_COMMAND} -E copy "${MOLTENVK_PATH}" "${FRAMEWORKS_DIR}/libMoltenVK.dylib" - COMMAND ${CMAKE_COMMAND} -E copy - "${LIBUSB_PATH}" - "${FRAMEWORKS_DIR}/libusb-1.0.0.dylib" + if (ENABLE_LIBUSB) + COMMAND ${CMAKE_COMMAND} -E copy + "${LIBUSB_PATH}" + "${FRAMEWORKS_DIR}/libusb-1.0.0.dylib" + endif() COMMAND ${CMAKE_COMMAND} -E copy "${UPDATE_SH_PATH}" "${RESOURCES_DIR}/update.sh" @@ -157,12 +161,14 @@ if (MACOS_BUNDLE) INSTALL_RPATH "@executable_path/../Frameworks" ) - add_custom_command(TARGET CemuBin POST_BUILD - COMMAND install_name_tool - -change @rpath/libusb-1.0.0.dylib - @executable_path/../Frameworks/libusb-1.0.0.dylib - "$" - ) + if (ENABLE_LIBUSB) + add_custom_command(TARGET CemuBin POST_BUILD + COMMAND install_name_tool + -change @rpath/libusb-1.0.0.dylib + @executable_path/../Frameworks/libusb-1.0.0.dylib + "$" + ) + 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..e6b9fd9d 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); } + #ifdef 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..0c528094 100644 --- a/src/Cafe/OS/libs/nsyshid/SkylanderXbox360.cpp +++ b/src/Cafe/OS/libs/nsyshid/SkylanderXbox360.cpp @@ -2,6 +2,7 @@ namespace nsyshid { + #ifdef 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..b92cffcc 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" +#ifdef HAS_LIBUSB #include "BackendLibusb.h" #include "g721/g721.h" +#endif namespace nsyshid { + #ifdef 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 && defined(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 && defined(HAS_LIBUSB) case InputAPI::GameCube: return std::make_shared(); #endif diff --git a/src/input/InputManager.cpp b/src/input/InputManager.cpp index 64b238fc..5b228414 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 && defined(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..910a513e 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 && defined(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..d027eee0 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 && defined(HAS_LIBUSB) class GameCubeController : public Controller { diff --git a/src/input/api/GameCube/GameCubeControllerProvider.cpp b/src/input/api/GameCube/GameCubeControllerProvider.cpp index f3a2f20d..60689568 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 && defined(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..d4e19d92 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 && defined(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$<$