@ -1,9 +1,92 @@
# E n s u r e l i b u s b c o m p i l e s w i t h U T F - 8 e n c o d i n g o n MSVC
if ( MSVC )
add_compile_options ( /utf-8 )
endif ( )
if ( MINGW )
# T h e M i n G W t o o l c h a i n f o r s o m e r e a s o n d o e s n ' t w o r k w i t h t h i s C M a k e L i s t s f i l e a f t e r u p d a t i n g t o
# 1 . 0 . 2 4 , s o w e d o i t t h e o l d - f a s h i o n e d w a y f o r n o w . W e m a y w a n t t o m o v e n a t i v e L i n u x t o o l c h a i n s
# t o h e r e , too ( TODO lat9nq? ) .
add_library ( usb STATIC EXCLUDE_FROM_ALL
set ( LIBUSB_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/libusb" )
set ( LIBUSB_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/libusb" )
# W o r k a r o u n d s f o r M S Y S / M i n G W
if ( MSYS )
# C M a k e o n W i n d o w s p a s s e s ` C : / ` , b u t w e n e e d ` / C / ` o r ` / c / ` t o u s e ` c o n f i g u r e `
string ( REPLACE ":/" "/" LIBUSB_SRC_DIR "${LIBUSB_SRC_DIR}" )
set ( LIBUSB_SRC_DIR "/${LIBUSB_SRC_DIR}" )
# A n d n o w t h a t w e a r e u s i n g / C / f o r s r c d i r b u t e v e r y t h i n g e l s e i s u s i n g C : / , w e n e e d t o
# c o m p i l e e v e r y t h i n g i n t h e s o u r c e d i r e c t o r y , e l s e ` c o n f i g u r e ` w o n ' t t h i n k t h e b u i l d
# e n v i r o n m e n t i s s a n e .
set ( LIBUSB_PREFIX "${LIBUSB_SRC_DIR}" )
endif ( )
set ( LIBUSB_CONFIGURE "${LIBUSB_SRC_DIR}/configure" )
set ( LIBUSB_MAKEFILE "${LIBUSB_PREFIX}/Makefile" )
set ( LIBUSB_LIBRARY "${LIBUSB_PREFIX}/libusb/.libs/libusb-1.0.dll.a" )
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" )
# C a u s e s " e x t e r n a l s / l i b u s b / l i b u s b / l i b u s b / o s / w i n d o w s _ w i n u s b . c : 1 4 2 7 : 2 : e r r o r : c o n v e r s i o n t o n o n - s c a l a r t y p e r e q u e s t e d " , s o c a n n o t s t a t i c a l l y l i n k i t f o r n o w .
# set ( LIBUSB_CFLAGS "-DGUID_DEVINTERFACE_USB_DEVICE=\\(GUID\\){0xA5DCBF10,0x6530,0x11D2,{0x90,0x1F,0x00,0xC0,0x4F,0xB9,0x51,0xED}}" )
make_directory ( "${LIBUSB_PREFIX}" )
add_custom_command (
O U T P U T
" $ { L I B U S B _ L I B R A R Y } "
C O M M A N D
m a k e
W O R K I N G _ D I R E C T O R Y
" $ { L I B U S B _ P R E F I X } "
)
# W e m a y u s e t h i s p a t h f o r o t h e r G N U t o o l c h a i n s , s o p u t a l l o f t h e M i n G W - s p e c i f i c s t u f f h e r e
if ( MINGW )
set ( LIBUSB_CONFIGURE_ARGS --host=x86_64-w64-mingw32 --build=x86_64-windows )
endif ( )
add_custom_command (
O U T P U T
" $ { L I B U S B _ M A K E F I L E } "
C O M M A N D
# / b i n / e n v
# C F L A G S = " $ { L I B U S B _ C F L A G S } "
/ b i n / s h " $ { L I B U S B _ C O N F I G U R E } "
$ { L I B U S B _ C O N F I G U R E _ A R G S }
- - s r c d i r = " $ { L I B U S B _ S R C _ D I R } "
W O R K I N G _ D I R E C T O R Y
" $ { L I B U S B _ P R E F I X } "
)
add_custom_command (
O U T P U T
" $ { L I B U S B _ C O N F I G U R E } "
C O M M A N D
/ b i n / s h " $ { L I B U S B _ S R C _ D I R } / b o o t s t r a p . s h "
W O R K I N G _ D I R E C T O R Y
" $ { L I B U S B _ S R C _ D I R } "
)
add_custom_command (
O U T P U T
" $ { L I B U S B _ S H A R E D _ L I B R A R Y _ D E S T } "
C O M M A N D
/ b i n / c p " $ { L I B U S B _ S H A R E D _ L I B R A R Y } " " $ { L I B U S B _ S H A R E D _ L I B R A R Y _ D E S T } "
)
add_custom_target ( usb-bootstrap ALL DEPENDS "${LIBUSB_CONFIGURE}" )
add_custom_target ( usb-configure ALL DEPENDS "${LIBUSB_MAKEFILE}" usb-bootstrap )
add_custom_target ( usb-build ALL DEPENDS "${LIBUSB_LIBRARY}" usb-configure )
# W o r k a r o u n d s i n c e s t a t i c l i n k i n g d i d n ' t w o r k o u t - - W e n e e d t o c o p y t h e D L L t o t h e b i n d i r e c t o r y
add_custom_target ( usb-copy ALL DEPENDS "${LIBUSB_SHARED_LIBRARY_DEST}" usb-build )
# M a k e ` u s b ` a l i a s t o L I B U S B _ L I B R A R Y
add_library ( usb INTERFACE )
target_link_libraries ( usb INTERFACE "${LIBUSB_LIBRARY}" )
else ( ) # MINGW
# E n s u r e l i b u s b c o m p i l e s w i t h U T F - 8 e n c o d i n g o n MSVC
if ( MSVC )
add_compile_options ( /utf-8 )
endif ( )
add_library ( usb STATIC EXCLUDE_FROM_ALL
l i b u s b / l i b u s b / c o r e . c
l i b u s b / l i b u s b / c o r e . c
l i b u s b / l i b u s b / d e s c r i p t o r . c
@ -11,9 +94,9 @@ add_library(usb STATIC EXCLUDE_FROM_ALL
l i b u s b / l i b u s b / i o . c
l i b u s b / l i b u s b / s t r e r r o r . c
l i b u s b / l i b u s b / s y n c . c
)
set_target_properties ( usb PROPERTIES VERSION 1.0.2 3 )
if ( WIN32 )
)
set_target_properties ( usb PROPERTIES VERSION 1.0.2 4 )
if ( WIN32 )
target_include_directories ( usb
B E F O R E
P U B L I C
@ -29,8 +112,8 @@ if(WIN32)
# W o r k s a r o u n d o t h e r l i b r a r i e s p r o v i d i n g t h e i r o w n d e f i n i t i o n o f U S B GUIDs ( e.g. SDL2 )
target_compile_definitions ( usb PRIVATE "-DGUID_DEVINTERFACE_USB_DEVICE=(GUID){ 0xA5DCBF10, 0x6530, 0x11D2, {0x90, 0x1F, 0x00, 0xC0, 0x4F, 0xB9, 0x51, 0xED}}" )
else ( )
target_include_directories ( usb
else ( )
target_include_directories ( usb
# t u r n s o u t o t h e r p r o j e c t s a l s o h a v e " c o n f i g . h " , s o m a k e s u r e t h e
# L i b U S B o n e c o m e s f i r s t
B E F O R E
@ -40,10 +123,10 @@ target_include_directories(usb
P R I V A T E
" $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } "
)
endif ( )
)
endif ( )
if ( WIN32 OR CYGWIN )
if ( WIN32 OR CYGWIN )
target_sources ( usb PRIVATE
l i b u s b / l i b u s b / o s / t h r e a d s _ w i n d o w s . c
l i b u s b / l i b u s b / o s / w i n d o w s _ w i n u s b . c
@ -51,7 +134,7 @@ if(WIN32 OR CYGWIN)
l i b u s b / l i b u s b / o s / w i n d o w s _ c o m m o n . c
)
set ( OS_WINDOWS TRUE )
elseif ( APPLE )
elseif ( APPLE )
target_sources ( usb PRIVATE
l i b u s b / l i b u s b / o s / d a r w i n _ u s b . c
)
@ -64,7 +147,7 @@ elseif(APPLE)
$ { O B J C _ L I B R A R Y }
)
set ( OS_DARWIN TRUE )
elseif ( ANDROID )
elseif ( ANDROID )
target_sources ( usb PRIVATE
l i b u s b / l i b u s b / o s / l i n u x _ u s b f s . c
l i b u s b / l i b u s b / o s / l i n u x _ n e t l i n k . c
@ -72,7 +155,7 @@ elseif(ANDROID)
find_library ( LOG_LIBRARY log )
target_link_libraries ( usb PRIVATE ${ LOG_LIBRARY } )
set ( OS_LINUX TRUE )
elseif ( ${ CMAKE_SYSTEM_NAME } MATCHES "Linux" )
elseif ( ${ CMAKE_SYSTEM_NAME } MATCHES "Linux" )
target_sources ( usb PRIVATE
l i b u s b / l i b u s b / o s / l i n u x _ u s b f s . c
)
@ -91,19 +174,19 @@ elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
)
endif ( )
set ( OS_LINUX TRUE )
elseif ( ${ CMAKE_SYSTEM_NAME } MATCHES "NetBSD" )
elseif ( ${ CMAKE_SYSTEM_NAME } MATCHES "NetBSD" )
target_sources ( usb PRIVATE
l i b u s b / l i b u s b / o s / n e t b s d _ u s b . c
)
set ( OS_NETBSD TRUE )
elseif ( ${ CMAKE_SYSTEM_NAME } MATCHES "OpenBSD" )
elseif ( ${ CMAKE_SYSTEM_NAME } MATCHES "OpenBSD" )
target_sources ( usb PRIVATE
l i b u s b / l i b u s b / o s / o p e n b s d _ u s b . c
)
set ( OS_OPENBSD TRUE )
endif ( )
endif ( )
if ( UNIX )
if ( UNIX )
target_sources ( usb PRIVATE
l i b u s b / l i b u s b / o s / e v e n t s _ p o s i x . c
l i b u s b / l i b u s b / o s / t h r e a d s _ p o s i x . c
@ -116,40 +199,41 @@ if(UNIX)
target_link_libraries ( usb PRIVATE "${CMAKE_THREAD_LIBS_INIT}" )
endif ( )
set ( THREADS_POSIX TRUE )
elseif ( WIN32 )
elseif ( WIN32 )
target_sources ( usb PRIVATE
l i b u s b / l i b u s b / o s / e v e n t s _ w i n d o w s . c
l i b u s b / l i b u s b / o s / t h r e a d s _ w i n d o w s . c
)
endif ( )
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 )
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 ( 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 ( )
else ( )
set ( POLL_NFDS_TYPE "unsigned int" )
endif ( )
endif ( )
check_include_files ( sys/timerfd.h USBI_TIMERFD_AVAILABLE )
check_include_files ( sys/timerfd.h USBI_TIMERFD_AVAILABLE )
configure_file ( config.h.in config.h )
configure_file ( config.h.in config.h )
endif ( ) # MINGW