Skip to content

Commit 7d550ff

Browse files
committed
reconfigure build to link vendor hidapi and separate components
1 parent 695b5f9 commit 7d550ff

File tree

4 files changed

+26
-120
lines changed

4 files changed

+26
-120
lines changed

CMakeLists.txt

+5-93
Original file line numberDiff line numberDiff line change
@@ -1,109 +1,21 @@
1-
cmake_minimum_required(VERSION 3.0)
2-
3-
project(hidapi VERSION 0.7.1)
4-
5-
option(HID_DEBUG_PARSER "verbose parser debugging output" OFF)
6-
7-
# option(LIBUSB "use libusb backend" OFF)
8-
# option(HIDRAW "use hidraw backend (linux/freebsd)" ON)
9-
10-
option(HID_EXAMPLE_TEST "build test example" OFF)
1+
cmake_minimum_required(VERSION 3.6)
2+
project(hidapi_tools)
113
option(HID_EXAMPLE_OSC "build osc example" OFF)
12-
134
option(HID_INSTALL_HUT "install hid usage tables" ON)
14-
15-
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
16-
set(HIDAPI "default" CACHE STRING "HID API to use (one of {default,hidraw,libusb})")
17-
elseif(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
18-
set(HIDAPI "libusb")
19-
endif()
20-
21-
# add our own cmake-modules
22-
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake_modules/")
23-
24-
if( HID_DEBUG_PARSER )
25-
add_definitions( -DDEBUG_PARSER )
26-
endif()
27-
28-
# some default libraries
29-
if (NOT WIN32)
30-
find_package(Pthreads)
31-
if (NOT PTHREADS_FOUND)
32-
message(SEND_ERROR "cannot find libpthreads")
33-
endif()
34-
endif()
35-
36-
37-
# directories
38-
add_subdirectory(hidapi)
39-
40-
if(CMAKE_SYSTEM_NAME MATCHES "Linux" OR CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
41-
add_definitions( -DLINUX_FREEBSD )
42-
if(HIDAPI STREQUAL "default")
43-
set( HIDAPI hidraw )
44-
endif()
45-
46-
if(NOT HIDAPI MATCHES "^(libusb|hidraw)$")
47-
message(WARNING "Unrecognised hid API: ${HIDAPI}")
48-
endif()
49-
50-
if (HIDAPI STREQUAL hidraw)
51-
add_subdirectory(linux)
52-
# set( hidapi_source ${hidapi_SOURCE_DIR}/linux )
53-
link_directories( ${UDEV_LIBRARIES} )
54-
elseif (HIDAPI STREQUAL libusb)
55-
add_subdirectory(libusb)
56-
# set( hidapi_source ${hidapi_SOURCE_DIR}/libusb )
57-
link_directories( ${LIBUSB_1_LIBRARIES} ${PTHREADS_LIBRARIES} )
58-
endif()
59-
60-
endif()
61-
62-
63-
if(WIN32)
64-
add_definitions( -DWIN32 )
65-
add_subdirectory(windows)
66-
# set( hidapi_source ${hidapi_SOURCE_DIR}/windows )
67-
#todo: add library dependencies
68-
endif()
69-
70-
if(APPLE)
71-
add_definitions( -DAPPLE )
72-
add_subdirectory(mac)
73-
# set( hidapi_source ${hidapi_SOURCE_DIR}/mac )
74-
#todo: add library dependencies - TEST
75-
find_library(IOKIT_LIBRARY IOKit )
76-
find_library(COREFOUNDATION_LIBRARY CoreFoundation )
77-
mark_as_advanced (COREFOUNDATION_LIBRARY
78-
IOKIT_LIBRARY)
79-
set(EXTRA_LIBS ${COREFOUNDATION_LIBRARY} ${IOKIT_LIBRARY})
80-
#link_directories("-framework IOKit -framework CoreFoundation")
81-
endif()
5+
find_package(hidapi REQUIRED)
826

837
add_subdirectory(hidapi_parser)
848

85-
# message( "main: hidapi source dir: ${hidapi_source}" )
869

87-
if( HID_EXAMPLE_TEST )
88-
add_subdirectory(hidtest)
10+
if( HID_PARSER_TEST )
8911
add_subdirectory(hidparsertest)
90-
if(APPLE)
91-
add_subdirectory(hidtestosx)
92-
endif()
93-
if(WIN32)
94-
add_subdirectory(hidtestwindows)
95-
endif()
9612
endif()
9713

9814
if( HID_EXAMPLE_OSC )
9915
add_subdirectory(hidapi2osc)
10016
endif()
10117

102-
if( HID_DEBUG_PARSER OR HID_INSTALL_HUT )
103-
# provisional to avoid having to commit to sc master while the HID submodule
104-
# is not final/added to master
105-
# the sc-settings for cmake_install_prefix and scappauxresourcesdir are not
106-
# visible in this scope
18+
if( HID_INSTALL_HUT )
10719
if(APPLE)
10820
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
10921
SET(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/Install")

hidapi2osc/CMakeLists.txt

+4-9
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,10 @@ include(FindPkgConfig)
44
# pkg_check_modules
55
pkg_check_modules(liblo REQUIRED liblo)
66

7-
# add_subdirectory( ${hidapi_source} )
8-
9-
# message( "osc: hidapi include dirs are: ${hidapi_INCLUDE_DIRS}" )
10-
# message( "osc: hidapi parser include dirs are: ${hidapi_parser_INCLUDE_DIRS}" )
11-
127
include_directories(
138
${CMAKE_BINARY_DIR}
149
${liblo_INCLUDE_DIRS}
15-
${hidapi_SOURCE_DIR}/hidapi/
16-
${hidapi_SOURCE_DIR}/hidapi_parser/
10+
${CMAKE_SOURCE_DIR}/hidapi_parser/
1711
)
1812

1913
link_directories(
@@ -22,15 +16,16 @@ link_directories(
2216

2317

2418
##########################################################################
25-
# sdl2osc
19+
# hidapi2osc
2620
##########################################################################
21+
project(hidapi2osc)
2722

2823
set(hidapi2osc_SRCS
2924
hidapi2osc.cpp
3025
)
3126

3227
add_executable( hidapi2osc ${hidapi2osc_SRCS} )
3328

34-
target_link_libraries(hidapi2osc ${liblo_LIBRARIES} ${EXTRA_LIBS} hidapi hidapi_parser m)
29+
target_link_libraries(hidapi2osc ${liblo_LIBRARIES} ${EXTRA_LIBS} hidapi::hidapi hidapi_parser m)
3530

3631
install(TARGETS hidapi2osc DESTINATION bin)

hidapi_parser/CMakeLists.txt

+15-10
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
message(STATUS " hidapi_parser" )
2+
project(hidapi_parser)
3+
find_package(hidapi REQUIRED)
4+
option(HID_DEBUG_PARSER "verbose parser debugging output" OFF)
5+
option(HID_PARSER_TEST "install hidparsertest" OFF)
6+
if( HID_DEBUG_PARSER )
7+
add_definitions( -DDEBUG_PARSER )
8+
endif()
29

10+
if(CMAKE_SYSTEM_NAME MATCHES "Linux" OR CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
11+
add_definitions( -DLINUX_FREEBSD )
12+
endif()
313

4-
# message( "hidapi parser source dir is: ${hidapi_SOURCE_DIR}" )
5-
#
6-
# set( hidapi_parser_INCLUDE_DIRS ${hidapi_SOURCE_DIR}/hidapi_parser/)
7-
# # set( hidapi_LIBS ${UDEV_LIBRARIES})
8-
# set( hidapi_parser_SRCS hidapi_parser.c )
9-
#
10-
# message( "hidapi_parser include dirs are: ${hidapi_parser_INCLUDE_DIRS}" )
14+
set(SOURCES hidapi_parser.c)
15+
set(HEADERS hidapi_parser.h)
16+
add_library( hidapi_parser STATIC ${SOURCES} )
1117

12-
include_directories( ${hidapi_SOURCE_DIR}/hidapi/ )
13-
add_library( hidapi_parser STATIC hidapi_parser.c )
14-
target_link_libraries( hidapi )
18+
target_link_libraries(hidapi_parser hidapi::hidapi)
19+
target_include_directories(hidapi_parser PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

hidparsertest/CMakeLists.txt

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
message(STATUS " hidparsertest" )
2-
3-
include_directories(
4-
${CMAKE_BINARY_DIR}
5-
${hidapi_SOURCE_DIR}/hidapi/
6-
${hidapi_SOURCE_DIR}/hidapi_parser/
7-
)
8-
2+
include_directories(${CMAKE_SOURCE_DIR}/hidapi_parser/)
93
add_executable( hidparsertest hidparsertest.c )
104

11-
target_link_libraries(hidparsertest hidapi hidapi_parser ${EXTRA_LIBS} m)
5+
target_link_libraries(hidparsertest hidapi::hidapi hidapi_parser ${EXTRA_LIBS} m)
126

137
install(TARGETS hidparsertest DESTINATION bin)

0 commit comments

Comments
 (0)