mirror of
https://github.com/RPCS3/hidapi.git
synced 2026-01-31 01:25:21 +01:00
libusb: cmake: Proper dependency on Iconv (#405)
- explicitly add Iconv as a dependent library; - check if iconv requires pointer-to-const as input (introduce ICONV_CONST check); - NetBSD CI (has external Iconv library implementation that uses all of the above);
This commit is contained in:
18
.builds/netbsd.yml
Normal file
18
.builds/netbsd.yml
Normal file
@@ -0,0 +1,18 @@
|
||||
image: netbsd/latest
|
||||
packages:
|
||||
- cmake
|
||||
- pkgconf
|
||||
- libusb1
|
||||
- libiconv
|
||||
sources:
|
||||
- https://github.com/libusb/hidapi
|
||||
tasks:
|
||||
- setup: |
|
||||
cd hidapi
|
||||
mkdir -p build install
|
||||
cmake -B build -S . -DCMAKE_INSTALL_PREFIX=install
|
||||
- build: |
|
||||
cd hidapi/build
|
||||
make
|
||||
make install
|
||||
make clean
|
||||
@@ -19,6 +19,29 @@ endif()
|
||||
find_package(Threads REQUIRED)
|
||||
target_link_libraries(hidapi_libusb PRIVATE Threads::Threads)
|
||||
|
||||
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)
|
||||
include(CheckCSourceCompiles)
|
||||
target_link_libraries(hidapi_libusb PRIVATE Iconv::Iconv)
|
||||
set(CMAKE_REQUIRED_LIBRARIES "Iconv::Iconv")
|
||||
# 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);
|
||||
int main() {}"
|
||||
HIDAPI_ICONV_CONST)
|
||||
if(HIDAPI_ICONV_CONST)
|
||||
target_compile_definitions(hidapi_libusb PRIVATE "ICONV_CONST=const")
|
||||
endif()
|
||||
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
|
||||
PROPERTIES
|
||||
EXPORT_NAME "libusb"
|
||||
|
||||
@@ -44,6 +44,9 @@
|
||||
#include <libusb.h>
|
||||
#if !defined(__ANDROID__) && !defined(NO_ICONV)
|
||||
#include <iconv.h>
|
||||
#ifndef ICONV_CONST
|
||||
#define ICONV_CONST
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include "hidapi_libusb.h"
|
||||
@@ -405,7 +408,7 @@ static wchar_t *get_usb_string(libusb_device_handle *dev, uint8_t idx)
|
||||
size_t inbytes;
|
||||
size_t outbytes;
|
||||
size_t res;
|
||||
char *inptr;
|
||||
ICONV_CONST char *inptr;
|
||||
char *outptr;
|
||||
#endif
|
||||
|
||||
@@ -421,7 +424,7 @@ static wchar_t *get_usb_string(libusb_device_handle *dev, uint8_t idx)
|
||||
lang,
|
||||
(unsigned char*)buf,
|
||||
sizeof(buf));
|
||||
if (len < 0)
|
||||
if (len < 2) /* we always skip first 2 bytes */
|
||||
return NULL;
|
||||
|
||||
#if defined(__ANDROID__) || defined(NO_ICONV)
|
||||
|
||||
@@ -92,6 +92,7 @@ set(EXPORT_COMPONENTS)
|
||||
set(HIDAPI_NEED_EXPORT_THREADS FALSE)
|
||||
set(HIDAPI_NEED_EXPORT_LIBUSB FALSE)
|
||||
set(HIDAPI_NEED_EXPORT_LIBUDEV FALSE)
|
||||
set(HIDAPI_NEED_EXPORT_ICONV FALSE)
|
||||
|
||||
if(WIN32)
|
||||
add_subdirectory("${PROJECT_ROOT}/windows" windows)
|
||||
@@ -128,6 +129,9 @@ else()
|
||||
target_include_directories(hidapi_include INTERFACE
|
||||
"$<BUILD_INTERFACE:${PROJECT_ROOT}/libusb>"
|
||||
)
|
||||
if(NOT DEFINED HIDAPI_NO_ICONV)
|
||||
set(HIDAPI_NO_ICONV OFF)
|
||||
endif()
|
||||
add_subdirectory("${PROJECT_ROOT}/libusb" libusb)
|
||||
list(APPEND EXPORT_COMPONENTS libusb)
|
||||
if(NOT EXPORT_ALIAS)
|
||||
@@ -138,6 +142,9 @@ 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")
|
||||
|
||||
@@ -11,6 +11,7 @@ set(hidapi_FOUND FALSE)
|
||||
set(HIDAPI_NEED_EXPORT_THREADS @HIDAPI_NEED_EXPORT_THREADS@)
|
||||
set(HIDAPI_NEED_EXPORT_LIBUSB @HIDAPI_NEED_EXPORT_LIBUSB@)
|
||||
set(HIDAPI_NEED_EXPORT_LIBUDEV @HIDAPI_NEED_EXPORT_LIBUDEV@)
|
||||
set(HIDAPI_NEED_EXPORT_ICONV @HIDAPI_NEED_EXPORT_ICONV@)
|
||||
|
||||
if(HIDAPI_NEED_EXPORT_THREADS)
|
||||
if(CMAKE_VERSION VERSION_LESS 3.4.3)
|
||||
@@ -32,6 +33,14 @@ if(HIDAPI_NEED_EXPORT_LIBUSB OR HIDAPI_NEED_EXPORT_LIBUDEV)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(HIDAPI_NEED_EXPORT_ICONV)
|
||||
if(CMAKE_VERSION VERSION_LESS 3.11)
|
||||
message(WARNING "HIDAPI requires CMake target Iconv::Iconv, make sure to provide it")
|
||||
else()
|
||||
find_package(Iconv REQUIRED)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/libhidapi.cmake")
|
||||
|
||||
set(hidapi_FOUND TRUE)
|
||||
|
||||
Reference in New Issue
Block a user