From dc40db85cfbb4a4d26d471f8aee9a20d32de981a Mon Sep 17 00:00:00 2001 From: Chad Cassady Date: Sat, 6 Apr 2024 10:03:45 -0500 Subject: [PATCH] reconfigure build to link vendor hidapi and separate components --- CMakeLists.txt | 98 ++---------------------------------- hidapi2osc/CMakeLists.txt | 13 ++--- hidapi_parser/CMakeLists.txt | 23 +++++---- hidparsertest/CMakeLists.txt | 10 +--- 4 files changed, 23 insertions(+), 121 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b01216f1..3f31bb63 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,109 +1,21 @@ -cmake_minimum_required(VERSION 3.0) - -project(hidapi VERSION 0.7.1) - -option(HID_DEBUG_PARSER "verbose parser debugging output" OFF) - -# option(LIBUSB "use libusb backend" OFF) -# option(HIDRAW "use hidraw backend (linux/freebsd)" ON) - -option(HID_EXAMPLE_TEST "build test example" OFF) +cmake_minimum_required(VERSION 3.6) +project(hidapi_tools) option(HID_EXAMPLE_OSC "build osc example" OFF) - option(HID_INSTALL_HUT "install hid usage tables" ON) - -if(${CMAKE_SYSTEM_NAME} MATCHES "Linux") - set(HIDAPI "default" CACHE STRING "HID API to use (one of {default,hidraw,libusb})") -elseif(CMAKE_SYSTEM_NAME MATCHES "FreeBSD") - set(HIDAPI "libusb") -endif() - -# add our own cmake-modules -set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake_modules/") - -if( HID_DEBUG_PARSER ) - add_definitions( -DDEBUG_PARSER ) -endif() - -# some default libraries -if (NOT WIN32) - find_package(Pthreads) - if (NOT PTHREADS_FOUND) - message(SEND_ERROR "cannot find libpthreads") - endif() -endif() - - -# directories -add_subdirectory(hidapi) - -if(CMAKE_SYSTEM_NAME MATCHES "Linux" OR CMAKE_SYSTEM_NAME MATCHES "FreeBSD") - add_definitions( -DLINUX_FREEBSD ) - if(HIDAPI STREQUAL "default") - set( HIDAPI hidraw ) - endif() - - if(NOT HIDAPI MATCHES "^(libusb|hidraw)$") - message(WARNING "Unrecognised hid API: ${HIDAPI}") - endif() - - if (HIDAPI STREQUAL hidraw) - add_subdirectory(linux) - # set( hidapi_source ${hidapi_SOURCE_DIR}/linux ) - link_directories( ${UDEV_LIBRARIES} ) - elseif (HIDAPI STREQUAL libusb) - add_subdirectory(libusb) - # set( hidapi_source ${hidapi_SOURCE_DIR}/libusb ) - link_directories( ${LIBUSB_1_LIBRARIES} ${PTHREADS_LIBRARIES} ) - endif() - -endif() - - -if(WIN32) - add_definitions( -DWIN32 ) - add_subdirectory(windows) -# set( hidapi_source ${hidapi_SOURCE_DIR}/windows ) - #todo: add library dependencies -endif() - -if(APPLE) - add_definitions( -DAPPLE ) - add_subdirectory(mac) -# set( hidapi_source ${hidapi_SOURCE_DIR}/mac ) - #todo: add library dependencies - TEST - find_library(IOKIT_LIBRARY IOKit ) - find_library(COREFOUNDATION_LIBRARY CoreFoundation ) - mark_as_advanced (COREFOUNDATION_LIBRARY - IOKIT_LIBRARY) - set(EXTRA_LIBS ${COREFOUNDATION_LIBRARY} ${IOKIT_LIBRARY}) - #link_directories("-framework IOKit -framework CoreFoundation") -endif() +find_package(hidapi REQUIRED) add_subdirectory(hidapi_parser) -# message( "main: hidapi source dir: ${hidapi_source}" ) -if( HID_EXAMPLE_TEST ) - add_subdirectory(hidtest) +if( HID_PARSER_TEST ) add_subdirectory(hidparsertest) - if(APPLE) - add_subdirectory(hidtestosx) - endif() - if(WIN32) - add_subdirectory(hidtestwindows) - endif() endif() if( HID_EXAMPLE_OSC ) add_subdirectory(hidapi2osc) endif() -if( HID_DEBUG_PARSER OR HID_INSTALL_HUT ) - # provisional to avoid having to commit to sc master while the HID submodule - # is not final/added to master - # the sc-settings for cmake_install_prefix and scappauxresourcesdir are not - # visible in this scope +if( HID_INSTALL_HUT ) if(APPLE) if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) SET(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/Install") diff --git a/hidapi2osc/CMakeLists.txt b/hidapi2osc/CMakeLists.txt index 7967c9c3..7b5b954d 100644 --- a/hidapi2osc/CMakeLists.txt +++ b/hidapi2osc/CMakeLists.txt @@ -4,16 +4,10 @@ include(FindPkgConfig) # pkg_check_modules pkg_check_modules(liblo REQUIRED liblo) -# add_subdirectory( ${hidapi_source} ) - -# message( "osc: hidapi include dirs are: ${hidapi_INCLUDE_DIRS}" ) -# message( "osc: hidapi parser include dirs are: ${hidapi_parser_INCLUDE_DIRS}" ) - include_directories( ${CMAKE_BINARY_DIR} ${liblo_INCLUDE_DIRS} - ${hidapi_SOURCE_DIR}/hidapi/ - ${hidapi_SOURCE_DIR}/hidapi_parser/ + ${CMAKE_SOURCE_DIR}/hidapi_parser/ ) link_directories( @@ -22,8 +16,9 @@ link_directories( ########################################################################## -# sdl2osc +# hidapi2osc ########################################################################## +project(hidapi2osc) set(hidapi2osc_SRCS hidapi2osc.cpp @@ -31,6 +26,6 @@ set(hidapi2osc_SRCS add_executable( hidapi2osc ${hidapi2osc_SRCS} ) -target_link_libraries(hidapi2osc ${liblo_LIBRARIES} ${EXTRA_LIBS} hidapi hidapi_parser m) +target_link_libraries(hidapi2osc ${liblo_LIBRARIES} ${EXTRA_LIBS} hidapi::hidapi hidapi_parser m) install(TARGETS hidapi2osc DESTINATION bin) diff --git a/hidapi_parser/CMakeLists.txt b/hidapi_parser/CMakeLists.txt index 84abdef3..98b7c177 100644 --- a/hidapi_parser/CMakeLists.txt +++ b/hidapi_parser/CMakeLists.txt @@ -1,14 +1,15 @@ message(STATUS " hidapi_parser" ) +project(hidapi_parser) +find_package(hidapi REQUIRED) +option(HID_DEBUG_PARSER "verbose parser debugging output" OFF) +option(HID_PARSER_TEST "install hidparsertest" OFF) +if( HID_DEBUG_PARSER ) + add_definitions( -DDEBUG_PARSER ) +endif() +set(SOURCES hidapi_parser.c) +set(HEADERS hidapi_parser.h) +add_library( hidapi_parser STATIC ${SOURCES} ) -# message( "hidapi parser source dir is: ${hidapi_SOURCE_DIR}" ) -# -# set( hidapi_parser_INCLUDE_DIRS ${hidapi_SOURCE_DIR}/hidapi_parser/) -# # set( hidapi_LIBS ${UDEV_LIBRARIES}) -# set( hidapi_parser_SRCS hidapi_parser.c ) -# -# message( "hidapi_parser include dirs are: ${hidapi_parser_INCLUDE_DIRS}" ) - -include_directories( ${hidapi_SOURCE_DIR}/hidapi/ ) -add_library( hidapi_parser STATIC hidapi_parser.c ) -target_link_libraries( hidapi ) +target_link_libraries(hidapi_parser hidapi::hidapi) +target_include_directories(hidapi_parser PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/hidparsertest/CMakeLists.txt b/hidparsertest/CMakeLists.txt index 2f864358..162935eb 100644 --- a/hidparsertest/CMakeLists.txt +++ b/hidparsertest/CMakeLists.txt @@ -1,13 +1,7 @@ message(STATUS " hidparsertest" ) - -include_directories( - ${CMAKE_BINARY_DIR} - ${hidapi_SOURCE_DIR}/hidapi/ - ${hidapi_SOURCE_DIR}/hidapi_parser/ -) - +include_directories(${CMAKE_SOURCE_DIR}/hidapi_parser/) add_executable( hidparsertest hidparsertest.c ) -target_link_libraries(hidparsertest hidapi hidapi_parser ${EXTRA_LIBS} m) +target_link_libraries(hidparsertest hidapi::hidapi hidapi_parser ${EXTRA_LIBS} m) install(TARGETS hidparsertest DESTINATION bin)