Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 7 additions & 13 deletions libs/hidapi/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,26 @@
include $(TOPDIR)/rules.mk

PKG_NAME:=hidapi
PKG_VERSION:=0.10.1
PKG_VERSION:=0.12.0
PKG_RELEASE:=$(AUTORELEASE)

PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=https://codeload.github.com/libusb/hidapi/tar.gz/$(PKG_NAME)-$(PKG_VERSION)?
PKG_HASH:=f71dd8a1f46979c17ee521bc2117573872bbf040f8a4750e492271fc141f2644
PKG_HASH:=28ec1451f0527ad40c1a4c92547966ffef96813528c8b184a665f03ecbb508bc
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_NAME)-$(PKG_VERSION)

PKG_MAINTAINER:=Paul Fertser <fercerpav@gmail.com>
PKG_LICENSE:=BSD-3-Clause
PKG_LICENSE_FILES:=LICENSE-bsd.txt

PKG_FIXUP:=autoreconf
PKG_INSTALL:=1
PKG_BUILD_PARALLEL:=1

include $(INCLUDE_DIR)/package.mk
include $(INCLUDE_DIR)/nls.mk
include $(INCLUDE_DIR)/cmake.mk

define Package/hidapi
SECTION:=libs
CATEGORY:=Libraries
DEPENDS:=+libusb-1.0 +librt +libudev $(ICONV_DEPENDS)
DEPENDS:=+libusb-1.0 +libudev $(ICONV_DEPENDS)
TITLE:=Library to talk to HID devices
URL:=https://github.com/libusb/hidapi
endef
Expand All @@ -43,19 +40,16 @@ can be embedded directly into a target application by adding a single source
file (per platform) and a single header.
endef

CONFIGURE_ARGS += \
--disable-static

TARGET_LDFLAGS += -liconv

define Build/InstallDev
$(INSTALL_DIR) $(1)/usr/include/hidapi
$(CP) $(PKG_INSTALL_DIR)/usr/include/hidapi/hidapi.h $(1)/usr/include/hidapi/
$(CP) $(PKG_INSTALL_DIR)/usr/include/hidapi/hidapi_libusb.h $(1)/usr/include/hidapi/
$(INSTALL_DIR) $(1)/usr/lib
$(CP) $(PKG_INSTALL_DIR)/usr/lib/libhidapi-hidraw.so* $(1)/usr/lib/
$(CP) $(PKG_INSTALL_DIR)/usr/lib//libhidapi-libusb.so* $(1)/usr/lib/
$(CP) $(PKG_INSTALL_DIR)/usr/lib/libhidapi-libusb.so* $(1)/usr/lib/
$(INSTALL_DIR) $(1)/usr/lib/pkgconfig/
$(CP) $(PKG_INSTALL_DIR)/usr/lib/pkgconfig/hidapi-libusb.pc $(1)/usr/lib/pkgconfig/
$(CP) $(PKG_INSTALL_DIR)/usr/lib/pkgconfig/hidapi-hidraw.pc $(1)/usr/lib/pkgconfig/
endef

define Package/hidapi/install
Expand Down
100 changes: 100 additions & 0 deletions libs/hidapi/patches/020-iconv.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
From cfcddf90ea6add9d4aaa99ee2decc5a9140bdf37 Mon Sep 17 00:00:00 2001
From: Ihor Dutchak <ihor.youw@gmail.com>
Date: Sat, 18 Jun 2022 15:58:31 +0300
Subject: [PATCH 1/3] Ensure Iconv is found when provided via CFLAGS/LDFLAGS

- by default find_file/find_library doesn't respect CFLAGS/LDFLAGS,
and FindIconv fails to find Iconv;
- by explicitly trying to link against `-liconv` - we're checking if library is available in such way;
- additionally: if Iconv is detected as BUILT_IN, no need to explicitly depend on `Iconv::Iconv`;
---
libusb/CMakeLists.txt | 41 +++++++++++++++++++++++++++++++++--------
src/CMakeLists.txt | 3 ---
2 files changed, 33 insertions(+), 11 deletions(-)

