From 57c5dfee9f6ef93c7a6db2ce7c28f130c071f41d Mon Sep 17 00:00:00 2001 From: Chad Cassady Date: Thu, 7 Mar 2024 21:17:39 -0600 Subject: [PATCH] it compiles; also addressed a TODO in hidapi_parser.c --- external_libraries/CMakeLists.txt | 9 --------- lang/CMakeLists.txt | 12 ++++++----- lang/hidapi_parser/CMakeLists.txt | 14 ++----------- lang/hidapi_parser/hidapi_parser.c | 3 +-- testsuite/sclang/CMakeLists.txt | 6 ++++++ testsuite/sclang/hidparsertest/CMakeLists.txt | 4 +--- tools/hidapi2osc/CMakeLists.txt | 20 +++---------------- 7 files changed, 20 insertions(+), 48 deletions(-) diff --git a/external_libraries/CMakeLists.txt b/external_libraries/CMakeLists.txt index 029553ba11b..b9875fde795 100644 --- a/external_libraries/CMakeLists.txt +++ b/external_libraries/CMakeLists.txt @@ -141,15 +141,6 @@ endif() set( EXAMPLE_TEST OFF ) set( EXAMPLE_OSC OFF ) -if(SC_HIDAPI) - add_subdirectory(hidapi) - message(STATUS "Building with HID support") -elseif(MINGW AND (${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS 5.3.0)) - message(WARNING "SC is by default built without HID-support if a MinGW/gcc-version below 5.3 is used. Please consult the Readme on how to enable it (easy).") -else() - message(STATUS "HID support disabled") -endif() - if(WIN32) add_library(portmidi portmidi/pm_common/pminternal.h portmidi/pm_common/pmutil.c diff --git a/lang/CMakeLists.txt b/lang/CMakeLists.txt index 0f9f52d0a44..cb1ecfae010 100644 --- a/lang/CMakeLists.txt +++ b/lang/CMakeLists.txt @@ -172,10 +172,8 @@ endif(WIN32) if(SC_HIDAPI) list(APPEND sclang_sources LangPrimSource/SC_HID_api.cpp) - include_directories( - ${CMAKE_SOURCE_DIR}/external_libraries/hidapi/hidapi - ${CMAKE_SOURCE_DIR}/external_libraries/hidapi/hidapi_parser - ) + find_package(hidapi REQUIRED GLOBAL) + add_subdirectory(hidapi_parser) add_definitions(-DSC_HIDAPI) endif(SC_HIDAPI) @@ -231,7 +229,7 @@ endif() if(SC_HIDAPI) target_compile_definitions(libsclang PRIVATE HAVE_HIDAPI) - target_link_libraries( libsclang hidapi hidapi_parser ) + target_link_libraries( libsclang hidapi::hidapi hidapi_parser ) if(${CMAKE_SYSTEM_NAME} MATCHES "Linux" AND HID_HIDRAW) target_link_libraries( libsclang ${UDEV_LIBRARIES}) @@ -239,6 +237,10 @@ if(SC_HIDAPI) if(HID_LIBUSB) target_link_libraries( libsclang ${LIBUSB_1_LIBRARIES}) endif() + + # hidapi2osc + include_directories(${CMAKE_SOURCE_DIR}/tools/hidapi2osc) + endif() target_link_libraries(libsclang boost_thread_lib boost_system_lib boost_regex_lib boost_filesystem_lib) diff --git a/lang/hidapi_parser/CMakeLists.txt b/lang/hidapi_parser/CMakeLists.txt index 84abdef3cbc..54cce513451 100644 --- a/lang/hidapi_parser/CMakeLists.txt +++ b/lang/hidapi_parser/CMakeLists.txt @@ -1,14 +1,4 @@ message(STATUS " hidapi_parser" ) - - -# 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 m) +target_include_directories(hidapi_parser PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/lang/hidapi_parser/hidapi_parser.c b/lang/hidapi_parser/hidapi_parser.c index 32f9ca12a35..dc4bfef0d21 100644 --- a/lang/hidapi_parser/hidapi_parser.c +++ b/lang/hidapi_parser/hidapi_parser.c @@ -748,10 +748,9 @@ float hid_element_map_logical( struct hid_device_element * element ){ return result; } -/** TODO: this needs a linking with the math library */ float hid_element_resolution( struct hid_device_element * element ){ float result = 0; -// result = ( element->logical_max - element->logical_min) / ( ( element->phys_max - element->phys_min) * pow(10, element->unit_exponent) ); + result = ( element->logical_max - element->logical_min) / ( ( element->phys_max - element->phys_min) * pow(10, element->unit_exponent) ); return result; } diff --git a/testsuite/sclang/CMakeLists.txt b/testsuite/sclang/CMakeLists.txt index 5c2cee5f922..580e63b666e 100644 --- a/testsuite/sclang/CMakeLists.txt +++ b/testsuite/sclang/CMakeLists.txt @@ -5,3 +5,9 @@ foreach(test ${tests}) set(test_target ${test_name}_run) add_test(NAME ${test_target} COMMAND sclang -l ${CMAKE_BINARY_DIR}/build_sclang.cfg ${test}) endforeach() + +if(SC_HIDAPI) + add_subdirectory(hidparsertest) + message(STATUS "Building HID tests") +endif() + diff --git a/testsuite/sclang/hidparsertest/CMakeLists.txt b/testsuite/sclang/hidparsertest/CMakeLists.txt index 2f864358e36..f388eca8fb7 100644 --- a/testsuite/sclang/hidparsertest/CMakeLists.txt +++ b/testsuite/sclang/hidparsertest/CMakeLists.txt @@ -2,12 +2,10 @@ message(STATUS " hidparsertest" ) include_directories( ${CMAKE_BINARY_DIR} - ${hidapi_SOURCE_DIR}/hidapi/ - ${hidapi_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) diff --git a/tools/hidapi2osc/CMakeLists.txt b/tools/hidapi2osc/CMakeLists.txt index 7967c9c3bbb..bd994a932bd 100644 --- a/tools/hidapi2osc/CMakeLists.txt +++ b/tools/hidapi2osc/CMakeLists.txt @@ -4,17 +4,7 @@ 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/ -) +find_package(hidapi_parser REQUIRED) link_directories( ${liblo_LIBRARY_DIRS} @@ -22,14 +12,10 @@ link_directories( ########################################################################## -# sdl2osc +# hidapi2osc ########################################################################## -set(hidapi2osc_SRCS - hidapi2osc.cpp -) - -add_executable( hidapi2osc ${hidapi2osc_SRCS} ) +add_executable( hidapi2osc hidapi2osc.cpp) target_link_libraries(hidapi2osc ${liblo_LIBRARIES} ${EXTRA_LIBS} hidapi hidapi_parser m)