Skip to content
Open
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
66 changes: 57 additions & 9 deletions .builds/freebsd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ packages:
- libtool
- pkgconf
- cmake
- meson
- ninja
sources:
- https://github.com/libusb/hidapi
Expand All @@ -15,20 +16,67 @@ tasks:
cd hidapi
echo Configure Autotools build
./bootstrap
./configure
./configure \
--prefix="$PWD/install_autotools"
echo Configure CMake build
mkdir -p build install_cmake
cmake -GNinja -B build -S . -DCMAKE_INSTALL_PREFIX=install_cmake
cmake -GNinja -B build/shared -S . \
-DCMAKE_INSTALL_PREFIX="$PWD/install_cmake/shared" \
-DHIDAPI_BUILD_HIDTEST=ON
cmake -GNinja -B build/static -S . \
-DCMAKE_INSTALL_PREFIX="$PWD/install_cmake/static" \
-DBUILD_SHARED_LIBS=FALSE \
-DHIDAPI_BUILD_HIDTEST=ON
cmake -GNinja -B build/cxx -S . \
-DCMAKE_BUILD_TYPE=Release \
-DHIDAPI_BUILD_AS_CXX=ON \
"-DCMAKE_CXX_FLAGS=-Wall -Wextra -Werror"
meson setup build/meson
- build-autotools: |
cd hidapi
make
make DESTDIR=$PWD/root install
make install
export PKG_CONFIG_PATH="$PWD/install_autotools/libdata/pkgconfig"
export LD_LIBRARY_PATH="$PWD/install_autotools/lib"
for package in hidapi hidapi-hidraw; do
cc -Wall -Wextra -Werror \
$(pkg-config --cflags "$package") \
tests/pkg-config/test.c \
-o "build/$package-pkg-config-test" \
$(pkg-config --static --libs "$package")
"./build/$package-pkg-config-test"
done
cc -Wall -Wextra -Werror \
$(pkg-config --cflags hidapi-libusb) \
tests/pkg-config/test.c \
-o build/hidapi-libusb-pkg-config-test \
$(pkg-config --libs hidapi-libusb)
./build/hidapi-libusb-pkg-config-test
make clean
- build-cmake: |
cd hidapi/build
ninja
ninja install
ninja clean
cd hidapi
cmake --build build/shared --target install
cmake --build build/static --target install
cmake --build build/cxx
cmake -GNinja -B build/shared_test -S hidtest \
-Dhidapi_ROOT="$PWD/install_cmake/shared" \
-DCMAKE_INSTALL_PREFIX="$PWD/install_cmake/shared_test"
cmake --build build/shared_test --target install
cmake -GNinja -B build/static_test -S hidtest \
-Dhidapi_ROOT="$PWD/install_cmake/static" \
-DCMAKE_INSTALL_PREFIX="$PWD/install_cmake/static_test"
cmake --build build/static_test --target install
test -x install_cmake/shared_test/bin/hidtest_hidraw
test -x install_cmake/shared_test/bin/hidtest_libusb
test -x install_cmake/static_test/bin/hidtest_hidraw
test -x install_cmake/static_test/bin/hidtest_libusb
cmake --build build/shared --target clean
cmake --build build/static --target clean
cmake --build build/cxx --target clean
- build-meson: |
cd hidapi
meson compile -C build/meson
- build-manual: |
cd hidapi/libusb
cd hidapi/freebsd
gmake -f Makefile-manual
cd ../libusb
gmake -f Makefile-manual
16 changes: 2 additions & 14 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,9 @@ alpine_task:
- make
- make install

freebsd11_task:
freebsd_task:
freebsd_instance:
image: freebsd-11-2-release-amd64
install_script:
- pkg install -y
autoconf automake libiconv libtool pkgconf
script:
- ./bootstrap
- ./configure || { cat config.log; exit 1; }
- make
- make install

freebsd12_task:
freebsd_instance:
image: freebsd-12-1-release-amd64
image_family: freebsd-14-3
install_script:
- pkg install -y
autoconf automake libiconv libtool pkgconf
Expand Down
10 changes: 5 additions & 5 deletions BUILD.cmake.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ HIDAPI-specific CMake variables:
currently this option is only available on Windows, since only Windows backend has tests;

<details>
<summary>Linux-specific variables</summary>
<summary>Linux and FreeBSD-specific variables</summary>

