diff options
| author | 2021-06-03 03:49:35 -0400 | |
|---|---|---|
| committer | 2021-06-03 03:49:35 -0400 | |
| commit | ddc47e6df8cd9e06d799933f67e75ba6f8952acd (patch) | |
| tree | f1fd486d62f031cc4606c42dab2fea60d3af5fd2 | |
| parent | cmake: Use autotools to build libusb generally for GNU (diff) | |
| download | yuzu-ddc47e6df8cd9e06d799933f67e75ba6f8952acd.tar.gz yuzu-ddc47e6df8cd9e06d799933f67e75ba6f8952acd.tar.xz yuzu-ddc47e6df8cd9e06d799933f67e75ba6f8952acd.zip | |
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
| -rw-r--r-- | CMakeLists.txt | 16 | ||||
| -rw-r--r-- | externals/CMakeLists.txt | 5 | ||||
| -rw-r--r-- | externals/libusb/CMakeLists.txt | 24 | ||||
| -rw-r--r-- | src/input_common/CMakeLists.txt | 3 |
4 files changed, 31 insertions, 17 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index c07be6f57..68d9e5f9d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt | |||
| @@ -422,18 +422,22 @@ elseif (TARGET Boost::boost) | |||
| 422 | endif() | 422 | endif() |
| 423 | 423 | ||
| 424 | # Ensure libusb is properly configured (based on dolphin libusb include) | 424 | # Ensure libusb is properly configured (based on dolphin libusb include) |
| 425 | if(NOT APPLE) | 425 | if(NOT APPLE AND NOT YUZU_USE_BUNDLED_LIBUSB) |
| 426 | include(FindPkgConfig) | 426 | include(FindPkgConfig) |
| 427 | if (PKG_CONFIG_FOUND) | 427 | if (PKG_CONFIG_FOUND) |
| 428 | pkg_check_modules(LIBUSB QUIET libusb-1.0>=1.0.24) | 428 | pkg_check_modules(LIBUSB QUIET libusb-1.0>=1.0.24) |
| 429 | else() | 429 | else() |
| 430 | find_package(LibUSB) | 430 | find_package(LibUSB) |
| 431 | endif() | 431 | endif() |
| 432 | endif() | 432 | |
| 433 | if (NOT LIBUSB_FOUND OR YUZU_USE_BUNDLED_LIBUSB) | 433 | if (NOT LIBUSB_FOUND) |
| 434 | add_subdirectory(externals/libusb) | 434 | message(WARNING "libusb not found, falling back to externals") |
| 435 | set(LIBUSB_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/externals/libusb/libusb/libusb") | 435 | set(YUZU_USE_BUNDLED_LIBUSB ON) |
| 436 | set(LIBUSB_LIBRARIES usb) | 436 | else() |
| 437 | add_library(usb INTERFACE) | ||
| 438 | target_include_directories(usb INTERFACE "${LIBUSB_INCLUDE_DIRS}") | ||
| 439 | target_link_libraries(usb INTERFACE "${LIBUSB_LIBRARIES}") | ||
| 440 | endif() | ||
| 437 | endif() | 441 | endif() |
| 438 | 442 | ||
| 439 | # List of all FFmpeg components required | 443 | # List of all FFmpeg components required |
diff --git a/externals/CMakeLists.txt b/externals/CMakeLists.txt index aae0baa0b..5402a532f 100644 --- a/externals/CMakeLists.txt +++ b/externals/CMakeLists.txt | |||
| @@ -45,6 +45,11 @@ target_include_directories(microprofile INTERFACE ./microprofile) | |||
| 45 | add_library(unicorn-headers INTERFACE) | 45 | add_library(unicorn-headers INTERFACE) |
| 46 | target_include_directories(unicorn-headers INTERFACE ./unicorn/include) | 46 | target_include_directories(unicorn-headers INTERFACE ./unicorn/include) |
| 47 | 47 | ||
| 48 | # libusb | ||
| 49 | if (NOT LIBUSB_FOUND OR YUZU_USE_BUNDLED_LIBUSB) | ||
| 50 | add_subdirectory(libusb) | ||
| 51 | endif() | ||
| 52 | |||
| 48 | # SDL2 | 53 | # SDL2 |
| 49 | if (NOT SDL2_FOUND AND ENABLE_SDL2) | 54 | if (NOT SDL2_FOUND AND ENABLE_SDL2) |
| 50 | if (NOT WIN32) | 55 | if (NOT WIN32) |
diff --git a/externals/libusb/CMakeLists.txt b/externals/libusb/CMakeLists.txt index da6d68684..b2b36261c 100644 --- a/externals/libusb/CMakeLists.txt +++ b/externals/libusb/CMakeLists.txt | |||
| @@ -1,4 +1,7 @@ | |||
| 1 | if (MINGW OR NOT WIN32) | 1 | set(LIBUSB_FOUND ON CACHE BOOL "libusb is present" FORCE) |
| 2 | set(LIBUSB_VERSION "1.0.24" CACHE STRING "libusb version string" FORCE) | ||
| 3 | |||
| 4 | if (MINGW OR (${CMAKE_SYSTEM_NAME} MATCHES "Linux")) | ||
| 2 | # GNU toolchains for some reason doesn't work with the later half of this CMakeLists after | 5 | # GNU toolchains for some reason doesn't work with the later half of this CMakeLists after |
| 3 | # updating to 1.0.24, so we do it the old-fashioned way for now. | 6 | # updating to 1.0.24, so we do it the old-fashioned way for now. |
| 4 | 7 | ||
| @@ -21,17 +24,19 @@ if (MINGW OR NOT WIN32) | |||
| 21 | set(LIBUSB_MAKEFILE "${LIBUSB_PREFIX}/Makefile") | 24 | set(LIBUSB_MAKEFILE "${LIBUSB_PREFIX}/Makefile") |
| 22 | 25 | ||
| 23 | if (MINGW) | 26 | if (MINGW) |
| 24 | set(LIBUSB_LIBRARY "${LIBUSB_PREFIX}/libusb/.libs/libusb-1.0.dll.a") | 27 | set(LIBUSB_LIBRARIES "${LIBUSB_PREFIX}/libusb/.libs/libusb-1.0.dll.a" CACHE PATH "libusb library path" FORCE) |
| 25 | set(LIBUSB_SHARED_LIBRARY "${LIBUSB_PREFIX}/libusb/.libs/libusb-1.0.dll") | 28 | set(LIBUSB_SHARED_LIBRARY "${LIBUSB_PREFIX}/libusb/.libs/libusb-1.0.dll") |
| 26 | set(LIBUSB_SHARED_LIBRARY_DEST "${CMAKE_BINARY_DIR}/bin/libusb-1.0.dll") | 29 | set(LIBUSB_SHARED_LIBRARY_DEST "${CMAKE_BINARY_DIR}/bin/libusb-1.0.dll") |
| 27 | 30 | ||
| 28 | set(LIBUSB_CONFIGURE_ARGS --host=x86_64-w64-mingw32 --build=x86_64-windows) | 31 | set(LIBUSB_CONFIGURE_ARGS --host=x86_64-w64-mingw32 --build=x86_64-windows) |
| 29 | else() | 32 | else() |
| 30 | set(LIBUSB_LIBRARY "${LIBUSB_PREFIX}/libusb/.libs/libusb-1.0.so") | 33 | set(LIBUSB_LIBRARIES "${LIBUSB_PREFIX}/libusb/.libs/libusb-1.0.so" CACHE PATH "libusb library path" FORCE) |
| 31 | set(LIBUSB_SHARED_LIBRARY "${LIBUSB_LIBRARY}") | 34 | set(LIBUSB_SHARED_LIBRARY "${LIBUSB_LIBRARIES}") |
| 32 | set(LIBUSB_SHARED_LIBRARY_DEST "${CMAKE_BINARY_DIR}/bin/libusb-1.0.so") | 35 | set(LIBUSB_SHARED_LIBRARY_DEST "${CMAKE_BINARY_DIR}/bin/libusb-1.0.so") |
| 33 | endif() | 36 | endif() |
| 34 | 37 | ||
| 38 | set(LIBUSB_INCLUDE_DIRS "${LIBUSB_SRC_DIR}/libusb" CACHE PATH "libusb headers path" FORCE) | ||
| 39 | |||
| 35 | # 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. | 40 | # 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. |
| 36 | # set(LIBUSB_CFLAGS "-DGUID_DEVINTERFACE_USB_DEVICE=\\(GUID\\){0xA5DCBF10,0x6530,0x11D2,{0x90,0x1F,0x00,0xC0,0x4F,0xB9,0x51,0xED}}") | 41 | # set(LIBUSB_CFLAGS "-DGUID_DEVINTERFACE_USB_DEVICE=\\(GUID\\){0xA5DCBF10,0x6530,0x11D2,{0x90,0x1F,0x00,0xC0,0x4F,0xB9,0x51,0xED}}") |
| 37 | 42 | ||
| @@ -39,7 +44,7 @@ if (MINGW OR NOT WIN32) | |||
| 39 | 44 | ||
| 40 | add_custom_command( | 45 | add_custom_command( |
| 41 | OUTPUT | 46 | OUTPUT |
| 42 | "${LIBUSB_LIBRARY}" | 47 | "${LIBUSB_LIBRARIES}" |
| 43 | COMMAND | 48 | COMMAND |
| 44 | make | 49 | make |
| 45 | WORKING_DIRECTORY | 50 | WORKING_DIRECTORY |
| @@ -77,13 +82,14 @@ if (MINGW OR NOT WIN32) | |||
| 77 | 82 | ||
| 78 | add_custom_target(usb-bootstrap DEPENDS "${LIBUSB_CONFIGURE}") | 83 | add_custom_target(usb-bootstrap DEPENDS "${LIBUSB_CONFIGURE}") |
| 79 | add_custom_target(usb-configure DEPENDS "${LIBUSB_MAKEFILE}" usb-bootstrap) | 84 | add_custom_target(usb-configure DEPENDS "${LIBUSB_MAKEFILE}" usb-bootstrap) |
| 80 | add_custom_target(usb-build ALL DEPENDS "${LIBUSB_LIBRARY}" usb-configure) | 85 | add_custom_target(usb-build ALL DEPENDS "${LIBUSB_LIBRARIES}" usb-configure) |
| 81 | # Workaround since static linking didn't work out -- We need to copy the DLL to the bin directory | 86 | # Workaround since static linking didn't work out -- We need to copy the DLL to the bin directory |
| 82 | add_custom_target(usb-copy ALL DEPENDS "${LIBUSB_SHARED_LIBRARY_DEST}" usb-build) | 87 | add_custom_target(usb-copy ALL DEPENDS "${LIBUSB_SHARED_LIBRARY_DEST}" usb-build) |
| 83 | 88 | ||
| 84 | add_library(usb INTERFACE) | 89 | add_library(usb INTERFACE) |
| 85 | add_dependencies(usb usb-copy) | 90 | add_dependencies(usb usb-copy) |
| 86 | target_link_libraries(usb INTERFACE "${LIBUSB_LIBRARY}") | 91 | target_link_libraries(usb INTERFACE "${LIBUSB_LIBRARIES}") |
| 92 | target_include_directories(usb INTERFACE "${LIBUSB_INCLUDE_DIRS}") | ||
| 87 | 93 | ||
| 88 | if (${CMAKE_SYSTEM_NAME} MATCHES "Linux") | 94 | if (${CMAKE_SYSTEM_NAME} MATCHES "Linux") |
| 89 | find_package(Libudev QUIET) | 95 | find_package(Libudev QUIET) |
| @@ -92,7 +98,7 @@ if (MINGW OR NOT WIN32) | |||
| 92 | target_include_directories(usb INTERFACE "${LIBUDEV_INCLUDE_DIR}") | 98 | target_include_directories(usb INTERFACE "${LIBUDEV_INCLUDE_DIR}") |
| 93 | endif() | 99 | endif() |
| 94 | endif() | 100 | endif() |
| 95 | else() # MINGW OR NOT WIN32 | 101 | else() # MINGW OR (${CMAKE_SYSTEM_NAME} MATCHES "Linux") |
| 96 | # Ensure libusb compiles with UTF-8 encoding on MSVC | 102 | # Ensure libusb compiles with UTF-8 encoding on MSVC |
| 97 | if(MSVC) | 103 | if(MSVC) |
| 98 | add_compile_options(/utf-8) | 104 | add_compile_options(/utf-8) |
| @@ -248,4 +254,4 @@ else() # MINGW OR NOT WIN32 | |||
| 248 | 254 | ||
| 249 | 255 | ||
| 250 | configure_file(config.h.in config.h) | 256 | configure_file(config.h.in config.h) |
| 251 | endif() # MINGW | 257 | endif() # MINGW OR (${CMAKE_SYSTEM_NAME} MATCHES "Linux") |
diff --git a/src/input_common/CMakeLists.txt b/src/input_common/CMakeLists.txt index de53e1fda..7c5763f9c 100644 --- a/src/input_common/CMakeLists.txt +++ b/src/input_common/CMakeLists.txt | |||
| @@ -71,8 +71,7 @@ if (ENABLE_SDL2) | |||
| 71 | target_compile_definitions(input_common PRIVATE HAVE_SDL2) | 71 | target_compile_definitions(input_common PRIVATE HAVE_SDL2) |
| 72 | endif() | 72 | endif() |
| 73 | 73 | ||
| 74 | target_include_directories(input_common SYSTEM PRIVATE ${LIBUSB_INCLUDE_DIR}) | 74 | target_link_libraries(input_common PRIVATE usb) |
| 75 | target_link_libraries(input_common PRIVATE ${LIBUSB_LIBRARIES}) | ||
| 76 | 75 | ||
| 77 | create_target_directory_groups(input_common) | 76 | create_target_directory_groups(input_common) |
| 78 | target_link_libraries(input_common PUBLIC core PRIVATE common Boost::boost) | 77 | target_link_libraries(input_common PUBLIC core PRIVATE common Boost::boost) |