CMakeLists.txt 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. add_library(usb STATIC EXCLUDE_FROM_ALL
  2. libusb/libusb/core.c
  3. libusb/libusb/descriptor.c
  4. libusb/libusb/hotplug.c
  5. libusb/libusb/io.c
  6. libusb/libusb/strerror.c
  7. libusb/libusb/sync.c
  8. )
  9. dolphin_disable_warnings(usb)
  10. set_target_properties(usb PROPERTIES VERSION 1.0.26)
  11. if(WIN32)
  12. target_include_directories(usb BEFORE PUBLIC libusb/libusb PRIVATE libusb/msvc)
  13. else()
  14. target_include_directories(usb
  15. # turns out other projects also have "config.h", so make sure the
  16. # LibUSB one comes first
  17. BEFORE
  18. PUBLIC libusb/libusb
  19. PRIVATE "${CMAKE_CURRENT_BINARY_DIR}"
  20. )
  21. endif()
  22. if(WIN32 OR CYGWIN)
  23. target_sources(usb PRIVATE
  24. libusb/libusb/os/threads_windows.c
  25. libusb/libusb/os/windows_common.c
  26. libusb/libusb/os/windows_usbdk.c
  27. libusb/libusb/os/windows_winusb.c
  28. libusb/libusb/os/events_windows.c
  29. )
  30. set(PLATFORM_WINDOWS TRUE)
  31. elseif(APPLE)
  32. target_sources(usb PRIVATE libusb/libusb/os/darwin_usb.c)
  33. find_library(COREFOUNDATION_LIBRARY CoreFoundation)
  34. find_library(IOKIT_LIBRARY IOKit)
  35. find_library(OBJC_LIBRARY objc)
  36. find_library(SECURITY_LIBRARY Security)
  37. target_link_libraries(usb PRIVATE
  38. ${COREFOUNDATION_LIBRARY}
  39. ${IOKIT_LIBRARY}
  40. ${OBJC_LIBRARY}
  41. ${SECURITY_LIBRARY}
  42. )
  43. # # Dolphin on Android doesn't use libusb.
  44. #elseif(ANDROID)
  45. # target_sources(usb PRIVATE
  46. # libusb/libusb/os/linux_usbfs.c
  47. # libusb/libusb/os/linux_netlink.c
  48. # )
  49. # find_library(LOG_LIBRARY log)
  50. # target_link_libraries(usb PRIVATE ${LOG_LIBRARY})
  51. elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
  52. target_sources(usb PRIVATE libusb/libusb/os/linux_usbfs.c)
  53. find_package(LIBUDEV)
  54. if(LIBUDEV_FOUND)
  55. target_sources(usb PRIVATE libusb/libusb/os/linux_udev.c)
  56. target_link_libraries(usb PRIVATE "${LIBUDEV_LIBRARIES}")
  57. target_include_directories(usb PRIVATE "${LIBUDEV_INCLUDE_DIR}")
  58. set(HAVE_LIBUDEV TRUE)
  59. else()
  60. target_sources(usb PRIVATE libusb/libusb/os/linux_netlink.c)
  61. endif()
  62. elseif(${CMAKE_SYSTEM_NAME} MATCHES "NetBSD")
  63. target_sources(usb PRIVATE libusb/libusb/os/netbsd_usb.c)
  64. elseif(${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD")
  65. target_sources(usb PRIVATE libusb/libusb/os/openbsd_usb.c)
  66. endif()
  67. if(UNIX)
  68. target_sources(usb PRIVATE
  69. libusb/libusb/os/events_posix.c
  70. libusb/libusb/os/threads_posix.c
  71. )
  72. find_package(Threads REQUIRED)
  73. if(THREADS_HAVE_PTHREAD_ARG)
  74. target_compile_options(usb PUBLIC "-pthread")
  75. endif()
  76. if(CMAKE_THREAD_LIBS_INIT)
  77. target_link_libraries(usb PRIVATE "${CMAKE_THREAD_LIBS_INIT}")
  78. endif()
  79. set(PLATFORM_POSIX TRUE)
  80. endif()
  81. # Create config.h
  82. include(CheckFunctionExists)
  83. include(CheckIncludeFiles)
  84. #include(CheckLibraryExists)
  85. include(CheckTypeSize)
  86. include(CheckSymbolExists)
  87. check_include_files(asm/types.h HAVE_ASM_TYPES_H)
  88. check_function_exists(clock_gettime HAVE_CLOCK_GETTIME)
  89. check_symbol_exists(EFD_CLOEXEC "sys/eventfd.h" HAVE_DECL_EFD_CLOEXEC)
  90. check_symbol_exists(EFD_NONBLOCK "sys/eventfd.h" HAVE_DECL_EFD_NONBLOCK)
  91. check_symbol_exists(TFD_CLOEXEC "sys/timerfd.h" HAVE_DECL_TFD_CLOEXEC)
  92. check_symbol_exists(TFD_NONBLOCK "sys/timerfd.h" HAVE_DECL_TFD_NONBLOCK)
  93. check_include_files(dlfcn.h HAVE_DLFCN_H)
  94. check_include_files(sys/eventfd.h HAVE_EVENTFD)
  95. check_include_files(inttypes.h HAVE_INTTYPES_H)
  96. check_include_files(IOKit/usb/IOUSBHostFamilyDefinitions.h HAVE_IOKIT_USB_IOUSBHOSTFAMILYDEFINITIONS_H)
  97. #check_library_exists(udev HAVE_LIBUDEV)
  98. check_include_files(memory.h HAVE_MEMORY_H)
  99. set(CMAKE_EXTRA_INCLUDE_FILES poll.h)
  100. check_type_size("nfds_t" NFDS_T)
  101. unset(CMAKE_EXTRA_INCLUDE_FILES)
  102. check_function_exists(pipe2 HAVE_PIPE2)
  103. check_function_exists(pthread_condattr_setclock HAVE_PTHREAD_CONDATTR_SETCLOCK)
  104. check_function_exists(pthread_setname_np HAVE_PTHREAD_SETNAME_NP)
  105. check_function_exists(pthread_threadid_np HAVE_PTHREAD_THREADID_NP)
  106. check_include_files(stdint.h HAVE_STDINT_H)
  107. check_include_files(stdlib.h HAVE_STDLIB_H)
  108. check_include_files(strings.h HAVE_STRINGS_H)
  109. check_include_files(string.h HAVE_STRING_H)
  110. check_type_size("struct timespec" STRUCT_TIMESPEC)
  111. check_function_exists(syslog HAVE_SYSLOG)
  112. check_include_files(sys/stat.h HAVE_SYS_STAT_H)
  113. check_include_files(sys/time.h HAVE_SYS_TIME_H)
  114. check_include_files(sys/types.h HAVE_SYS_TYPES_H)
  115. check_include_files(sys/timerfd.h HAVE_TIMERFD)
  116. check_include_files(unistd.h HAVE_UNISTD_H)
  117. configure_file(config.h.in config.h)
  118. add_library(LibUSB::LibUSB ALIAS usb)