2017-01-20 16:51:06 +00:00
|
|
|
add_library(usb STATIC EXCLUDE_FROM_ALL
|
2022-04-11 13:04:20 +00:00
|
|
|
libusb/libusb/core.c
|
|
|
|
libusb/libusb/descriptor.c
|
|
|
|
libusb/libusb/hotplug.c
|
|
|
|
libusb/libusb/io.c
|
|
|
|
libusb/libusb/strerror.c
|
|
|
|
libusb/libusb/sync.c
|
2016-09-28 17:32:07 +00:00
|
|
|
)
|
2022-04-11 13:04:20 +00:00
|
|
|
set_target_properties(usb PROPERTIES VERSION 1.0.26)
|
2017-01-20 16:51:06 +00:00
|
|
|
if(WIN32)
|
2022-04-11 13:04:20 +00:00
|
|
|
target_include_directories(usb BEFORE PUBLIC libusb/libusb PRIVATE libusb/msvc)
|
2017-01-20 16:51:06 +00:00
|
|
|
else()
|
2016-09-28 17:32:07 +00:00
|
|
|
target_include_directories(usb
|
|
|
|
# turns out other projects also have "config.h", so make sure the
|
|
|
|
# LibUSB one comes first
|
|
|
|
BEFORE
|
|
|
|
|
2022-04-11 13:04:20 +00:00
|
|
|
PUBLIC libusb/libusb
|
2016-09-28 17:32:07 +00:00
|
|
|
PRIVATE "${CMAKE_CURRENT_BINARY_DIR}"
|
|
|
|
)
|
2017-01-20 16:51:06 +00:00
|
|
|
endif()
|
2016-09-28 17:32:07 +00:00
|
|
|
|
|
|
|
if(WIN32 OR CYGWIN)
|
2017-01-20 16:51:06 +00:00
|
|
|
target_sources(usb PRIVATE
|
2022-04-11 13:04:20 +00:00
|
|
|
libusb/libusb/os/threads_windows.c
|
|
|
|
libusb/libusb/os/windows_common.c
|
|
|
|
libusb/libusb/os/windows_usbdk.c
|
|
|
|
libusb/libusb/os/windows_winusb.c
|
2022-04-27 06:10:04 +00:00
|
|
|
libusb/libusb/os/events_windows.c
|
2017-01-20 16:51:06 +00:00
|
|
|
)
|
2022-04-11 13:04:20 +00:00
|
|
|
set(PLATFORM_WINDOWS TRUE)
|
2016-09-28 17:32:07 +00:00
|
|
|
elseif(APPLE)
|
2022-04-11 13:04:20 +00:00
|
|
|
target_sources(usb PRIVATE libusb/libusb/os/darwin_usb.c)
|
2016-09-28 17:32:07 +00:00
|
|
|
find_library(COREFOUNDATION_LIBRARY CoreFoundation)
|
|
|
|
find_library(IOKIT_LIBRARY IOKit)
|
|
|
|
find_library(OBJC_LIBRARY objc)
|
2022-04-11 13:04:20 +00:00
|
|
|
find_library(SECURITY_LIBRARY Security)
|
2016-09-28 17:32:07 +00:00
|
|
|
target_link_libraries(usb PRIVATE
|
|
|
|
${COREFOUNDATION_LIBRARY}
|
|
|
|
${IOKIT_LIBRARY}
|
|
|
|
${OBJC_LIBRARY}
|
2022-04-11 13:04:20 +00:00
|
|
|
${SECURITY_LIBRARY}
|
2016-09-28 17:32:07 +00:00
|
|
|
)
|
|
|
|
# # Dolphin on Android doesn't use libusb.
|
|
|
|
#elseif(ANDROID)
|
|
|
|
# target_sources(usb PRIVATE
|
2022-04-11 13:04:20 +00:00
|
|
|
# libusb/libusb/os/linux_usbfs.c
|
|
|
|
# libusb/libusb/os/linux_netlink.c
|
2016-09-28 17:32:07 +00:00
|
|
|
# )
|
|
|
|
# find_library(LOG_LIBRARY log)
|
|
|
|
# target_link_libraries(usb PRIVATE ${LOG_LIBRARY})
|
|
|
|
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
|
2022-04-11 13:04:20 +00:00
|
|
|
target_sources(usb PRIVATE libusb/libusb/os/linux_usbfs.c)
|
|
|
|
find_package(LIBUDEV)
|
2016-09-28 17:32:07 +00:00
|
|
|
if(LIBUDEV_FOUND)
|
2022-04-11 13:04:20 +00:00
|
|
|
target_sources(usb PRIVATE libusb/libusb/os/linux_udev.c)
|
2016-09-28 17:32:07 +00:00
|
|
|
target_link_libraries(usb PRIVATE "${LIBUDEV_LIBRARIES}")
|
|
|
|
target_include_directories(usb PRIVATE "${LIBUDEV_INCLUDE_DIR}")
|
|
|
|
set(HAVE_LIBUDEV TRUE)
|
|
|
|
else()
|
2022-04-11 13:04:20 +00:00
|
|
|
target_sources(usb PRIVATE libusb/libusb/os/linux_netlink.c)
|
2016-09-28 17:32:07 +00:00
|
|
|
endif()
|
|
|
|
elseif(${CMAKE_SYSTEM_NAME} MATCHES "NetBSD")
|
2022-04-11 13:04:20 +00:00
|
|
|
target_sources(usb PRIVATE libusb/libusb/os/netbsd_usb.c)
|
2016-09-28 17:32:07 +00:00
|
|
|
elseif(${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD")
|
2022-04-11 13:04:20 +00:00
|
|
|
target_sources(usb PRIVATE libusb/libusb/os/openbsd_usb.c)
|
2016-09-28 17:32:07 +00:00
|
|
|
endif()
|
|
|
|
|
|
|
|
if(UNIX)
|
|
|
|
target_sources(usb PRIVATE
|
2022-04-11 13:04:20 +00:00
|
|
|
libusb/libusb/os/events_posix.c
|
|
|
|
libusb/libusb/os/threads_posix.c
|
2016-09-28 17:32:07 +00:00
|
|
|
)
|
|
|
|
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()
|
2022-04-11 13:04:20 +00:00
|
|
|
set(PLATFORM_POSIX TRUE)
|
2016-09-28 17:32:07 +00:00
|
|
|
endif()
|
|
|
|
|
2022-04-11 13:04:20 +00:00
|
|
|
# Create config.h
|
|
|
|
|
2016-09-28 17:32:07 +00:00
|
|
|
include(CheckFunctionExists)
|
|
|
|
include(CheckIncludeFiles)
|
2022-04-11 13:04:20 +00:00
|
|
|
#include(CheckLibraryExists)
|
2016-09-28 17:32:07 +00:00
|
|
|
include(CheckTypeSize)
|
2022-04-11 13:04:20 +00:00
|
|
|
include(CheckSymbolExists)
|
|
|
|
|
2016-09-28 17:32:07 +00:00
|
|
|
check_include_files(asm/types.h HAVE_ASM_TYPES_H)
|
2022-04-11 13:04:20 +00:00
|
|
|
check_function_exists(clock_gettime HAVE_CLOCK_GETTIME)
|
|
|
|
check_symbol_exists(EFD_CLOEXEC "sys/eventfd.h" HAVE_DECL_EFD_CLOEXEC)
|
|
|
|
check_symbol_exists(EFD_NONBLOCK "sys/eventfd.h" HAVE_DECL_EFD_NONBLOCK)
|
|
|
|
check_symbol_exists(TFD_CLOEXEC "sys/timerfd.h" HAVE_DECL_TFD_CLOEXEC)
|
|
|
|
check_symbol_exists(TFD_NONBLOCK "sys/timerfd.h" HAVE_DECL_TFD_NONBLOCK)
|
|
|
|
check_include_files(dlfcn.h HAVE_DLFCN_H)
|
|
|
|
check_include_files(sys/eventfd.h HAVE_EVENTFD)
|
|
|
|
check_include_files(inttypes.h HAVE_INTTYPES_H)
|
|
|
|
check_include_files(IOKit/usb/IOUSBHostFamilyDefinitions.h HAVE_IOKIT_USB_IOUSBHOSTFAMILYDEFINITIONS_H)
|
|
|
|
#check_library_exists(udev HAVE_LIBUDEV)
|
|
|
|
check_include_files(memory.h HAVE_MEMORY_H)
|
2016-09-28 17:32:07 +00:00
|
|
|
|
|
|
|
set(CMAKE_EXTRA_INCLUDE_FILES poll.h)
|
2022-04-11 13:04:20 +00:00
|
|
|
check_type_size("nfds_t" NFDS_T)
|
2016-09-28 17:32:07 +00:00
|
|
|
unset(CMAKE_EXTRA_INCLUDE_FILES)
|
|
|
|
|
2022-04-11 13:04:20 +00:00
|
|
|
check_function_exists(pipe2 HAVE_PIPE2)
|
|
|
|
check_function_exists(pthread_condattr_setclock HAVE_PTHREAD_CONDATTR_SETCLOCK)
|
|
|
|
check_function_exists(pthread_setname_np HAVE_PTHREAD_SETNAME_NP)
|
|
|
|
check_function_exists(pthread_threadid_np HAVE_PTHREAD_THREADID_NP)
|
|
|
|
check_include_files(stdint.h HAVE_STDINT_H)
|
|
|
|
check_include_files(stdlib.h HAVE_STDLIB_H)
|
|
|
|
check_include_files(strings.h HAVE_STRINGS_H)
|
|
|
|
check_include_files(string.h HAVE_STRING_H)
|
|
|
|
check_type_size("struct timespec" STRUCT_TIMESPEC)
|
|
|
|
check_function_exists(syslog HAVE_SYSLOG)
|
|
|
|
check_include_files(sys/stat.h HAVE_SYS_STAT_H)
|
|
|
|
check_include_files(sys/time.h HAVE_SYS_TIME_H)
|
|
|
|
check_include_files(sys/types.h HAVE_SYS_TYPES_H)
|
|
|
|
check_include_files(sys/timerfd.h HAVE_TIMERFD)
|
|
|
|
check_include_files(unistd.h HAVE_UNISTD_H)
|
2016-09-28 17:32:07 +00:00
|
|
|
|
|
|
|
configure_file(config.h.in config.h)
|