yuzu-emu
/
yuzu
Archived
1
0
Fork 0

cmake: General improvements to libusb linking

Delegates libusb external communication to externals/CMakeLists.txt
Ensures an interface library `usb` for every pathway
input_common just links to the `usb` library now
externals/libusb/CMakeLists.txt sets variables to override SDL2's libusb
finding
Other minor cleanup
This commit is contained in:
lat9nq 2021-06-03 03:49:35 -04:00
parent 55dd027115
commit ddc47e6df8
4 changed files with 31 additions and 17 deletions

View File

@ -422,18 +422,22 @@ elseif (TARGET Boost::boost)
endif() endif()
# Ensure libusb is properly configured (based on dolphin libusb include) # Ensure libusb is properly configured (based on dolphin libusb include)
if(NOT APPLE) if(NOT APPLE AND NOT YUZU_USE_BUNDLED_LIBUSB)
include(FindPkgConfig) include(FindPkgConfig)
if (PKG_CONFIG_FOUND) if (PKG_CONFIG_FOUND)
pkg_check_modules(LIBUSB QUIET libusb-1.0>=1.0.24) pkg_check_modules(LIBUSB QUIET libusb-1.0>=1.0.24)
else() else()
find_package(LibUSB) find_package(LibUSB)
endif() endif()
endif()
if (NOT LIBUSB_FOUND OR YUZU_USE_BUNDLED_LIBUSB) if (NOT LIBUSB_FOUND)
add_subdirectory(externals/libusb) message(WARNING "libusb not found, falling back to externals")
set(LIBUSB_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/externals/libusb/libusb/libusb") set(YUZU_USE_BUNDLED_LIBUSB ON)
set(LIBUSB_LIBRARIES usb) else()
add_library(usb INTERFACE)
target_include_directories(usb INTERFACE "${LIBUSB_INCLUDE_DIRS}")
target_link_libraries(usb INTERFACE "${LIBUSB_LIBRARIES}")
endif()
endif() endif()
# List of all FFmpeg components required # List of all FFmpeg components required

View File

@ -45,6 +45,11 @@ target_include_directories(microprofile INTERFACE ./microprofile)
add_library(unicorn-headers INTERFACE) add_library(unicorn-headers INTERFACE)
target_include_directories(unicorn-headers INTERFACE ./unicorn/include) target_include_directories(unicorn-headers INTERFACE ./unicorn/include)
# libusb
if (NOT LIBUSB_FOUND OR YUZU_USE_BUNDLED_LIBUSB)
add_subdirectory(libusb)
endif()
# SDL2 # SDL2
if (NOT SDL2_FOUND AND ENABLE_SDL2) if (NOT SDL2_FOUND AND ENABLE_SDL2)
if (NOT WIN32) if (NOT WIN32)

View File

@ -1,4 +1,7 @@
if (MINGW OR NOT WIN32) set(LIBUSB_FOUND ON CACHE BOOL "libusb is present" FORCE)
set(LIBUSB_VERSION "1.0.24" CACHE STRING "libusb version string" FORCE)
if (MINGW OR (${CMAKE_SYSTEM_NAME} MATCHES "Linux"))
# GNU toolchains for some reason doesn't work with the later half of this CMakeLists after # GNU toolchains for some reason doesn't work with the later half of this CMakeLists after
# updating to 1.0.24, so we do it the old-fashioned way for now. # updating to 1.0.24, so we do it the old-fashioned way for now.
@ -21,17 +24,19 @@ if (MINGW OR NOT WIN32)
set(LIBUSB_MAKEFILE "${LIBUSB_PREFIX}/Makefile") set(LIBUSB_MAKEFILE "${LIBUSB_PREFIX}/Makefile")
if (MINGW) if (MINGW)
set(LIBUSB_LIBRARY "${LIBUSB_PREFIX}/libusb/.libs/libusb-1.0.dll.a") set(LIBUSB_LIBRARIES "${LIBUSB_PREFIX}/libusb/.libs/libusb-1.0.dll.a" CACHE PATH "libusb library path" FORCE)
set(LIBUSB_SHARED_LIBRARY "${LIBUSB_PREFIX}/libusb/.libs/libusb-1.0.dll") set(LIBUSB_SHARED_LIBRARY "${LIBUSB_PREFIX}/libusb/.libs/libusb-1.0.dll")
set(LIBUSB_SHARED_LIBRARY_DEST "${CMAKE_BINARY_DIR}/bin/libusb-1.0.dll") set(LIBUSB_SHARED_LIBRARY_DEST "${CMAKE_BINARY_DIR}/bin/libusb-1.0.dll")
set(LIBUSB_CONFIGURE_ARGS --host=x86_64-w64-mingw32 --build=x86_64-windows) set(LIBUSB_CONFIGURE_ARGS --host=x86_64-w64-mingw32 --build=x86_64-windows)
else() else()
set(LIBUSB_LIBRARY "${LIBUSB_PREFIX}/libusb/.libs/libusb-1.0.so") set(LIBUSB_LIBRARIES "${LIBUSB_PREFIX}/libusb/.libs/libusb-1.0.so" CACHE PATH "libusb library path" FORCE)
set(LIBUSB_SHARED_LIBRARY "${LIBUSB_LIBRARY}") set(LIBUSB_SHARED_LIBRARY "${LIBUSB_LIBRARIES}")
set(LIBUSB_SHARED_LIBRARY_DEST "${CMAKE_BINARY_DIR}/bin/libusb-1.0.so") set(LIBUSB_SHARED_LIBRARY_DEST "${CMAKE_BINARY_DIR}/bin/libusb-1.0.so")
endif() endif()
set(LIBUSB_INCLUDE_DIRS "${LIBUSB_SRC_DIR}/libusb" CACHE PATH "libusb headers path" FORCE)
# Causes "externals/libusb/libusb/libusb/os/windows_winusb.c:1427:2: error: conversion to non-scalar type requested", so cannot statically link it for now. # Causes "externals/libusb/libusb/libusb/os/windows_winusb.c:1427:2: error: conversion to non-scalar type requested", so cannot statically link it for now.
# set(LIBUSB_CFLAGS "-DGUID_DEVINTERFACE_USB_DEVICE=\\(GUID\\){0xA5DCBF10,0x6530,0x11D2,{0x90,0x1F,0x00,0xC0,0x4F,0xB9,0x51,0xED}}") # set(LIBUSB_CFLAGS "-DGUID_DEVINTERFACE_USB_DEVICE=\\(GUID\\){0xA5DCBF10,0x6530,0x11D2,{0x90,0x1F,0x00,0xC0,0x4F,0xB9,0x51,0xED}}")
@ -39,7 +44,7 @@ if (MINGW OR NOT WIN32)
add_custom_command( add_custom_command(
OUTPUT OUTPUT
"${LIBUSB_LIBRARY}" "${LIBUSB_LIBRARIES}"
COMMAND COMMAND
make make
WORKING_DIRECTORY WORKING_DIRECTORY
@ -77,13 +82,14 @@ if (MINGW OR NOT WIN32)
add_custom_target(usb-bootstrap DEPENDS "${LIBUSB_CONFIGURE}") add_custom_target(usb-bootstrap DEPENDS "${LIBUSB_CONFIGURE}")
add_custom_target(usb-configure DEPENDS "${LIBUSB_MAKEFILE}" usb-bootstrap) add_custom_target(usb-configure DEPENDS "${LIBUSB_MAKEFILE}" usb-bootstrap)
add_custom_target(usb-build ALL DEPENDS "${LIBUSB_LIBRARY}" usb-configure) add_custom_target(usb-build ALL DEPENDS "${LIBUSB_LIBRARIES}" usb-configure)
# Workaround since static linking didn't work out -- We need to copy the DLL to the bin directory # Workaround since static linking didn't work out -- We need to copy the DLL to the bin directory
add_custom_target(usb-copy ALL DEPENDS "${LIBUSB_SHARED_LIBRARY_DEST}" usb-build) add_custom_target(usb-copy ALL DEPENDS "${LIBUSB_SHARED_LIBRARY_DEST}" usb-build)
add_library(usb INTERFACE) add_library(usb INTERFACE)
add_dependencies(usb usb-copy) add_dependencies(usb usb-copy)
target_link_libraries(usb INTERFACE "${LIBUSB_LIBRARY}") target_link_libraries(usb INTERFACE "${LIBUSB_LIBRARIES}")
target_include_directories(usb INTERFACE "${LIBUSB_INCLUDE_DIRS}")
if (${CMAKE_SYSTEM_NAME} MATCHES "Linux") if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
find_package(Libudev QUIET) find_package(Libudev QUIET)
@ -92,7 +98,7 @@ if (MINGW OR NOT WIN32)
target_include_directories(usb INTERFACE "${LIBUDEV_INCLUDE_DIR}") target_include_directories(usb INTERFACE "${LIBUDEV_INCLUDE_DIR}")
endif() endif()
endif() endif()
else() # MINGW OR NOT WIN32 else() # MINGW OR (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
# Ensure libusb compiles with UTF-8 encoding on MSVC # Ensure libusb compiles with UTF-8 encoding on MSVC
if(MSVC) if(MSVC)
add_compile_options(/utf-8) add_compile_options(/utf-8)
@ -248,4 +254,4 @@ else() # MINGW OR NOT WIN32
configure_file(config.h.in config.h) configure_file(config.h.in config.h)
endif() # MINGW endif() # MINGW OR (${CMAKE_SYSTEM_NAME} MATCHES "Linux")

View File

@ -71,8 +71,7 @@ if (ENABLE_SDL2)
target_compile_definitions(input_common PRIVATE HAVE_SDL2) target_compile_definitions(input_common PRIVATE HAVE_SDL2)
endif() endif()
target_include_directories(input_common SYSTEM PRIVATE ${LIBUSB_INCLUDE_DIR}) target_link_libraries(input_common PRIVATE usb)
target_link_libraries(input_common PRIVATE ${LIBUSB_LIBRARIES})
create_target_directory_groups(input_common) create_target_directory_groups(input_common)
target_link_libraries(input_common PUBLIC core PRIVATE common Boost::boost) target_link_libraries(input_common PUBLIC core PRIVATE common Boost::boost)