From 8bb213922444daa007458569f744a0c5e103751f Mon Sep 17 00:00:00 2001 From: Michael Maltese Date: Wed, 28 Sep 2016 13:32:07 -0400 Subject: [PATCH 1/3] Build vendored libUSB with CMake --- CMakeLists.txt | 17 +++-- Externals/libusb/CMakeLists.txt | 113 ++++++++++++++++++++++++++++++++ Externals/libusb/config.h.in | 86 ++++++++++++++++++++++++ 3 files changed, 210 insertions(+), 6 deletions(-) create mode 100644 Externals/libusb/CMakeLists.txt create mode 100644 Externals/libusb/config.h.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 15e52bda7b..93b60ee113 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -273,10 +273,9 @@ if(APPLE) # increase the chance of not depending on a bunch of copies of them # installed by MacPorts, Fink, Homebrew, etc, and ending up copying # them into the bundle. Since we optionally depend on libraries which - # are not part of OS X (ffmpeg, libusb, etc.), however, don't remove - # the default path entirely as was done in a previous version of this - # file. This is still kinda evil, since it defeats the user's path - # settings... + # are not part of OS X (ffmpeg, etc.), however, don't remove the default + # path entirely as was done in a previous version of this file. This is + # still kinda evil, since it defeats the user's path settings... # See http://www.cmake.org/cmake/help/v3.0/command/find_program.html set(CMAKE_PREFIX_PATH "${CMAKE_PREFIX_PATH};/usr") endif() @@ -739,11 +738,17 @@ if(ENABLE_SDL) endif(SDL2_FOUND) endif() -include(FindLibUSB OPTIONAL) +if(NOT APPLE) + find_package(LibUSB) +endif() +add_definitions(-D__LIBUSB__) if(LIBUSB_FOUND) message("Using shared LibUSB") - add_definitions(-D__LIBUSB__) include_directories(${LIBUSB_INCLUDE_DIR}) +else() + message("Using static LibUSB from Externals") + add_subdirectory(Externals/libusb) + set(LIBUSB_LIBRARIES usb) endif(LIBUSB_FOUND) set(SFML_REQD_VERSION 2.1) diff --git a/Externals/libusb/CMakeLists.txt b/Externals/libusb/CMakeLists.txt new file mode 100644 index 0000000000..0faa2ac2f2 --- /dev/null +++ b/Externals/libusb/CMakeLists.txt @@ -0,0 +1,113 @@ +add_library(usb SHARED EXCLUDE_FROM_ALL + libusb/core.c + libusb/core.c + libusb/descriptor.c + libusb/hotplug.c + libusb/io.c + libusb/strerror.c + libusb/sync.c +) +set_target_properties(usb PROPERTIES VERSION 1.0.19) +target_include_directories(usb + # turns out other projects also have "config.h", so make sure the + # LibUSB one comes first + BEFORE + + PUBLIC libusb + PRIVATE "${CMAKE_CURRENT_BINARY_DIR}" +) + +if(WIN32 OR CYGWIN) + target_sources(usb PRIVATE libusb/os/windows_usb.c) + set(OS_WINDOWS TRUE) +elseif(APPLE) + target_sources(usb PRIVATE libusb/os/darwin_usb.c) + find_library(COREFOUNDATION_LIBRARY CoreFoundation) + find_library(IOKIT_LIBRARY IOKit) + find_library(OBJC_LIBRARY objc) + target_link_libraries(usb PRIVATE + ${COREFOUNDATION_LIBRARY} + ${IOKIT_LIBRARY} + ${OBJC_LIBRARY} + ) + set(OS_DARWIN TRUE) +# # Dolphin on Android doesn't use libusb. +#elseif(ANDROID) +# target_sources(usb PRIVATE +# libusb/os/linux_usbfs.c +# libusb/os/linux_netlink.c +# ) +# find_library(LOG_LIBRARY log) +# target_link_libraries(usb PRIVATE ${LOG_LIBRARY}) +# set(OS_LINUX TRUE) +elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux") + target_sources(usb PRIVATE libusb/os/linux_usbfs.c) + find_package(Libudev) + if(LIBUDEV_FOUND) + target_sources(usb PRIVATE libusb/os/linux_udev.c) + target_link_libraries(usb PRIVATE "${LIBUDEV_LIBRARIES}") + target_include_directories(usb PRIVATE "${LIBUDEV_INCLUDE_DIR}") + set(HAVE_LIBUDEV TRUE) + set(USE_LIBUDEV TRUE) + else() + target_sources(usb PRIVATE libusb/os/linux_netlink.c) + endif() + set(OS_LINUX TRUE) +elseif(${CMAKE_SYSTEM_NAME} MATCHES "NetBSD") + target_sources(usb PRIVATE libusb/os/netbsd_usb.c) + set(OS_NETBSD TRUE) +elseif(${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD") + target_sources(usb PRIVATE libusb/os/openbsd_usb.c) + set(OS_OPENBSD TRUE) +endif() + +if(UNIX) + target_sources(usb PRIVATE + libusb/os/poll_posix.c + libusb/os/threads_posix.c + ) + find_package(Threads REQUIRED) + if(THREADS_HAVE_PTHREAD_ARG) + target_compile_options(usb PUBLIC "-pthread") + endif() + if(CMAKE_THREAD_LIBS_INIT) + target_link_libraries(usb PRIVATE "${CMAKE_THREAD_LIBS_INIT}") + endif() + set(THREADS_POSIX TRUE) +elseif(WIN32) + target_sources(usb PRIVATE + libusb/os/poll_windows.c + libusb/os/threads_windows.c + ) +endif() + +include(CheckFunctionExists) +include(CheckIncludeFiles) +include(CheckTypeSize) +check_include_files(asm/types.h HAVE_ASM_TYPES_H) +check_function_exists(gettimeofday HAVE_GETTIMEOFDAY) +check_include_files(linux/filter.h HAVE_LINUX_FILTER_H) +check_include_files(linux/netlink.h HAVE_LINUX_NETLINK_H) +check_include_files(poll.h HAVE_POLL_H) +check_include_files(signal.h HAVE_SIGNAL_H) +check_include_files(strings.h HAVE_STRINGS_H) +check_type_size("struct timespec" STRUCT_TIMESPEC) +check_function_exists(syslog HAVE_SYSLOG_FUNC) +check_include_files(syslog.h HAVE_SYSLOG_H) +check_include_files(sys/socket.h HAVE_SYS_SOCKET_H) +check_include_files(sys/time.h HAVE_SYS_TIME_H) +check_include_files(sys/types.h HAVE_SYS_TYPES_H) + +set(CMAKE_EXTRA_INCLUDE_FILES poll.h) +check_type_size("nfds_t" nfds_t) +unset(CMAKE_EXTRA_INCLUDE_FILES) +if(HAVE_NFDS_T) + set(POLL_NFDS_TYPE "nfds_t") +else() + set(POLL_NFDS_TYPE "unsigned int") +endif() + +check_include_files(sys/timerfd.h USBI_TIMERFD_AVAILABLE) + + +configure_file(config.h.in config.h) diff --git a/Externals/libusb/config.h.in b/Externals/libusb/config.h.in new file mode 100644 index 0000000000..830628afaf --- /dev/null +++ b/Externals/libusb/config.h.in @@ -0,0 +1,86 @@ +/* Default visibility */ +#define DEFAULT_VISIBILITY __attribute__((visibility("default"))) + +/* Start with debug message logging enabled */ +#undef ENABLE_DEBUG_LOGGING + +/* Message logging */ +#undef ENABLE_LOGGING + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_ASM_TYPES_H 1 + +/* Define to 1 if you have the `gettimeofday' function. */ +#cmakedefine HAVE_GETTIMEOFDAY 1 + +/* Define to 1 if you have the `udev' library (-ludev). */ +#cmakedefine HAVE_LIBUDEV 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_LINUX_FILTER_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_LINUX_NETLINK_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_POLL_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SIGNAL_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_STRINGS_H 1 + +/* Define to 1 if the system has the type `struct timespec'. */ +#cmakedefine HAVE_STRUCT_TIMESPEC 1 + +/* syslog() function available */ +#cmakedefine HAVE_SYSLOG_FUNC 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYSLOG_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_SOCKET_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_TIME_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_TYPES_H 1 + +/* Darwin backend */ +#cmakedefine OS_DARWIN 1 + +/* Linux backend */ +#cmakedefine OS_LINUX 1 + +/* NetBSD backend */ +#cmakedefine OS_NETBSD 1 + +/* OpenBSD backend */ +#cmakedefine OS_OPENBSD 1 + +/* Windows backend */ +#cmakedefine OS_WINDOWS 1 + +/* type of second poll() argument */ +#define POLL_NFDS_TYPE @POLL_NFDS_TYPE@ + +/* Use POSIX Threads */ +#cmakedefine THREADS_POSIX + +/* timerfd headers available */ +#cmakedefine USBI_TIMERFD_AVAILABLE 1 + +/* Enable output to system log */ +#define USE_SYSTEM_LOGGING_FACILITY 1 + +/* Use udev for device enumeration/hotplug */ +#cmakedefine USE_UDEV 1 + +/* Use GNU extensions */ +#define _GNU_SOURCE + +/* Oldest Windows version supported */ +#define WINVER 0x0501 From a403e379012fd0f28357c969640f6af9b2657652 Mon Sep 17 00:00:00 2001 From: Michael Maltese Date: Wed, 28 Sep 2016 13:32:13 -0400 Subject: [PATCH 2/3] always build an implementation of GCAdapter (either libusb or android) --- Source/Core/InputCommon/CMakeLists.txt | 11 ++--- Source/Core/InputCommon/GCAdapter_Null.cpp | 53 ---------------------- 2 files changed, 5 insertions(+), 59 deletions(-) delete mode 100644 Source/Core/InputCommon/GCAdapter_Null.cpp diff --git a/Source/Core/InputCommon/CMakeLists.txt b/Source/Core/InputCommon/CMakeLists.txt index a0bcef815d..0c6b95a771 100644 --- a/Source/Core/InputCommon/CMakeLists.txt +++ b/Source/Core/InputCommon/CMakeLists.txt @@ -32,13 +32,12 @@ elseif(ANDROID) ControllerInterface/Android/Android.cpp) endif() -if(LIBUSB_FOUND) - set(SRCS ${SRCS} GCAdapter.cpp) -elseif(ANDROID) - set(SRCS ${SRCS} GCAdapter_Android.cpp) +if(ANDROID) + set(SRCS ${SRCS} GCAdapter_Android.cpp) else() - set(SRCS ${SRCS} GCAdapter_Null.cpp) -endif(LIBUSB_FOUND) + set(SRCS ${SRCS} GCAdapter.cpp) + set(LIBS ${LIBS} ${LIBUSB_LIBRARIES}) +endif() if(LIBEVDEV_FOUND AND LIBUDEV_FOUND) set(SRCS ${SRCS} ControllerInterface/evdev/evdev.cpp) diff --git a/Source/Core/InputCommon/GCAdapter_Null.cpp b/Source/Core/InputCommon/GCAdapter_Null.cpp deleted file mode 100644 index e5b30a312f..0000000000 --- a/Source/Core/InputCommon/GCAdapter_Null.cpp +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright 2014 Dolphin Emulator Project -// Licensed under GPLv2+ -// Refer to the license.txt file included. - -#include "InputCommon/GCAdapter.h" -#include "Common/CommonTypes.h" -#include "InputCommon/GCPadStatus.h" - -namespace GCAdapter -{ -void Init() -{ -} -void ResetRumble() -{ -} -void Shutdown() -{ -} -void SetAdapterCallback(std::function func) -{ -} -void StartScanThread() -{ -} -void StopScanThread() -{ -} -GCPadStatus Input(int chan) -{ - return {}; -} -void Output(int chan, u8 rumble_command) -{ -} -bool IsDetected() -{ - return false; -} -bool IsDriverDetected() -{ - return false; -} -bool DeviceConnected(int chan) -{ - return false; -} -bool UseAdapter() -{ - return false; -} - -} // end of namespace GCAdapter From eb4d980d2f5a3527106cf3ec5c15ac94cb0db4ec Mon Sep 17 00:00:00 2001 From: Michael Maltese Date: Wed, 28 Sep 2016 13:32:17 -0400 Subject: [PATCH 3/3] Ignore LIBUSB_FOUND on Apple It shouldn't be set in the first place, and its cached value is screwing up the buildbots. --- CMakeLists.txt | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 93b60ee113..89fbd4971b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -738,18 +738,20 @@ if(ENABLE_SDL) endif(SDL2_FOUND) endif() -if(NOT APPLE) - find_package(LibUSB) +if(NOT ANDROID) + add_definitions(-D__LIBUSB__) + if(NOT APPLE) + find_package(LibUSB) + endif() + if(LIBUSB_FOUND AND NOT APPLE) + message("Using shared LibUSB") + include_directories(${LIBUSB_INCLUDE_DIR}) + else() + message("Using static LibUSB from Externals") + add_subdirectory(Externals/libusb) + set(LIBUSB_LIBRARIES usb) + endif() endif() -add_definitions(-D__LIBUSB__) -if(LIBUSB_FOUND) - message("Using shared LibUSB") - include_directories(${LIBUSB_INCLUDE_DIR}) -else() - message("Using static LibUSB from Externals") - add_subdirectory(Externals/libusb) - set(LIBUSB_LIBRARIES usb) -endif(LIBUSB_FOUND) set(SFML_REQD_VERSION 2.1) if(NOT APPLE)