- `HIDAPI_WITH_HIDRAW` - when set to TRUE, build HIDRAW-based implementation of HIDAPI (`hidapi-hidraw`), otherwise don't build it; defaults to TRUE;
- `HIDAPI_WITH_LIBUSB` - when set to TRUE, build LIBUSB-based implementation of HIDAPI (`hidapi-libusb`), otherwise don't build it; defaults to TRUE;
Expand Down Expand Up @@ -149,10 +149,10 @@ Available CMake targets after successful `find_package(hidapi)`:
- `hidapi::winapi` - same as `hidapi::hidapi` on Windows; available only on Windows;
- `hidapi::darwin` - same as `hidapi::hidapi` on macOS; available only on macOS;
- `hidapi::libusb` - available when libusb backend is used/available;
- `hidapi::hidraw` - available when hidraw backend is used/available on Linux;
- `hidapi::hidraw` - available when hidraw backend is used/available on Linux or FreeBSD;

**NOTE**: on Linux often both `hidapi::libusb` and `hidapi::hidraw` backends are available; in that case `hidapi::hidapi` is an alias for **`hidapi::hidraw`**. The motivation is that `hidraw` backend is a native Linux kernel implementation of HID protocol, and supports various HID devices (USB, Bluetooth, I2C, etc.). If `hidraw` backend isn't built at all (`hidapi::libusb` is the only target) - `hidapi::hidapi` is an alias for `hidapi::libusb`.
If you're developing a cross-platform application and you are sure you need to use `libusb` backend on Linux, the simple way to achieve this is:
**NOTE**: on Linux and FreeBSD often both `hidapi::libusb` and `hidapi::hidraw` backends are available; in that case `hidapi::hidapi` is an alias for **`hidapi::hidraw`**. The motivation is that `hidraw` is the native kernel HID implementation and supports various HID devices (USB, Bluetooth, I2C, etc.). If `hidraw` backend isn't built at all (`hidapi::libusb` is the only target) - `hidapi::hidapi` is an alias for `hidapi::libusb`.
If you're developing a cross-platform application and you are sure you need to use `libusb` backend on Linux or FreeBSD, the simple way to achieve this is:
```cmake
if(TARGET hidapi::libusb)
target_link_libraries(my_project PRIVATE hidapi::libusb)
Expand Down Expand Up @@ -183,7 +183,7 @@ Lets call this "larger project" a "host project".

All of the variables described in [standalone build](#standalone-package-build) section can be used to control HIDAPI build in case of a subdirectory, e.g.:
```cmake
set(HIDAPI_WITH_LIBUSB FALSE) # surely will be used only on Linux
set(HIDAPI_WITH_LIBUSB FALSE) # used only on Linux and FreeBSD
set(BUILD_SHARED_LIBS FALSE) # HIDAPI as static library on all platforms
add_subdirectory(hidapi)
```
Expand Down
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ elseif(NOT WIN32)
option(HIDAPI_WITH_HIDRAW "Build HIDRAW-based implementation of HIDAPI" ON)
option(HIDAPI_WITH_LIBUSB "Build LIBUSB-based implementation of HIDAPI" ON)
endif()
if(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
option(HIDAPI_WITH_HIDRAW "Build HIDRAW-based implementation of HIDAPI" ON)
option(HIDAPI_WITH_LIBUSB "Build LIBUSB-based implementation of HIDAPI" ON)
endif()
if(CMAKE_SYSTEM_NAME MATCHES "NetBSD")
option(HIDAPI_WITH_NETBSD "Build NetBSD/UHID implementation of HIDAPI" ON)
endif()
Expand Down
5 changes: 3 additions & 2 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pkgconfig_DATA += pc/hidapi-darwin.pc
endif

if OS_FREEBSD
pkgconfig_DATA += pc/hidapi-libusb.pc
pkgconfig_DATA += pc/hidapi-hidraw.pc pc/hidapi-libusb.pc
endif

if OS_KFREEBSD
Expand All @@ -44,7 +44,7 @@ SUBDIRS += mac
endif

if OS_FREEBSD
SUBDIRS += libusb
SUBDIRS += freebsd libusb
endif

if OS_KFREEBSD
Expand Down Expand Up @@ -95,6 +95,7 @@ SCMCLEAN_TARGETS= \
libusb/Makefile.in \
Makefile.in \
linux/Makefile.in \
freebsd/Makefile.in \
windows/Makefile.in \
m4/libtool.m4 \
m4/lt~obsolete.m4 \
Expand Down
30 changes: 24 additions & 6 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,18 @@ case $host in
AC_MSG_RESULT([ (FreeBSD back-end)])
AC_DEFINE(OS_FREEBSD, 1, [FreeBSD implementation])
AC_SUBST(OS_FREEBSD)
backend="libusb"
backend="freebsd"
os="freebsd"
threads="pthreads"

CFLAGS="$CFLAGS -I/usr/local/include"
LDFLAGS="$LDFLAGS -L/usr/local/lib"
LIBS="${LIBS}"
PKG_CHECK_MODULES([libusb], [libusb-1.0 >= 1.0.9], true, [hidapi_lib_error libusb-1.0])
# HIDAPI/hidraw libs
LIBS_HIDRAW_PR="${LIBS_HIDRAW_PR} $libusb_LIBS"
CFLAGS_HIDRAW="${CFLAGS_HIDRAW} $libusb_CFLAGS"
# HIDAPI/libusb libs
LIBS_LIBUSB_PRIVATE="${LIBS_LIBUSB_PRIVATE} $libusb_LIBS"
CFLAGS_LIBUSB="${CFLAGS_LIBUSB} $libusb_CFLAGS"
AC_CHECK_LIB([iconv], [iconv_open], [LIBS_LIBUSB_PRIVATE="${LIBS_LIBUSB_PRIVATE} -liconv"], [hidapi_lib_error libiconv])
Expand Down Expand Up @@ -243,45 +247,58 @@ m4_define([HIDAPI_CONFIGURE_BACKEND_PC], [
-e "s|@HIDAPI_BACKEND_NAME@|$2|g" \
-e "s|@HIDAPI_BACKEND_DESCRIPTION@|$3|g" \
-e "s|@HIDAPI_BACKEND_LIBRARY_NAME@|$4|g" \
-e "s|@HIDAPI_BACKEND_REQUIRES_PRIVATE@|$5|g" \
"$1" > "$1.tmp" &&
mv "$1.tmp" "$1"
], [$5])
], [$6])
])

HIDAPI_LIB_NAME=hidapi
HIDAPI_LIBUSB_LIB_NAME=hidapi
if test "x$os" = "xlinux"; then
HIDAPI_GENERIC_REQUIRES_PRIVATE=
HIDAPI_HIDRAW_REQUIRES_PRIVATE=
if test "x$os" = "xlinux" || test "x$os" = "xfreebsd"; then
HIDAPI_LIB_NAME=hidapi-hidraw
HIDAPI_LIBUSB_LIB_NAME=hidapi-libusb
if test "x$os" = "xfreebsd"; then
HIDAPI_GENERIC_REQUIRES_PRIVATE="Requires.private: libusb-1.0 >= 1.0.9"
HIDAPI_HIDRAW_REQUIRES_PRIVATE="$HIDAPI_GENERIC_REQUIRES_PRIVATE"
fi
HIDAPI_CONFIGURE_BACKEND_PC(
[pc/hidapi-hidraw.pc],
[hidapi-hidraw],
[C Library for USB/Bluetooth HID device access from Linux, Mac OS X, FreeBSD, and Windows. This is the hidraw implementation.],
[hidapi-hidraw])
[hidapi-hidraw],
[$hidapi_hidraw_requires_private],
[hidapi_hidraw_requires_private="$HIDAPI_HIDRAW_REQUIRES_PRIVATE"])
elif test "x$os" = "xdarwin"; then
HIDAPI_CONFIGURE_BACKEND_PC(
[pc/hidapi-darwin.pc],
[hidapi-darwin],
[C Library for USB/Bluetooth HID device access from Linux, Mac OS X, FreeBSD, and Windows. This is the Darwin implementation.],
[hidapi])
[hidapi],
[])
elif test "x$os" = "xwindows"; then
HIDAPI_CONFIGURE_BACKEND_PC(
[pc/hidapi-winapi.pc],
[hidapi-winapi],
[C Library for USB/Bluetooth HID device access from Linux, Mac OS X, FreeBSD, and Windows. This is the WinAPI implementation.],
[hidapi])
[hidapi],
[])
fi
if test "x$os" != "xdarwin" && test "x$os" != "xwindows"; then
HIDAPI_CONFIGURE_BACKEND_PC(
[pc/hidapi-libusb.pc],
[hidapi-libusb],
[C Library for USB HID device access from Linux, Mac OS X, FreeBSD, and Windows. This is the libusb implementation.],
[$hidapi_libusb_lib_name],
[],
[hidapi_libusb_lib_name="$HIDAPI_LIBUSB_LIB_NAME"])
fi
m4_undefine([HIDAPI_CONFIGURE_BACKEND_PC])

AC_SUBST([HIDAPI_LIB_NAME])
AC_SUBST([HIDAPI_GENERIC_REQUIRES_PRIVATE])
AC_CONFIG_FILES([pc/hidapi.pc])

AC_SUBST(LTLDFLAGS)
Expand All @@ -290,6 +307,7 @@ AC_CONFIG_FILES([Makefile \
hidtest/Makefile \
libusb/Makefile \
linux/Makefile \
freebsd/Makefile \
mac/Makefile \
testgui/Makefile \
windows/Makefile])
Expand Down
18 changes: 18 additions & 0 deletions freebsd/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Debug
Release
*.exp
*.ilk
*.lib
*.suo
*.vcproj.*
*.ncb
*.suo
*.dll
*.pdb
*.o
*.so
hidtest-hidraw
.deps
.libs
*.lo
*.la
46 changes: 46 additions & 0 deletions freebsd/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
cmake_minimum_required(VERSION 3.6.3...3.25 FATAL_ERROR)

add_library(hidapi_hidraw
${HIDAPI_PUBLIC_HEADERS}
hid.c
)
if(HIDAPI_BUILD_AS_CXX)
set_source_files_properties(hid.c PROPERTIES LANGUAGE CXX)
endif()
target_link_libraries(hidapi_hidraw PUBLIC hidapi_include)

find_package(Threads REQUIRED)

include(FindPkgConfig)
pkg_check_modules(libusb REQUIRED IMPORTED_TARGET libusb-1.0>=1.0.9)

target_link_libraries(hidapi_hidraw PRIVATE PkgConfig::libusb Threads::Threads)

set_target_properties(hidapi_hidraw
PROPERTIES
EXPORT_NAME "hidraw"
OUTPUT_NAME "hidapi-hidraw"
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR}
PUBLIC_HEADER "${HIDAPI_PUBLIC_HEADERS}"
)

# compatibility with find_package()
add_library(hidapi::hidraw ALIAS hidapi_hidraw)
# compatibility with raw library link
add_library(hidapi-hidraw ALIAS hidapi_hidraw)

if(HIDAPI_INSTALL_TARGETS)
install(TARGETS hidapi_hidraw EXPORT hidapi
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/hidapi"
)
endif()

hidapi_configure_pc("${PROJECT_ROOT}/pc/hidapi-backend-specific.pc.in"
OUTPUT_NAME "hidapi-hidraw"
LIBRARY_NAME "hidapi-hidraw"
DESCRIPTION "C Library for USB/Bluetooth HID device access from Linux, Mac OS X, FreeBSD, and Windows. This is the hidraw implementation."
REQUIRES_PRIVATE "libusb-1.0 >= 1.0.9"
)
42 changes: 42 additions & 0 deletions freebsd/Makefile-manual
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
###########################################
# Simple Makefile for HIDAPI test program
#
# Alan Ott
# Signal 11 Software
# 2010-06-01
###########################################

all: hidtest-hidraw libs

libs: libhidapi-hidraw.so

CC ?= gcc
CFLAGS ?= -Wall -g -fpic

LDFLAGS ?= -Wall -g


COBJS = hid.o ../hidtest/test.o
OBJS = $(COBJS)
LIBS_USB = `pkg-config libusb-1.0 --libs`
LIBS = $(LIBS_USB)
INCLUDES ?= -I../hidapi `pkg-config libusb-1.0 --cflags`


# Console Test Program
hidtest-hidraw: $(COBJS)
$(CC) $(LDFLAGS) $^ $(LIBS_USB) -o $@

# Shared Libs
libhidapi-hidraw.so: $(COBJS)
$(CC) $(LDFLAGS) $(LIBS_USB) -shared -fpic -Wl,-soname,$@.0 $^ -o $@

# Objects
$(COBJS): %.o: %.c
$(CC) $(CFLAGS) -c $(INCLUDES) $< -o $@


clean:
rm -f $(OBJS) hidtest-hidraw libhidapi-hidraw.so $(COBJS)

.PHONY: clean libs
10 changes: 10 additions & 0 deletions freebsd/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
lib_LTLIBRARIES = libhidapi-hidraw.la
libhidapi_hidraw_la_SOURCES = hid.c
libhidapi_hidraw_la_LDFLAGS = $(LTLDFLAGS)
AM_CPPFLAGS = -I$(top_srcdir)/hidapi/ $(CFLAGS_HIDRAW)
libhidapi_hidraw_la_LIBADD = $(LIBS_HIDRAW)

hdrdir = $(includedir)/hidapi
hdr_HEADERS = $(top_srcdir)/hidapi/hidapi.h

EXTRA_DIST = Makefile-manual
Loading
Loading