From d53ae9b523bfa7573b80a91ced1e3f0bd23fe385 Mon Sep 17 00:00:00 2001 From: Luke Schmitt Date: Tue, 8 Oct 2024 19:04:29 +0000 Subject: [PATCH 01/16] Add general humble workflow --- .github/workflows/humble.yml | 52 ++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 .github/workflows/humble.yml diff --git a/.github/workflows/humble.yml b/.github/workflows/humble.yml new file mode 100644 index 0000000..1a5c405 --- /dev/null +++ b/.github/workflows/humble.yml @@ -0,0 +1,52 @@ +name: build-humble + +on: + push: + branches: + - humble + pull_request: + branches: + - humble + workflow_dispatch: + +# Limit jobs run by PRs or branches by cancelling ongoing jobs +# https://docs.github.com/en/actions/using-jobs/using-concurrency#example-using-concurrency-and-the-default-behavior +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +jobs: + humble: + strategy: + matrix: + env: + - {ROS_DISTRO: humble, ROS_REPO: main} + - {ROS_DISTRO: humble, ROS_REPO: testing} + runs-on: ubuntu-latest + container: ubuntu:jammy + steps: + - uses: actions/checkout@v4 + with: + submodules: recursive + - name: Prepare Workspace + run: | + rm \ + interbotix_ros_common_drivers/COLCON_IGNORE \ + interbotix_ros_xseries/COLCON_IGNORE \ + interbotix_ros_slate/COLCON_IGNORE + - uses: ros-tooling/setup-ros@v0.7 + with: + use-ros2-testing: true + required-ros-distributions: humble + - uses: ros-tooling/action-ros-ci@v0.3 + with: + target-ros2-distro: humble + package-name: + interbotix_footswitch_driver + interbotix_footswitch_msgs + interbotix_ros_slate + interbotix_ros_xseries + interbotix_slate_driver + interbotix_slate_msgs + interbotix_xs_msgs + interbotix_xs_sdk From 1ac8af7b5c3914aae9c5e3460824ff693185ea4b Mon Sep 17 00:00:00 2001 From: Luke Schmitt Date: Tue, 8 Oct 2024 19:05:42 +0000 Subject: [PATCH 02/16] Minor ordering change --- .github/workflows/humble.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/humble.yml b/.github/workflows/humble.yml index 1a5c405..202a1b5 100644 --- a/.github/workflows/humble.yml +++ b/.github/workflows/humble.yml @@ -32,8 +32,8 @@ jobs: run: | rm \ interbotix_ros_common_drivers/COLCON_IGNORE \ - interbotix_ros_xseries/COLCON_IGNORE \ - interbotix_ros_slate/COLCON_IGNORE + interbotix_ros_slate/COLCON_IGNORE \ + interbotix_ros_xseries/COLCON_IGNORE - uses: ros-tooling/setup-ros@v0.7 with: use-ros2-testing: true From 5c975250e29a157384a24d7efc0e475f896e13b3 Mon Sep 17 00:00:00 2001 From: Luke Schmitt Date: Tue, 8 Oct 2024 19:07:16 +0000 Subject: [PATCH 03/16] Fix container --- .github/workflows/humble.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/humble.yml b/.github/workflows/humble.yml index 202a1b5..c50613a 100644 --- a/.github/workflows/humble.yml +++ b/.github/workflows/humble.yml @@ -23,7 +23,8 @@ jobs: - {ROS_DISTRO: humble, ROS_REPO: main} - {ROS_DISTRO: humble, ROS_REPO: testing} runs-on: ubuntu-latest - container: ubuntu:jammy + container: + image: ubuntu:jammy steps: - uses: actions/checkout@v4 with: From 1128df42340e793938643b27804fa994dbfecb51 Mon Sep 17 00:00:00 2001 From: Luke Schmitt Date: Tue, 8 Oct 2024 19:08:59 +0000 Subject: [PATCH 04/16] Run on 22.04, no container --- .github/workflows/humble.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/humble.yml b/.github/workflows/humble.yml index c50613a..95174b2 100644 --- a/.github/workflows/humble.yml +++ b/.github/workflows/humble.yml @@ -22,9 +22,7 @@ jobs: env: - {ROS_DISTRO: humble, ROS_REPO: main} - {ROS_DISTRO: humble, ROS_REPO: testing} - runs-on: ubuntu-latest - container: - image: ubuntu:jammy + runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v4 with: From b56feb82ecc1da0a88a9652c516e804fb977ff24 Mon Sep 17 00:00:00 2001 From: Luke Schmitt Date: Tue, 8 Oct 2024 19:32:18 +0000 Subject: [PATCH 05/16] Use industrial ci instead of ros-tooling --- .github/workflows/humble.yml | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/.github/workflows/humble.yml b/.github/workflows/humble.yml index 95174b2..9cd317d 100644 --- a/.github/workflows/humble.yml +++ b/.github/workflows/humble.yml @@ -33,19 +33,5 @@ jobs: interbotix_ros_common_drivers/COLCON_IGNORE \ interbotix_ros_slate/COLCON_IGNORE \ interbotix_ros_xseries/COLCON_IGNORE - - uses: ros-tooling/setup-ros@v0.7 - with: - use-ros2-testing: true - required-ros-distributions: humble - - uses: ros-tooling/action-ros-ci@v0.3 - with: - target-ros2-distro: humble - package-name: - interbotix_footswitch_driver - interbotix_footswitch_msgs - interbotix_ros_slate - interbotix_ros_xseries - interbotix_slate_driver - interbotix_slate_msgs - interbotix_xs_msgs - interbotix_xs_sdk + - uses: ros-industrial/industrial_ci@master + env: ${{matrix.env}} From 1e42fba7abe80bfa8a0b1a0931ce87109e56992d Mon Sep 17 00:00:00 2001 From: Luke Schmitt Date: Tue, 8 Oct 2024 19:44:13 +0000 Subject: [PATCH 06/16] Install dependencies --- .github/workflows/humble.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/humble.yml b/.github/workflows/humble.yml index 9cd317d..ee36125 100644 --- a/.github/workflows/humble.yml +++ b/.github/workflows/humble.yml @@ -27,6 +27,12 @@ jobs: - uses: actions/checkout@v4 with: submodules: recursive + - name: Install Dependencies + run: | + export DEBIAN_FRONTEND=noninteractive \ + apt-get update \ + && apt-get install -yqq --no-install-recommends \ + libusb-1.0-0-dev - name: Prepare Workspace run: | rm \ From ff9b433a1add0f5f299e627f37902914c8038cfe Mon Sep 17 00:00:00 2001 From: Luke Schmitt Date: Tue, 8 Oct 2024 19:45:40 +0000 Subject: [PATCH 07/16] Fix error --- .github/workflows/humble.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/humble.yml b/.github/workflows/humble.yml index ee36125..382be15 100644 --- a/.github/workflows/humble.yml +++ b/.github/workflows/humble.yml @@ -30,7 +30,7 @@ jobs: - name: Install Dependencies run: | export DEBIAN_FRONTEND=noninteractive \ - apt-get update \ + && apt-get update \ && apt-get install -yqq --no-install-recommends \ libusb-1.0-0-dev - name: Prepare Workspace From b9e828463979a3ff469dfbc1166f052c0ee6b1d6 Mon Sep 17 00:00:00 2001 From: Luke Schmitt Date: Tue, 8 Oct 2024 19:46:28 +0000 Subject: [PATCH 08/16] Use sudo --- .github/workflows/humble.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/humble.yml b/.github/workflows/humble.yml index 382be15..1c0ce19 100644 --- a/.github/workflows/humble.yml +++ b/.github/workflows/humble.yml @@ -30,8 +30,8 @@ jobs: - name: Install Dependencies run: | export DEBIAN_FRONTEND=noninteractive \ - && apt-get update \ - && apt-get install -yqq --no-install-recommends \ + && sudo apt-get update \ + && sudo apt-get install -yqq --no-install-recommends \ libusb-1.0-0-dev - name: Prepare Workspace run: | From b1a326db4272389237d6f33ba7483cf2b18bd90e Mon Sep 17 00:00:00 2001 From: Luke Schmitt Date: Wed, 9 Oct 2024 16:26:45 +0000 Subject: [PATCH 09/16] Update some dependencies --- .github/workflows/humble.yml | 6 ------ .../interbotix_footswitch_driver/package.xml | 1 + 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/.github/workflows/humble.yml b/.github/workflows/humble.yml index 1c0ce19..9cd317d 100644 --- a/.github/workflows/humble.yml +++ b/.github/workflows/humble.yml @@ -27,12 +27,6 @@ jobs: - uses: actions/checkout@v4 with: submodules: recursive - - name: Install Dependencies - run: | - export DEBIAN_FRONTEND=noninteractive \ - && sudo apt-get update \ - && sudo apt-get install -yqq --no-install-recommends \ - libusb-1.0-0-dev - name: Prepare Workspace run: | rm \ diff --git a/interbotix_ros_common_drivers/interbotix_ros_footswitch/interbotix_footswitch_driver/package.xml b/interbotix_ros_common_drivers/interbotix_ros_footswitch/interbotix_footswitch_driver/package.xml index a4c2535..8778e8a 100644 --- a/interbotix_ros_common_drivers/interbotix_ros_footswitch/interbotix_footswitch_driver/package.xml +++ b/interbotix_ros_common_drivers/interbotix_ros_footswitch/interbotix_footswitch_driver/package.xml @@ -15,6 +15,7 @@ ament_cmake interbotix_footswitch_msgs + libusb-1.0 rclcpp_components rclcpp From 6610c186fd60576bdb861bb15a132da6249a6544 Mon Sep 17 00:00:00 2001 From: Luke Schmitt Date: Wed, 9 Oct 2024 16:43:58 +0000 Subject: [PATCH 10/16] Additional dependencies --- .../interbotix_footswitch_driver/package.xml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/interbotix_ros_common_drivers/interbotix_ros_footswitch/interbotix_footswitch_driver/package.xml b/interbotix_ros_common_drivers/interbotix_ros_footswitch/interbotix_footswitch_driver/package.xml index 8778e8a..f4a3942 100644 --- a/interbotix_ros_common_drivers/interbotix_ros_footswitch/interbotix_footswitch_driver/package.xml +++ b/interbotix_ros_common_drivers/interbotix_ros_footswitch/interbotix_footswitch_driver/package.xml @@ -15,7 +15,10 @@ ament_cmake interbotix_footswitch_msgs + libusb-1.0-dev libusb-1.0 + libusb-dev + libusb rclcpp_components rclcpp From 4cf2172d976cd6b034f7f7c15296b3e2d7204b89 Mon Sep 17 00:00:00 2001 From: Luke Schmitt Date: Wed, 9 Oct 2024 16:48:20 +0000 Subject: [PATCH 11/16] Remove (likely unneeded deps) --- .../interbotix_footswitch_driver/package.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/interbotix_ros_common_drivers/interbotix_ros_footswitch/interbotix_footswitch_driver/package.xml b/interbotix_ros_common_drivers/interbotix_ros_footswitch/interbotix_footswitch_driver/package.xml index f4a3942..64035a6 100644 --- a/interbotix_ros_common_drivers/interbotix_ros_footswitch/interbotix_footswitch_driver/package.xml +++ b/interbotix_ros_common_drivers/interbotix_ros_footswitch/interbotix_footswitch_driver/package.xml @@ -16,9 +16,9 @@ interbotix_footswitch_msgs libusb-1.0-dev - libusb-1.0 + rclcpp_components rclcpp From 12dc20976655f46f760b560a43222e87f08601fd Mon Sep 17 00:00:00 2001 From: Luke Schmitt Date: Wed, 9 Oct 2024 16:52:30 +0000 Subject: [PATCH 12/16] Fully remove deps --- .../interbotix_footswitch_driver/package.xml | 3 --- 1 file changed, 3 deletions(-) diff --git a/interbotix_ros_common_drivers/interbotix_ros_footswitch/interbotix_footswitch_driver/package.xml b/interbotix_ros_common_drivers/interbotix_ros_footswitch/interbotix_footswitch_driver/package.xml index 64035a6..902be57 100644 --- a/interbotix_ros_common_drivers/interbotix_ros_footswitch/interbotix_footswitch_driver/package.xml +++ b/interbotix_ros_common_drivers/interbotix_ros_footswitch/interbotix_footswitch_driver/package.xml @@ -16,9 +16,6 @@ interbotix_footswitch_msgs libusb-1.0-dev - rclcpp_components rclcpp From 474401dfc2e7397a9e1eec50c02b2a6bc4557195 Mon Sep 17 00:00:00 2001 From: Luke Schmitt Date: Wed, 9 Oct 2024 17:17:09 +0000 Subject: [PATCH 13/16] Set some hidapi cmake variables --- .../interbotix_footswitch_driver/CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/interbotix_ros_common_drivers/interbotix_ros_footswitch/interbotix_footswitch_driver/CMakeLists.txt b/interbotix_ros_common_drivers/interbotix_ros_footswitch/interbotix_footswitch_driver/CMakeLists.txt index 95d41f4..d3320d4 100644 --- a/interbotix_ros_common_drivers/interbotix_ros_footswitch/interbotix_footswitch_driver/CMakeLists.txt +++ b/interbotix_ros_common_drivers/interbotix_ros_footswitch/interbotix_footswitch_driver/CMakeLists.txt @@ -7,6 +7,11 @@ find_package(rclcpp REQUIRED) find_package(rclcpp_components REQUIRED) find_package(PkgConfig REQUIRED) + +set(HIDAPI_WITH_LIBUSB FALSE) +set(BUILD_SHARED_LIBS FALSE) +set(HIDAPI_PRINT_VERSION ON) +set(HIDAPI_INSTALL_TARGETS ON) add_subdirectory(dependencies/hidapi) include_directories(include) From cd1b321b443c1d7a5ba8811faaedc2c698adab49 Mon Sep 17 00:00:00 2001 From: Luke Schmitt Date: Wed, 9 Oct 2024 19:19:14 +0000 Subject: [PATCH 14/16] Use cmake to find hidapi, libusb --- .../CMakeLists.txt | 24 +- .../cmake/FindHIDAPI.cmake | 232 ++++++++++++++++++ .../cmake/FindLIBUSB.cmake | 153 ++++++++++++ .../cmake/libusb-1.0.cmake | 49 ++++ .../cmake/test-libusb-version.cpp | 53 ++++ .../interbotix_footswitch_driver/package.xml | 1 + 6 files changed, 502 insertions(+), 10 deletions(-) create mode 100644 interbotix_ros_common_drivers/interbotix_ros_footswitch/interbotix_footswitch_driver/cmake/FindHIDAPI.cmake create mode 100644 interbotix_ros_common_drivers/interbotix_ros_footswitch/interbotix_footswitch_driver/cmake/FindLIBUSB.cmake create mode 100644 interbotix_ros_common_drivers/interbotix_ros_footswitch/interbotix_footswitch_driver/cmake/libusb-1.0.cmake create mode 100644 interbotix_ros_common_drivers/interbotix_ros_footswitch/interbotix_footswitch_driver/cmake/test-libusb-version.cpp diff --git a/interbotix_ros_common_drivers/interbotix_ros_footswitch/interbotix_footswitch_driver/CMakeLists.txt b/interbotix_ros_common_drivers/interbotix_ros_footswitch/interbotix_footswitch_driver/CMakeLists.txt index d3320d4..30e3637 100644 --- a/interbotix_ros_common_drivers/interbotix_ros_footswitch/interbotix_footswitch_driver/CMakeLists.txt +++ b/interbotix_ros_common_drivers/interbotix_ros_footswitch/interbotix_footswitch_driver/CMakeLists.txt @@ -1,20 +1,20 @@ cmake_minimum_required(VERSION 3.12.0) project(interbotix_footswitch_driver) +list(INSERT CMAKE_MODULE_PATH 0 "${PROJECT_SOURCE_DIR}/cmake") + find_package(ament_cmake REQUIRED) find_package(interbotix_footswitch_msgs REQUIRED) find_package(rclcpp REQUIRED) find_package(rclcpp_components REQUIRED) +find_package(HIDAPI REQUIRED) +find_package(LIBUSB 1 REQUIRED) -find_package(PkgConfig REQUIRED) - -set(HIDAPI_WITH_LIBUSB FALSE) -set(BUILD_SHARED_LIBS FALSE) -set(HIDAPI_PRINT_VERSION ON) -set(HIDAPI_INSTALL_TARGETS ON) -add_subdirectory(dependencies/hidapi) - -include_directories(include) +include_directories( + include + ${HIDAPI_INCLUDE_DIRS} + ${LibUSB_INCLUDE_DIRS} +) set(ROS_DEPENDENCIES interbotix_footswitch_msgs @@ -27,7 +27,11 @@ add_library(footswitch_driver ) ament_target_dependencies(footswitch_driver ${ROS_DEPENDENCIES}) -target_link_libraries(footswitch_driver hidapi::hidraw) + +target_link_libraries(footswitch_driver + ${LibUSB_LIBRARIES} + ${HIDAPI_LIBRARIES} +) add_executable(footswitch_driver_node src/footswitch_driver_node.cpp diff --git a/interbotix_ros_common_drivers/interbotix_ros_footswitch/interbotix_footswitch_driver/cmake/FindHIDAPI.cmake b/interbotix_ros_common_drivers/interbotix_ros_footswitch/interbotix_footswitch_driver/cmake/FindHIDAPI.cmake new file mode 100644 index 0000000..b77eeaa --- /dev/null +++ b/interbotix_ros_common_drivers/interbotix_ros_footswitch/interbotix_footswitch_driver/cmake/FindHIDAPI.cmake @@ -0,0 +1,232 @@ +#.rst: +# FindHIDAPI +# ---------- +# +# Try to find HIDAPI library, from http://www.signal11.us/oss/hidapi/ +# +# Cache Variables: (probably not for direct use in your scripts) +# HIDAPI_INCLUDE_DIR +# HIDAPI_LIBRARY +# +# Non-cache variables you might use in your CMakeLists.txt: +# HIDAPI_FOUND +# HIDAPI_INCLUDE_DIRS +# HIDAPI_LIBRARIES +# +# COMPONENTS +# ^^^^^^^^^^ +# +# This module respects several COMPONENTS specifying the backend you prefer: +# ``any`` (the default), ``libusb``, and ``hidraw``. +# The availablility of the latter two depends on your platform. +# +# +# IMPORTED Targets +# ^^^^^^^^^^^^^^^^ + +# This module defines :prop_tgt:`IMPORTED` target ``HIDAPI::hidapi`` (in all cases or +# if no components specified), ``HIDAPI::hidapi-libusb`` (if you requested the libusb component), +# and ``HIDAPI::hidapi-hidraw`` (if you requested the hidraw component), +# +# Result Variables +# ^^^^^^^^^^^^^^^^ +# +# ``HIDAPI_FOUND`` +# True if HIDAPI or the requested components (if any) were found. +# +# We recommend using the imported targets instead of the following. +# +# ``HIDAPI_INCLUDE_DIRS`` +# ``HIDAPI_LIBRARIES`` +# +# Original Author: +# 2009-2010, 2019 Ryan Pavlik +# http://academic.cleardefinition.com +# +# Copyright Iowa State University 2009-2010. +# Copyright Collabora, Ltd. 2019. +# Distributed under the Boost Software License, Version 1.0. +# (See accompanying file LICENSE_1_0.txt or copy at +# http://www.boost.org/LICENSE_1_0.txt) + +cmake_policy(SET CMP0045 NEW) +cmake_policy(SET CMP0053 NEW) +cmake_policy(SET CMP0054 NEW) + +set(HIDAPI_ROOT_DIR + "${HIDAPI_ROOT_DIR}" + CACHE PATH "Root to search for HIDAPI") + +# Clean up components +if("${HIDAPI_FIND_COMPONENTS}") + if(WIN32 OR APPLE) + # This makes no sense on Windows or Mac, which have native APIs + list(REMOVE "${HIDAPI_FIND_COMPONENTS}" libusb) + endif() + + if(NOT ${CMAKE_SYSTEM} MATCHES "Linux") + # hidraw is only on linux + list(REMOVE "${HIDAPI_FIND_COMPONENTS}" hidraw) + endif() +endif() +# if(NOT "${HIDAPI_FIND_COMPONENTS}") +# # Default to any +# set("${HIDAPI_FIND_COMPONENTS}" any) +# endif() + +# Ask pkg-config for hints +find_package(PkgConfig QUIET) +if(PKG_CONFIG_FOUND) + set(_old_prefix_path "${CMAKE_PREFIX_PATH}") + # So pkg-config uses HIDAPI_ROOT_DIR too. + if(HIDAPI_ROOT_DIR) + list(APPEND CMAKE_PREFIX_PATH ${HIDAPI_ROOT_DIR}) + endif() + pkg_check_modules(PC_HIDAPI_LIBUSB QUIET hidapi-libusb) + pkg_check_modules(PC_HIDAPI_HIDRAW QUIET hidapi-hidraw) + # Restore + set(CMAKE_PREFIX_PATH "${_old_prefix_path}") +endif() + +# Actually search +find_library( + HIDAPI_UNDECORATED_LIBRARY + NAMES hidapi + PATHS "${HIDAPI_ROOT_DIR}") + +find_library( + HIDAPI_LIBUSB_LIBRARY + NAMES hidapi hidapi-libusb + PATHS "${HIDAPI_ROOT_DIR}" + HINTS ${PC_HIDAPI_LIBUSB_LIBRARY_DIRS}) + +if(CMAKE_SYSTEM MATCHES "Linux") + find_library( + HIDAPI_HIDRAW_LIBRARY + NAMES hidapi-hidraw + HINTS ${PC_HIDAPI_HIDRAW_LIBRARY_DIRS}) +endif() + +find_path( + HIDAPI_INCLUDE_DIR + NAMES hidapi.h + PATHS "${HIDAPI_ROOT_DIR}" + PATH_SUFFIXES hidapi include include/hidapi + HINTS ${PC_HIDAPI_HIDRAW_INCLUDE_DIRS} ${PC_HIDAPI_LIBUSB_INCLUDE_DIRS}) + +find_package(Threads QUIET) + +### +# Compute the "I don't care which backend" library +### +set(HIDAPI_LIBRARY) + +# First, try to use a preferred backend if supplied +if("${HIDAPI_FIND_COMPONENTS}" MATCHES "libusb" + AND HIDAPI_LIBUSB_LIBRARY + AND NOT HIDAPI_LIBRARY) + set(HIDAPI_LIBRARY ${HIDAPI_LIBUSB_LIBRARY}) +endif() +if("${HIDAPI_FIND_COMPONENTS}" MATCHES "hidraw" + AND HIDAPI_HIDRAW_LIBRARY + AND NOT HIDAPI_LIBRARY) + set(HIDAPI_LIBRARY ${HIDAPI_HIDRAW_LIBRARY}) +endif() + +# Then, if we don't have a preferred one, settle for anything. +if(NOT HIDAPI_LIBRARY) + if(HIDAPI_LIBUSB_LIBRARY) + set(HIDAPI_LIBRARY ${HIDAPI_LIBUSB_LIBRARY}) + elseif(HIDAPI_HIDRAW_LIBRARY) + set(HIDAPI_LIBRARY ${HIDAPI_HIDRAW_LIBRARY}) + elseif(HIDAPI_UNDECORATED_LIBRARY) + set(HIDAPI_LIBRARY ${HIDAPI_UNDECORATED_LIBRARY}) + endif() +endif() + +### +# Determine if the various requested components are found. +### +set(_hidapi_component_required_vars) + +foreach(_comp IN LISTS HIDAPI_FIND_COMPONENTS) + if("${_comp}" STREQUAL "any") + list(APPEND _hidapi_component_required_vars HIDAPI_INCLUDE_DIR + HIDAPI_LIBRARY) + if(HIDAPI_INCLUDE_DIR AND EXISTS "${HIDAPI_LIBRARY}") + set(HIDAPI_any_FOUND TRUE) + mark_as_advanced(HIDAPI_INCLUDE_DIR) + else() + set(HIDAPI_any_FOUND FALSE) + endif() + + elseif("${_comp}" STREQUAL "libusb") + list(APPEND _hidapi_component_required_vars HIDAPI_INCLUDE_DIR + HIDAPI_LIBUSB_LIBRARY) + if(HIDAPI_INCLUDE_DIR AND EXISTS "${HIDAPI_LIBUSB_LIBRARY}") + set(HIDAPI_libusb_FOUND TRUE) + mark_as_advanced(HIDAPI_INCLUDE_DIR HIDAPI_LIBUSB_LIBRARY) + else() + set(HIDAPI_libusb_FOUND FALSE) + endif() + + elseif("${_comp}" STREQUAL "hidraw") + list(APPEND _hidapi_component_required_vars HIDAPI_INCLUDE_DIR + HIDAPI_HIDRAW_LIBRARY) + if(HIDAPI_INCLUDE_DIR AND EXISTS "${HIDAPI_HIDRAW_LIBRARY}") + set(HIDAPI_hidraw_FOUND TRUE) + mark_as_advanced(HIDAPI_INCLUDE_DIR HIDAPI_HIDRAW_LIBRARY) + else() + set(HIDAPI_hidraw_FOUND FALSE) + endif() + + else() + message(WARNING "${_comp} is not a recognized HIDAPI component") + set(HIDAPI_${_comp}_FOUND FALSE) + endif() +endforeach() +unset(_comp) + +### +# FPHSA call +### +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args( + HIDAPI REQUIRED_VARS ${_hidapi_component_required_vars} THREADS_FOUND + HANDLE_COMPONENTS) + +if(HIDAPI_FOUND) + set(HIDAPI_LIBRARIES "${HIDAPI_LIBRARY}") + set(HIDAPI_INCLUDE_DIRS "${HIDAPI_INCLUDE_DIR}") + if(NOT TARGET HIDAPI::hidapi) + add_library(HIDAPI::hidapi UNKNOWN IMPORTED) + set_target_properties( + HIDAPI::hidapi + PROPERTIES + IMPORTED_LINK_INTERFACE_LANGUAGES "C" + IMPORTED_LOCATION ${HIDAPI_LIBRARY}) + set_property( + TARGET HIDAPI::hidapi PROPERTY IMPORTED_LINK_INTERFACE_LIBRARIES + Threads::Threads) + endif() +endif() + +if(HIDAPI_libusb_FOUND AND NOT TARGET HIDAPI::hidapi-libusb) + add_library(HIDAPI::hidapi-libusb UNKNOWN IMPORTED) + set_target_properties( + HIDAPI::hidapi-libusb + PROPERTIES IMPORTED_LINK_INTERFACE_LANGUAGES "C" IMPORTED_LOCATION + ${HIDAPI_LIBUSB_LIBRARY}) + set_property(TARGET HIDAPI::hidapi-libusb + PROPERTY IMPORTED_LINK_INTERFACE_LIBRARIES Threads::Threads) +endif() + +if(HIDAPI_hidraw_FOUND AND NOT TARGET HIDAPI::hidapi-hidraw) + add_library(HIDAPI::hidapi-hidraw UNKNOWN IMPORTED) + set_target_properties( + HIDAPI::hidapi-hidraw + PROPERTIES IMPORTED_LINK_INTERFACE_LANGUAGES "C" IMPORTED_LOCATION + ${HIDAPI_HIDRAW_LIBRARY}) + set_property(TARGET HIDAPI::hidapi-hidraw + PROPERTY IMPORTED_LINK_INTERFACE_LIBRARIES Threads::Threads) +endif() diff --git a/interbotix_ros_common_drivers/interbotix_ros_footswitch/interbotix_footswitch_driver/cmake/FindLIBUSB.cmake b/interbotix_ros_common_drivers/interbotix_ros_footswitch/interbotix_footswitch_driver/cmake/FindLIBUSB.cmake new file mode 100644 index 0000000..4e653af --- /dev/null +++ b/interbotix_ros_common_drivers/interbotix_ros_footswitch/interbotix_footswitch_driver/cmake/FindLIBUSB.cmake @@ -0,0 +1,153 @@ +# - Find libusb for portable USB support +# This module will find libusb as published by +# http://libusb.sf.net and +# http://libusb-win32.sf.net +# +# It will use PkgConfig if present and supported, else search +# it on its own. If the LibUSB_ROOT_DIR environment variable +# is defined, it will be used as base path. +# The following standard variables get defined: +# LibUSB_FOUND: true if LibUSB was found +# LibUSB_HEADER_FILE: the location of the C header file +# LibUSB_INCLUDE_DIRS: the directory that contains the include file +# LibUSB_LIBRARIES: the library +# source: https://github.com/IntelRealSense/librealsense + +cmake_policy(SET CMP0045 NEW) +cmake_policy(SET CMP0053 NEW) +cmake_policy(SET CMP0054 NEW) + +include ( CheckLibraryExists ) +include ( CheckIncludeFile ) + +find_package ( PkgConfig ) +if ( PKG_CONFIG_FOUND ) + pkg_check_modules ( PKGCONFIG_LIBUSB libusb-1.0 ) + if ( NOT PKGCONFIG_LIBUSB_FOUND ) + pkg_check_modules ( PKGCONFIG_LIBUSB libusb ) + endif ( NOT PKGCONFIG_LIBUSB_FOUND ) +endif ( PKG_CONFIG_FOUND ) + +if ( PKGCONFIG_LIBUSB_FOUND ) + set ( LibUSB_INCLUDE_DIRS ${PKGCONFIG_LIBUSB_INCLUDE_DIRS} ) + foreach ( i ${PKGCONFIG_LIBUSB_LIBRARIES} ) + string ( REGEX MATCH "[^-]*" ibase "${i}" ) + find_library ( ${ibase}_LIBRARY + NAMES ${i} + PATHS ${PKGCONFIG_LIBUSB_LIBRARY_DIRS} + ) + if ( ${ibase}_LIBRARY ) + list ( APPEND LibUSB_LIBRARIES ${${ibase}_LIBRARY} ) + endif ( ${ibase}_LIBRARY ) + mark_as_advanced ( ${ibase}_LIBRARY ) + endforeach ( i ) + +else ( PKGCONFIG_LIBUSB_FOUND ) + find_file ( LibUSB_HEADER_FILE + NAMES + libusb.h usb.h + PATHS + $ENV{ProgramFiles}/LibUSB-Win32 + $ENV{LibUSB_ROOT_DIR} + PATH_SUFFIXES + include + libusb-1.0 + include/libusb-1.0 + ) + mark_as_advanced ( LibUSB_HEADER_FILE ) + get_filename_component ( LibUSB_INCLUDE_DIRS "${LibUSB_HEADER_FILE}" PATH ) + + if ( ${CMAKE_SYSTEM_NAME} STREQUAL "Windows" ) + # LibUSB-Win32 binary distribution contains several libs. + # Use the lib that got compiled with the same compiler. + if ( MSVC ) + if ( WIN32 ) + set ( LibUSB_LIBRARY_PATH_SUFFIX lib/msvc ) + else ( WIN32 ) + set ( LibUSB_LIBRARY_PATH_SUFFIX lib/msvc_x64 ) + endif ( WIN32 ) + elseif ( BORLAND ) + set ( LibUSB_LIBRARY_PATH_SUFFIX lib/bcc ) + elseif ( CMAKE_COMPILER_IS_GNUCC ) + set ( LibUSB_LIBRARY_PATH_SUFFIX lib/gcc ) + endif ( MSVC ) + endif ( ${CMAKE_SYSTEM_NAME} STREQUAL "Windows" ) + + find_library ( usb_LIBRARY + NAMES + usb-1.0 libusb usb + PATHS + $ENV{ProgramFiles}/LibUSB-Win32 + $ENV{LibUSB_ROOT_DIR} + PATH_SUFFIXES + ${LibUSB_LIBRARY_PATH_SUFFIX} + ) + mark_as_advanced ( usb_LIBRARY ) + if ( usb_LIBRARY ) + set ( LibUSB_LIBRARIES ${usb_LIBRARY} ) + endif ( usb_LIBRARY ) + +endif ( PKGCONFIG_LIBUSB_FOUND ) + +if ( LibUSB_INCLUDE_DIRS AND LibUSB_LIBRARIES ) + set ( LibUSB_FOUND true ) +endif ( LibUSB_INCLUDE_DIRS AND LibUSB_LIBRARIES ) + +if ( LibUSB_FOUND ) + set ( CMAKE_REQUIRED_INCLUDES "${LibUSB_INCLUDE_DIRS}" ) + check_include_file ( "${LibUSB_HEADER_FILE}" LibUSB_FOUND ) +endif ( LibUSB_FOUND ) + +if ( LibUSB_FOUND ) + check_library_exists ( "${LibUSB_LIBRARIES}" usb_open "" LibUSB_FOUND ) + check_library_exists ( "${LibUSB_LIBRARIES}" libusb_get_device_list "" LibUSB_VERSION_1.0 ) + check_library_exists ( "${LibUSB_LIBRARIES}" libusb_get_port_numbers "" LibUSB_VERSION_1.0.16 ) + + if((STATIC AND UNIX AND NOT APPLE) OR (DEPENDS AND CMAKE_SYSTEM_NAME STREQUAL "Linux")) + find_library(LIBUDEV_LIBRARY udev) + if(LIBUDEV_LIBRARY) + set(LibUSB_LIBRARIES "${LibUSB_LIBRARIES};${LIBUDEV_LIBRARY}") + else() + message(WARNING "libudev library not found, binaries may fail to link.") + endif() + endif() + + # Library 1.0.16+ compilation test. + # The check_library_exists does not work well on Apple with shared libs. + if (APPLE OR LibUSB_VERSION_1.0.16 OR STATIC) + if (APPLE) + if(DEPENDS) + list(APPEND TEST_COMPILE_EXTRA_LIBRARIES "-framework Foundation -framework IOKit") + else() + find_library(COREFOUNDATION CoreFoundation) + find_library(IOKIT IOKit) + list(APPEND TEST_COMPILE_EXTRA_LIBRARIES ${IOKIT}) + list(APPEND TEST_COMPILE_EXTRA_LIBRARIES ${COREFOUNDATION}) + endif() + endif() + if (WIN32) + list(APPEND TEST_COMPILE_EXTRA_LIBRARIES setupapi) + endif() + list(APPEND TEST_COMPILE_EXTRA_LIBRARIES ${LibUSB_LIBRARIES}) + + try_compile(LibUSB_COMPILE_TEST_PASSED + ${CMAKE_BINARY_DIR} + "${PROJECT_SOURCE_DIR}/cmake/test-libusb-version.cpp" + CMAKE_FLAGS + "-DINCLUDE_DIRECTORIES=${LibUSB_INCLUDE_DIRS}" + "-DLINK_DIRECTORIES=${LibUSB_LIBRARIES}" + LINK_LIBRARIES ${TEST_COMPILE_EXTRA_LIBRARIES} + OUTPUT_VARIABLE OUTPUT) + unset(TEST_COMPILE_EXTRA_LIBRARIES) + message(STATUS "LibUSB Compilation test: ${LibUSB_COMPILE_TEST_PASSED}") + endif() +endif ( LibUSB_FOUND ) + +if ( NOT LibUSB_FOUND ) + if ( NOT LibUSB_FIND_QUIETLY ) + message ( STATUS "LibUSB not found, try setting LibUSB_ROOT_DIR environment variable." ) + endif ( NOT LibUSB_FIND_QUIETLY ) + if ( LibUSB_FIND_REQUIRED ) + message ( FATAL_ERROR "" ) + endif ( LibUSB_FIND_REQUIRED ) +endif ( NOT LibUSB_FOUND ) diff --git a/interbotix_ros_common_drivers/interbotix_ros_footswitch/interbotix_footswitch_driver/cmake/libusb-1.0.cmake b/interbotix_ros_common_drivers/interbotix_ros_footswitch/interbotix_footswitch_driver/cmake/libusb-1.0.cmake new file mode 100644 index 0000000..0287649 --- /dev/null +++ b/interbotix_ros_common_drivers/interbotix_ros_footswitch/interbotix_footswitch_driver/cmake/libusb-1.0.cmake @@ -0,0 +1,49 @@ +if (LIBUSB_1_LIBRARIES AND LIBUSB_1_INCLUDE_DIRS) + # in cache already + set(LIBUSB_FOUND TRUE) +else (LIBUSB_1_LIBRARIES AND LIBUSB_1_INCLUDE_DIRS) + find_path(LIBUSB_1_INCLUDE_DIR + NAMES +libusb.h + PATHS + /usr/include + /usr/local/include + /sw/include +PATH_SUFFIXES +libusb-1.0 + ) + + find_library(LIBUSB_1_LIBRARY + NAMES + usb-1.0 usb + PATHS + /usr/lib + /usr/local/lib + /sw/lib + /usr/lib/x86_64-linux-gnu + /usr/lib/aarch64-linux-gnu/ + ) + + set(LIBUSB_1_INCLUDE_DIRS ${LIBUSB_1_INCLUDE_DIR} ) + set(LIBUSB_1_LIBRARIES ${LIBUSB_1_LIBRARY}) + + if (LIBUSB_1_INCLUDE_DIRS AND LIBUSB_1_LIBRARIES) + set(LIBUSB_1_FOUND TRUE) + endif (LIBUSB_1_INCLUDE_DIRS AND LIBUSB_1_LIBRARIES) + + if (LIBUSB_1_FOUND) + if (NOT libusb_1_FIND_QUIETLY) + message(STATUS "Found libusb-1.0:") +message(STATUS " - Includes: ${LIBUSB_1_INCLUDE_DIRS}") +message(STATUS " - Libraries: ${LIBUSB_1_LIBRARIES}") + endif (NOT libusb_1_FIND_QUIETLY) + else (LIBUSB_1_FOUND) + if (libusb_1_FIND_REQUIRED) + message(FATAL_ERROR "Could not find libusb") + endif (libusb_1_FIND_REQUIRED) + endif (LIBUSB_1_FOUND) + + # show the LIBUSB_1_INCLUDE_DIRS and LIBUSB_1_LIBRARIES variables only in the advanced view + mark_as_advanced(LIBUSB_1_INCLUDE_DIRS LIBUSB_1_LIBRARIES) + +endif (LIBUSB_1_LIBRARIES AND LIBUSB_1_INCLUDE_DIRS) diff --git a/interbotix_ros_common_drivers/interbotix_ros_footswitch/interbotix_footswitch_driver/cmake/test-libusb-version.cpp b/interbotix_ros_common_drivers/interbotix_ros_footswitch/interbotix_footswitch_driver/cmake/test-libusb-version.cpp new file mode 100644 index 0000000..51e62ed --- /dev/null +++ b/interbotix_ros_common_drivers/interbotix_ros_footswitch/interbotix_footswitch_driver/cmake/test-libusb-version.cpp @@ -0,0 +1,53 @@ +// Copyright (c) 2014-2019, The Monero Project +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, are +// permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, this list of +// conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright notice, this list +// of conditions and the following disclaimer in the documentation and/or other +// materials provided with the distribution. +// +// 3. Neither the name of the copyright holder nor the names of its contributors may be +// used to endorse or promote products derived from this software without specific +// prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY +// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL +// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF +// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#include + +#define UNUSED(expr) (void)(expr) + +int main(int argc, char *argv[]) +{ + libusb_device **devs; + libusb_context *ctx = NULL; + + int r = libusb_init(&ctx); UNUSED(r); + ssize_t cnt = libusb_get_device_list(ctx, &devs); UNUSED(cnt); + + struct libusb_device_descriptor desc; + r = libusb_get_device_descriptor(devs[0], &desc); UNUSED(r); + uint8_t bus_id = libusb_get_bus_number(devs[0]); UNUSED(bus_id); + uint8_t addr = libusb_get_device_address(devs[0]); UNUSED(addr); + + uint8_t tmp_path[16]; + r = libusb_get_port_numbers(devs[0], tmp_path, sizeof(tmp_path)); + UNUSED(r); + UNUSED(tmp_path); + + libusb_free_device_list(devs, 1); + libusb_exit(ctx); +} diff --git a/interbotix_ros_common_drivers/interbotix_ros_footswitch/interbotix_footswitch_driver/package.xml b/interbotix_ros_common_drivers/interbotix_ros_footswitch/interbotix_footswitch_driver/package.xml index 902be57..15e0440 100644 --- a/interbotix_ros_common_drivers/interbotix_ros_footswitch/interbotix_footswitch_driver/package.xml +++ b/interbotix_ros_common_drivers/interbotix_ros_footswitch/interbotix_footswitch_driver/package.xml @@ -15,6 +15,7 @@ ament_cmake interbotix_footswitch_msgs + libhidapi-dev libusb-1.0-dev rclcpp_components rclcpp From 87d7daafcfcf90d168058de4171cf7965ff44e4c Mon Sep 17 00:00:00 2001 From: Luke Schmitt Date: Wed, 9 Oct 2024 20:24:27 +0000 Subject: [PATCH 15/16] Simplify cmake modules --- .../CMakeLists.txt | 2 +- .../cmake/FindHIDAPI.cmake | 2 + .../cmake/FindLIBUSB.cmake | 235 +++++++----------- .../cmake/libusb-1.0.cmake | 49 ---- .../cmake/test-libusb-version.cpp | 53 ---- 5 files changed, 94 insertions(+), 247 deletions(-) delete mode 100644 interbotix_ros_common_drivers/interbotix_ros_footswitch/interbotix_footswitch_driver/cmake/libusb-1.0.cmake delete mode 100644 interbotix_ros_common_drivers/interbotix_ros_footswitch/interbotix_footswitch_driver/cmake/test-libusb-version.cpp diff --git a/interbotix_ros_common_drivers/interbotix_ros_footswitch/interbotix_footswitch_driver/CMakeLists.txt b/interbotix_ros_common_drivers/interbotix_ros_footswitch/interbotix_footswitch_driver/CMakeLists.txt index 30e3637..1fa7c2b 100644 --- a/interbotix_ros_common_drivers/interbotix_ros_footswitch/interbotix_footswitch_driver/CMakeLists.txt +++ b/interbotix_ros_common_drivers/interbotix_ros_footswitch/interbotix_footswitch_driver/CMakeLists.txt @@ -29,8 +29,8 @@ add_library(footswitch_driver ament_target_dependencies(footswitch_driver ${ROS_DEPENDENCIES}) target_link_libraries(footswitch_driver - ${LibUSB_LIBRARIES} ${HIDAPI_LIBRARIES} + ${LibUSB_LIBRARIES} ) add_executable(footswitch_driver_node diff --git a/interbotix_ros_common_drivers/interbotix_ros_footswitch/interbotix_footswitch_driver/cmake/FindHIDAPI.cmake b/interbotix_ros_common_drivers/interbotix_ros_footswitch/interbotix_footswitch_driver/cmake/FindHIDAPI.cmake index b77eeaa..a320ca8 100644 --- a/interbotix_ros_common_drivers/interbotix_ros_footswitch/interbotix_footswitch_driver/cmake/FindHIDAPI.cmake +++ b/interbotix_ros_common_drivers/interbotix_ros_footswitch/interbotix_footswitch_driver/cmake/FindHIDAPI.cmake @@ -1,3 +1,5 @@ +# https://github.com/rpavlik/cmake-modules/blob/1b450496c5d11fdcad8b000843d0c516e1eaa59f/FindHIDAPI.cmake + #.rst: # FindHIDAPI # ---------- diff --git a/interbotix_ros_common_drivers/interbotix_ros_footswitch/interbotix_footswitch_driver/cmake/FindLIBUSB.cmake b/interbotix_ros_common_drivers/interbotix_ros_footswitch/interbotix_footswitch_driver/cmake/FindLIBUSB.cmake index 4e653af..4de4c4c 100644 --- a/interbotix_ros_common_drivers/interbotix_ros_footswitch/interbotix_footswitch_driver/cmake/FindLIBUSB.cmake +++ b/interbotix_ros_common_drivers/interbotix_ros_footswitch/interbotix_footswitch_driver/cmake/FindLIBUSB.cmake @@ -1,153 +1,100 @@ -# - Find libusb for portable USB support -# This module will find libusb as published by -# http://libusb.sf.net and -# http://libusb-win32.sf.net -# -# It will use PkgConfig if present and supported, else search -# it on its own. If the LibUSB_ROOT_DIR environment variable -# is defined, it will be used as base path. -# The following standard variables get defined: -# LibUSB_FOUND: true if LibUSB was found -# LibUSB_HEADER_FILE: the location of the C header file -# LibUSB_INCLUDE_DIRS: the directory that contains the include file -# LibUSB_LIBRARIES: the library -# source: https://github.com/IntelRealSense/librealsense - -cmake_policy(SET CMP0045 NEW) -cmake_policy(SET CMP0053 NEW) -cmake_policy(SET CMP0054 NEW) - -include ( CheckLibraryExists ) -include ( CheckIncludeFile ) - -find_package ( PkgConfig ) -if ( PKG_CONFIG_FOUND ) - pkg_check_modules ( PKGCONFIG_LIBUSB libusb-1.0 ) - if ( NOT PKGCONFIG_LIBUSB_FOUND ) - pkg_check_modules ( PKGCONFIG_LIBUSB libusb ) - endif ( NOT PKGCONFIG_LIBUSB_FOUND ) -endif ( PKG_CONFIG_FOUND ) - -if ( PKGCONFIG_LIBUSB_FOUND ) - set ( LibUSB_INCLUDE_DIRS ${PKGCONFIG_LIBUSB_INCLUDE_DIRS} ) - foreach ( i ${PKGCONFIG_LIBUSB_LIBRARIES} ) - string ( REGEX MATCH "[^-]*" ibase "${i}" ) - find_library ( ${ibase}_LIBRARY - NAMES ${i} - PATHS ${PKGCONFIG_LIBUSB_LIBRARY_DIRS} - ) - if ( ${ibase}_LIBRARY ) - list ( APPEND LibUSB_LIBRARIES ${${ibase}_LIBRARY} ) - endif ( ${ibase}_LIBRARY ) - mark_as_advanced ( ${ibase}_LIBRARY ) - endforeach ( i ) +# https://github.com/ryanbinns/ttwatch/blob/f449ce60818454415a4a667b39654f0e5446a6b3/cmake_modules/FindLibUSB.cmake#L62 -else ( PKGCONFIG_LIBUSB_FOUND ) - find_file ( LibUSB_HEADER_FILE - NAMES - libusb.h usb.h - PATHS - $ENV{ProgramFiles}/LibUSB-Win32 - $ENV{LibUSB_ROOT_DIR} - PATH_SUFFIXES - include - libusb-1.0 - include/libusb-1.0 - ) - mark_as_advanced ( LibUSB_HEADER_FILE ) - get_filename_component ( LibUSB_INCLUDE_DIRS "${LibUSB_HEADER_FILE}" PATH ) - - if ( ${CMAKE_SYSTEM_NAME} STREQUAL "Windows" ) - # LibUSB-Win32 binary distribution contains several libs. - # Use the lib that got compiled with the same compiler. - if ( MSVC ) - if ( WIN32 ) - set ( LibUSB_LIBRARY_PATH_SUFFIX lib/msvc ) - else ( WIN32 ) - set ( LibUSB_LIBRARY_PATH_SUFFIX lib/msvc_x64 ) - endif ( WIN32 ) - elseif ( BORLAND ) - set ( LibUSB_LIBRARY_PATH_SUFFIX lib/bcc ) - elseif ( CMAKE_COMPILER_IS_GNUCC ) - set ( LibUSB_LIBRARY_PATH_SUFFIX lib/gcc ) - endif ( MSVC ) - endif ( ${CMAKE_SYSTEM_NAME} STREQUAL "Windows" ) - - find_library ( usb_LIBRARY - NAMES - usb-1.0 libusb usb - PATHS - $ENV{ProgramFiles}/LibUSB-Win32 - $ENV{LibUSB_ROOT_DIR} - PATH_SUFFIXES - ${LibUSB_LIBRARY_PATH_SUFFIX} - ) - mark_as_advanced ( usb_LIBRARY ) - if ( usb_LIBRARY ) - set ( LibUSB_LIBRARIES ${usb_LIBRARY} ) - endif ( usb_LIBRARY ) +# - Try to find libusb-1.0 +# Once done this will define +# +# LIBUSB_1_FOUND - system has libusb +# LIBUSB_1_INCLUDE_DIRS - the libusb include directory +# LIBUSB_1_LIBRARIES - Link these to use libusb +# LIBUSB_1_DEFINITIONS - Compiler switches required for using libusb +# +# Adapted from cmake-modules Google Code project +# +# Copyright (c) 2006 Andreas Schneider +# +# (Changes for libusb) Copyright (c) 2008 Kyle Machulis +# +# Redistribution and use is allowed according to the terms of the New BSD license. +# +# CMake-Modules Project New BSD License +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# * Neither the name of the CMake-Modules Project nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# -endif ( PKGCONFIG_LIBUSB_FOUND ) -if ( LibUSB_INCLUDE_DIRS AND LibUSB_LIBRARIES ) - set ( LibUSB_FOUND true ) -endif ( LibUSB_INCLUDE_DIRS AND LibUSB_LIBRARIES ) +if (LIBUSB_1_LIBRARIES AND LIBUSB_1_INCLUDE_DIRS) + # in cache already + set(LIBUSB_FOUND TRUE) +else (LIBUSB_1_LIBRARIES AND LIBUSB_1_INCLUDE_DIRS) + find_path(LIBUSB_1_INCLUDE_DIR + NAMES + libusb.h + PATHS + /usr/include + /usr/local/include + /opt/local/include + /sw/include + PATH_SUFFIXES + libusb-1.0 + ) -if ( LibUSB_FOUND ) - set ( CMAKE_REQUIRED_INCLUDES "${LibUSB_INCLUDE_DIRS}" ) - check_include_file ( "${LibUSB_HEADER_FILE}" LibUSB_FOUND ) -endif ( LibUSB_FOUND ) + find_library(LIBUSB_1_LIBRARY + NAMES + usb-1.0 usb + PATHS + /usr/lib + /usr/local/lib + /opt/local/lib + /sw/lib + ) -if ( LibUSB_FOUND ) - check_library_exists ( "${LibUSB_LIBRARIES}" usb_open "" LibUSB_FOUND ) - check_library_exists ( "${LibUSB_LIBRARIES}" libusb_get_device_list "" LibUSB_VERSION_1.0 ) - check_library_exists ( "${LibUSB_LIBRARIES}" libusb_get_port_numbers "" LibUSB_VERSION_1.0.16 ) + set(LIBUSB_1_INCLUDE_DIRS + ${LIBUSB_1_INCLUDE_DIR} + ) + set(LIBUSB_1_LIBRARIES + ${LIBUSB_1_LIBRARY} +) - if((STATIC AND UNIX AND NOT APPLE) OR (DEPENDS AND CMAKE_SYSTEM_NAME STREQUAL "Linux")) - find_library(LIBUDEV_LIBRARY udev) - if(LIBUDEV_LIBRARY) - set(LibUSB_LIBRARIES "${LibUSB_LIBRARIES};${LIBUDEV_LIBRARY}") - else() - message(WARNING "libudev library not found, binaries may fail to link.") - endif() - endif() + if (LIBUSB_1_INCLUDE_DIRS AND LIBUSB_1_LIBRARIES) + set(LIBUSB_1_FOUND TRUE) + endif (LIBUSB_1_INCLUDE_DIRS AND LIBUSB_1_LIBRARIES) - # Library 1.0.16+ compilation test. - # The check_library_exists does not work well on Apple with shared libs. - if (APPLE OR LibUSB_VERSION_1.0.16 OR STATIC) - if (APPLE) - if(DEPENDS) - list(APPEND TEST_COMPILE_EXTRA_LIBRARIES "-framework Foundation -framework IOKit") - else() - find_library(COREFOUNDATION CoreFoundation) - find_library(IOKIT IOKit) - list(APPEND TEST_COMPILE_EXTRA_LIBRARIES ${IOKIT}) - list(APPEND TEST_COMPILE_EXTRA_LIBRARIES ${COREFOUNDATION}) - endif() - endif() - if (WIN32) - list(APPEND TEST_COMPILE_EXTRA_LIBRARIES setupapi) - endif() - list(APPEND TEST_COMPILE_EXTRA_LIBRARIES ${LibUSB_LIBRARIES}) + if (LIBUSB_1_FOUND) + if (NOT libusb_1_FIND_QUIETLY) + message(STATUS "Found libusb-1.0:") + message(STATUS " - Includes: ${LIBUSB_1_INCLUDE_DIRS}") + message(STATUS " - Libraries: ${LIBUSB_1_LIBRARIES}") + endif (NOT libusb_1_FIND_QUIETLY) + else (LIBUSB_1_FOUND) + if (libusb_1_FIND_REQUIRED) + message(FATAL_ERROR "Could not find libusb") + endif (libusb_1_FIND_REQUIRED) + endif (LIBUSB_1_FOUND) - try_compile(LibUSB_COMPILE_TEST_PASSED - ${CMAKE_BINARY_DIR} - "${PROJECT_SOURCE_DIR}/cmake/test-libusb-version.cpp" - CMAKE_FLAGS - "-DINCLUDE_DIRECTORIES=${LibUSB_INCLUDE_DIRS}" - "-DLINK_DIRECTORIES=${LibUSB_LIBRARIES}" - LINK_LIBRARIES ${TEST_COMPILE_EXTRA_LIBRARIES} - OUTPUT_VARIABLE OUTPUT) - unset(TEST_COMPILE_EXTRA_LIBRARIES) - message(STATUS "LibUSB Compilation test: ${LibUSB_COMPILE_TEST_PASSED}") - endif() -endif ( LibUSB_FOUND ) + # show the LIBUSB_1_INCLUDE_DIRS and LIBUSB_1_LIBRARIES variables only in the advanced view + mark_as_advanced(LIBUSB_1_INCLUDE_DIRS LIBUSB_1_LIBRARIES) -if ( NOT LibUSB_FOUND ) - if ( NOT LibUSB_FIND_QUIETLY ) - message ( STATUS "LibUSB not found, try setting LibUSB_ROOT_DIR environment variable." ) - endif ( NOT LibUSB_FIND_QUIETLY ) - if ( LibUSB_FIND_REQUIRED ) - message ( FATAL_ERROR "" ) - endif ( LibUSB_FIND_REQUIRED ) -endif ( NOT LibUSB_FOUND ) +endif (LIBUSB_1_LIBRARIES AND LIBUSB_1_INCLUDE_DIRS) diff --git a/interbotix_ros_common_drivers/interbotix_ros_footswitch/interbotix_footswitch_driver/cmake/libusb-1.0.cmake b/interbotix_ros_common_drivers/interbotix_ros_footswitch/interbotix_footswitch_driver/cmake/libusb-1.0.cmake deleted file mode 100644 index 0287649..0000000 --- a/interbotix_ros_common_drivers/interbotix_ros_footswitch/interbotix_footswitch_driver/cmake/libusb-1.0.cmake +++ /dev/null @@ -1,49 +0,0 @@ -if (LIBUSB_1_LIBRARIES AND LIBUSB_1_INCLUDE_DIRS) - # in cache already - set(LIBUSB_FOUND TRUE) -else (LIBUSB_1_LIBRARIES AND LIBUSB_1_INCLUDE_DIRS) - find_path(LIBUSB_1_INCLUDE_DIR - NAMES -libusb.h - PATHS - /usr/include - /usr/local/include - /sw/include -PATH_SUFFIXES -libusb-1.0 - ) - - find_library(LIBUSB_1_LIBRARY - NAMES - usb-1.0 usb - PATHS - /usr/lib - /usr/local/lib - /sw/lib - /usr/lib/x86_64-linux-gnu - /usr/lib/aarch64-linux-gnu/ - ) - - set(LIBUSB_1_INCLUDE_DIRS ${LIBUSB_1_INCLUDE_DIR} ) - set(LIBUSB_1_LIBRARIES ${LIBUSB_1_LIBRARY}) - - if (LIBUSB_1_INCLUDE_DIRS AND LIBUSB_1_LIBRARIES) - set(LIBUSB_1_FOUND TRUE) - endif (LIBUSB_1_INCLUDE_DIRS AND LIBUSB_1_LIBRARIES) - - if (LIBUSB_1_FOUND) - if (NOT libusb_1_FIND_QUIETLY) - message(STATUS "Found libusb-1.0:") -message(STATUS " - Includes: ${LIBUSB_1_INCLUDE_DIRS}") -message(STATUS " - Libraries: ${LIBUSB_1_LIBRARIES}") - endif (NOT libusb_1_FIND_QUIETLY) - else (LIBUSB_1_FOUND) - if (libusb_1_FIND_REQUIRED) - message(FATAL_ERROR "Could not find libusb") - endif (libusb_1_FIND_REQUIRED) - endif (LIBUSB_1_FOUND) - - # show the LIBUSB_1_INCLUDE_DIRS and LIBUSB_1_LIBRARIES variables only in the advanced view - mark_as_advanced(LIBUSB_1_INCLUDE_DIRS LIBUSB_1_LIBRARIES) - -endif (LIBUSB_1_LIBRARIES AND LIBUSB_1_INCLUDE_DIRS) diff --git a/interbotix_ros_common_drivers/interbotix_ros_footswitch/interbotix_footswitch_driver/cmake/test-libusb-version.cpp b/interbotix_ros_common_drivers/interbotix_ros_footswitch/interbotix_footswitch_driver/cmake/test-libusb-version.cpp deleted file mode 100644 index 51e62ed..0000000 --- a/interbotix_ros_common_drivers/interbotix_ros_footswitch/interbotix_footswitch_driver/cmake/test-libusb-version.cpp +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright (c) 2014-2019, The Monero Project -// -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without modification, are -// permitted provided that the following conditions are met: -// -// 1. Redistributions of source code must retain the above copyright notice, this list of -// conditions and the following disclaimer. -// -// 2. Redistributions in binary form must reproduce the above copyright notice, this list -// of conditions and the following disclaimer in the documentation and/or other -// materials provided with the distribution. -// -// 3. Neither the name of the copyright holder nor the names of its contributors may be -// used to endorse or promote products derived from this software without specific -// prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY -// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL -// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF -// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -#include - -#define UNUSED(expr) (void)(expr) - -int main(int argc, char *argv[]) -{ - libusb_device **devs; - libusb_context *ctx = NULL; - - int r = libusb_init(&ctx); UNUSED(r); - ssize_t cnt = libusb_get_device_list(ctx, &devs); UNUSED(cnt); - - struct libusb_device_descriptor desc; - r = libusb_get_device_descriptor(devs[0], &desc); UNUSED(r); - uint8_t bus_id = libusb_get_bus_number(devs[0]); UNUSED(bus_id); - uint8_t addr = libusb_get_device_address(devs[0]); UNUSED(addr); - - uint8_t tmp_path[16]; - r = libusb_get_port_numbers(devs[0], tmp_path, sizeof(tmp_path)); - UNUSED(r); - UNUSED(tmp_path); - - libusb_free_device_list(devs, 1); - libusb_exit(ctx); -} From b72a4d946d70ad7600a15d2147f899793cd736f9 Mon Sep 17 00:00:00 2001 From: Luke Schmitt Date: Wed, 9 Oct 2024 20:26:58 +0000 Subject: [PATCH 16/16] Remove now-unused hidapi submodule --- .gitmodules | 3 --- .../interbotix_footswitch_driver/dependencies/hidapi | 1 - 2 files changed, 4 deletions(-) delete mode 160000 interbotix_ros_common_drivers/interbotix_ros_footswitch/interbotix_footswitch_driver/dependencies/hidapi diff --git a/.gitmodules b/.gitmodules index f903e94..e49f002 100644 --- a/.gitmodules +++ b/.gitmodules @@ -6,6 +6,3 @@ path = interbotix_ros_xseries/interbotix_xs_driver url = https://github.com/Interbotix/interbotix_xs_driver.git branch = v0.3.3 -[submodule "interbotix_ros_common_drivers/interbotix_ros_footswitch/interbotix_footswitch_driver/dependencies/hidapi"] - path = interbotix_ros_common_drivers/interbotix_ros_footswitch/interbotix_footswitch_driver/dependencies/hidapi - url = https://github.com/libusb/hidapi.git diff --git a/interbotix_ros_common_drivers/interbotix_ros_footswitch/interbotix_footswitch_driver/dependencies/hidapi b/interbotix_ros_common_drivers/interbotix_ros_footswitch/interbotix_footswitch_driver/dependencies/hidapi deleted file mode 160000 index 6c2de30..0000000 --- a/interbotix_ros_common_drivers/interbotix_ros_footswitch/interbotix_footswitch_driver/dependencies/hidapi +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 6c2de304317d2e48c463399e0401ae6e406cd7c6