From 81d24dd7fb73ae7fb6f7b8d19c2ea9ac5369d7d2 Mon Sep 17 00:00:00 2001 From: Steveice10 <1269164+Steveice10@users.noreply.github.com> Date: Sat, 22 Apr 2023 08:10:12 -0700 Subject: [PATCH] input_common: Allow disabling GCAdapter on platforms without libusb. (#6448) --- CMakeLists.txt | 20 ++++++++++++-------- src/input_common/CMakeLists.txt | 18 ++++++++++++------ src/input_common/main.cpp | 14 ++++++++++++++ 3 files changed, 38 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8dc1c757d..0c1910435 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,6 +34,8 @@ endif() option(ENABLE_CUBEB "Enables the cubeb audio backend" ON) +CMAKE_DEPENDENT_OPTION(ENABLE_LIBUSB "Enable libusb for GameCube Adapter support" ON "NOT IOS" OFF) + option(ENABLE_FFMPEG_AUDIO_DECODER "Enable FFmpeg audio (AAC) decoder" OFF) option(ENABLE_FFMPEG_VIDEO_DUMPER "Enable FFmpeg video dumper" OFF) @@ -224,14 +226,16 @@ if (ENABLE_QT) endif() # Ensure libusb is properly configured (based on dolphin libusb include) -if(NOT APPLE) - include(FindPkgConfig) - find_package(LibUSB) -endif() -if (NOT LIBUSB_FOUND) - add_subdirectory(externals/libusb) - set(LIBUSB_INCLUDE_DIR "") - set(LIBUSB_LIBRARIES usb) +if (ENABLE_LIBUSB) + if(NOT APPLE) + include(FindPkgConfig) + find_package(LibUSB) + endif() + if (NOT LIBUSB_FOUND) + add_subdirectory(externals/libusb) + set(LIBUSB_INCLUDE_DIR "") + set(LIBUSB_LIBRARIES usb) + endif() endif() if (ENABLE_FFMPEG) diff --git a/src/input_common/CMakeLists.txt b/src/input_common/CMakeLists.txt index d03284a23..246e2652b 100644 --- a/src/input_common/CMakeLists.txt +++ b/src/input_common/CMakeLists.txt @@ -1,10 +1,6 @@ add_library(input_common STATIC analog_from_button.cpp analog_from_button.h - gcadapter/gc_adapter.cpp - gcadapter/gc_adapter.h - gcadapter/gc_poller.cpp - gcadapter/gc_poller.h keyboard.cpp keyboard.h main.cpp @@ -33,10 +29,20 @@ if(ENABLE_SDL2) target_compile_definitions(input_common PRIVATE HAVE_SDL2) endif() +if(ENABLE_LIBUSB) + target_sources(input_common PRIVATE + gcadapter/gc_adapter.cpp + gcadapter/gc_adapter.h + gcadapter/gc_poller.cpp + gcadapter/gc_poller.h + ) + target_include_directories(input_common PRIVATE ${LIBUSB_INCLUDE_DIR}) + target_link_libraries(input_common PRIVATE ${LIBUSB_LIBRARIES}) + add_definitions(-DENABLE_GCADAPTER) +endif() + create_target_directory_groups(input_common) target_link_libraries(input_common PUBLIC core PRIVATE common ${Boost_LIBRARIES}) -target_include_directories(input_common PRIVATE ${LIBUSB_INCLUDE_DIR}) -target_link_libraries(input_common PUBLIC ${LIBUSB_LIBRARIES}) set_target_properties(input_common PROPERTIES INTERPROCEDURAL_OPTIMIZATION ${ENABLE_LTO}) if (CITRA_USE_PRECOMPILED_HEADERS) diff --git a/src/input_common/main.cpp b/src/input_common/main.cpp index 26cfc8e61..bcff11d20 100644 --- a/src/input_common/main.cpp +++ b/src/input_common/main.cpp @@ -6,8 +6,10 @@ #include #include "common/param_package.h" #include "input_common/analog_from_button.h" +#ifdef ENABLE_GCADAPTER #include "input_common/gcadapter/gc_adapter.h" #include "input_common/gcadapter/gc_poller.h" +#endif #include "input_common/keyboard.h" #include "input_common/main.h" #include "input_common/motion_emu.h" @@ -18,20 +20,24 @@ namespace InputCommon { +#ifdef ENABLE_GCADAPTER std::shared_ptr gcbuttons; std::shared_ptr gcanalog; std::shared_ptr gcadapter; +#endif static std::shared_ptr keyboard; static std::shared_ptr motion_emu; static std::unique_ptr udp; static std::unique_ptr sdl; void Init() { +#ifdef ENABLE_GCADAPTER gcadapter = std::make_shared(); gcbuttons = std::make_shared(gcadapter); Input::RegisterFactory("gcpad", gcbuttons); gcanalog = std::make_shared(gcadapter); Input::RegisterFactory("gcpad", gcanalog); +#endif keyboard = std::make_shared(); Input::RegisterFactory("keyboard", keyboard); Input::RegisterFactory("analog_from_button", @@ -47,10 +53,12 @@ void Init() { } void Shutdown() { +#ifdef ENABLE_GCADAPTER Input::UnregisterFactory("gcpad"); Input::UnregisterFactory("gcpad"); gcbuttons.reset(); gcanalog.reset(); +#endif Input::UnregisterFactory("keyboard"); keyboard.reset(); Input::UnregisterFactory("analog_from_button"); @@ -99,9 +107,11 @@ Common::ParamPackage GetControllerButtonBinds(const Common::ParamPackage& params return dynamic_cast(sdl.get())->GetSDLControllerButtonBindByGUID( params.Get("guid", "0"), params.Get("port", 0), native_button); } +#ifdef ENABLE_GCADAPTER if (engine == "gcpad") { return gcbuttons->GetGcTo3DSMappedButton(params.Get("port", 0), native_button); } +#endif return {}; } @@ -112,9 +122,11 @@ Common::ParamPackage GetControllerAnalogBinds(const Common::ParamPackage& params return dynamic_cast(sdl.get())->GetSDLControllerAnalogBindByGUID( params.Get("guid", "0"), params.Get("port", 0), native_analog); } +#ifdef ENABLE_GCADAPTER if (engine == "gcpad") { return gcanalog->GetGcTo3DSMappedAnalog(params.Get("port", 0), native_analog); } +#endif return {}; } @@ -133,6 +145,7 @@ std::vector> GetPollers(DeviceType type) { #ifdef HAVE_SDL2 pollers = sdl->GetPollers(type); #endif +#ifdef ENABLE_GCADAPTER switch (type) { case DeviceType::Analog: pollers.push_back(std::make_unique(*gcanalog)); @@ -143,6 +156,7 @@ std::vector> GetPollers(DeviceType type) { default: break; } +#endif return pollers; }