--- a/libusb/CMakeLists.txt
+++ b/libusb/CMakeLists.txt
@@ -22,11 +22,53 @@ target_link_libraries(hidapi_libusb PRIV
if(HIDAPI_NO_ICONV)
target_compile_definitions(hidapi_libusb PRIVATE NO_ICONV)
else()
- if(NOT ANDROID AND NOT CMAKE_VERSION VERSION_LESS 3.11)
- find_package(Iconv REQUIRED)
+ if(NOT ANDROID)
include(CheckCSourceCompiles)
- target_link_libraries(hidapi_libusb PRIVATE Iconv::Iconv)
- set(CMAKE_REQUIRED_LIBRARIES "Iconv::Iconv")
+
+ if(NOT CMAKE_VERSION VERSION_LESS 3.11)
+ message(STATUS "Check for Iconv")
+ find_package(Iconv)
+ if(Iconv_FOUND)
+ if(NOT Iconv_IS_BUILT_IN)
+ target_link_libraries(hidapi_libusb PRIVATE Iconv::Iconv)
+ set(CMAKE_REQUIRED_LIBRARIES "Iconv::Iconv")
+ if(NOT BUILD_SHARED_LIBS)
+ set(HIDAPI_NEED_EXPORT_ICONV TRUE PARENT_SCOPE)
+ endif()
+ endif()
+ else()
+ message(STATUS "Iconv Explicitly check '-liconv'")
+ # Sometime the build environment is not setup
+ # in a way CMake can find Iconv on its own by default.
+ # But if we simply link against iconv (-liconv), the build may succeed
+ # due to other compiler/link flags.
+ set(CMAKE_REQUIRED_LIBRARIES "iconv")
+ check_c_source_compiles("
+ #include <stddef.h>
+ #include <iconv.h>
+ int main() {
+ char *a, *b;
+ size_t i, j;
+ iconv_t ic;
+ ic = iconv_open(\"to\", \"from\");
+ iconv(ic, &a, &i, &b, &j);
+ iconv_close(ic);
+ }
+ "
+ Iconv_EXPLICITLY_AT_ENV)
+ if(Iconv_EXPLICITLY_AT_ENV)
+ message(STATUS "Iconv Explicitly check '-liconv' - Available")
+ target_link_libraries(hidapi_libusb PRIVATE iconv)
+ else()
+ message(FATAL_ERROR "Iconv is not found, make sure to provide it in the build environment")
+ endif()
+ endif()
+ else()
+ # otherwise there is 2 options:
+ # 1) iconv is provided by Standard C library and the build will be just fine
+ # 2) The _user_ has to provide additiona compilation options for this project/target
+ endif()
+
# check for error: "conflicting types for 'iconv'"
check_c_source_compiles("#include<iconv.h>
extern size_t iconv (iconv_t cd, const char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft);
@@ -35,11 +77,9 @@ else()
if(HIDAPI_ICONV_CONST)
target_compile_definitions(hidapi_libusb PRIVATE "ICONV_CONST=const")
endif()
+ else()
+ # On Android Iconv is disabled on the code level anyway, so no issue;
endif()
- # otherwise there is 3 options:
- # 1) On Android Iconv is disabled on the code level anyway, so no issue;
- # 2) iconv is provided by Standard C library and the build will be just fine;
- # 4) The _user_ has to provide additiona compilation options for this project/target.
endif()

set_target_properties(hidapi_libusb
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -148,9 +148,6 @@ else()
if(NOT TARGET usb-1.0)
set(HIDAPI_NEED_EXPORT_LIBUSB TRUE)
endif()
- if(NOT HIDAPI_NO_ICONV AND NOT ANDROID AND NOT CMAKE_VERSION VERSION_LESS 3.11)
- set(HIDAPI_NEED_EXPORT_ICONV TRUE)
- endif()
endif()
elseif(NOT TARGET hidapi_hidraw)
message(FATAL_ERROR "Select at least one option to build: HIDAPI_WITH_LIBUSB or HIDAPI_WITH_HIDRAW")