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
2 changes: 1 addition & 1 deletion .cirrus.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
alpine_task:
container:
image: alpine:latest
install_script: apk add autoconf automake g++ gcc libusb-dev libtool linux-headers eudev-dev make musl-dev
install_script: apk add autoconf automake g++ gcc libusb-dev libtool linux-headers eudev-libs make musl-dev
script:
- ./bootstrap
- ./configure || { cat config.log; exit 1; }
Expand Down
21 changes: 15 additions & 6 deletions .github/workflows/builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -125,19 +125,22 @@ jobs:
- name: Install dependencies
run: |
sudo apt update
sudo apt install autoconf automake libudev-dev libusb-1.0-0-dev pkg-config python3-pip ninja-build
sudo apt install autoconf automake libudev1 libusb-1.0-0-dev pkg-config python3-pip ninja-build
sudo -H pip3 install meson
- name: Configure CMake
run: |
rm -rf build install
cmake -B build/shared -S hidapisrc -DCMAKE_BUILD_TYPE=RelWithDebInfo -DHIDAPI_ENABLE_ASAN=ON -DCMAKE_INSTALL_PREFIX=install/shared -DHIDAPI_BUILD_HIDTEST=ON -DHIDAPI_WITH_TESTS=ON "-DCMAKE_C_FLAGS=${GNU_COMPILE_FLAGS}"
cmake -B build/static -S hidapisrc -DCMAKE_BUILD_TYPE=RelWithDebInfo -DHIDAPI_ENABLE_ASAN=ON -DCMAKE_INSTALL_PREFIX=install/static -DBUILD_SHARED_LIBS=FALSE -DHIDAPI_BUILD_HIDTEST=ON "-DCMAKE_C_FLAGS=${GNU_COMPILE_FLAGS}"
cmake -B build/shared -S hidapisrc -DCMAKE_BUILD_TYPE=RelWithDebInfo -DHIDAPI_ENABLE_ASAN=ON -DHIDAPI_WITH_TESTS=ON -DCMAKE_INSTALL_PREFIX=install/shared -DHIDAPI_BUILD_HIDTEST=ON "-DCMAKE_C_FLAGS=${GNU_COMPILE_FLAGS}"
cmake -B build/static -S hidapisrc -DCMAKE_BUILD_TYPE=RelWithDebInfo -DHIDAPI_ENABLE_ASAN=ON -DHIDAPI_WITH_TESTS=ON -DCMAKE_INSTALL_PREFIX=install/static -DBUILD_SHARED_LIBS=FALSE -DHIDAPI_BUILD_HIDTEST=ON "-DCMAKE_C_FLAGS=${GNU_COMPILE_FLAGS}"
- name: Build CMake Shared
working-directory: build/shared
run: make install
- name: Build CMake Static
working-directory: build/static
run: make install
- name: Test CMake Static
working-directory: build/static
run: ctest --output-on-failure
- name: Check pkg-config package
run: |
autoreconf --install --force hidapisrc/tests/pkg-config
Expand Down Expand Up @@ -581,12 +584,12 @@ jobs:
path: hidapisrc
- name: Install dependencies
run: |
apk add gcc musl-dev autoconf automake libtool eudev-dev libusb-dev linux-headers cmake ninja make
apk add gcc musl-dev autoconf automake libtool eudev-libs libusb-dev linux-headers cmake ninja make
- name: Configure CMake
run: |
rm -rf build install
cmake -B build/shared-cmake -S hidapisrc -GNinja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_INSTALL_PREFIX=install/shared-cmake -DHIDAPI_BUILD_HIDTEST=ON "-DCMAKE_C_FLAGS=${ALPINE_COMPILE_FLAGS}"
cmake -B build/static-cmake -S hidapisrc -GNinja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_INSTALL_PREFIX=install/static-cmake -DBUILD_SHARED_LIBS=FALSE -DHIDAPI_BUILD_HIDTEST=ON "-DCMAKE_C_FLAGS=${ALPINE_COMPILE_FLAGS}"
cmake -B build/shared-cmake -S hidapisrc -GNinja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DHIDAPI_WITH_TESTS=ON -DCMAKE_INSTALL_PREFIX=install/shared-cmake -DHIDAPI_BUILD_HIDTEST=ON "-DCMAKE_C_FLAGS=${ALPINE_COMPILE_FLAGS}"
cmake -B build/static-cmake -S hidapisrc -GNinja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DHIDAPI_WITH_TESTS=ON -DCMAKE_INSTALL_PREFIX=install/static-cmake -DBUILD_SHARED_LIBS=FALSE -DHIDAPI_BUILD_HIDTEST=ON "-DCMAKE_C_FLAGS=${ALPINE_COMPILE_FLAGS}"
- name: Configure Automake
working-directory: hidapisrc
run: |
Expand All @@ -595,9 +598,15 @@ jobs:
- name: Build CMake Shared
working-directory: build/shared-cmake
run: ninja install
- name: Test CMake Shared
working-directory: build/shared-cmake
run: ctest --output-on-failure
- name: Build CMake Static
working-directory: build/static-cmake
run: ninja install
- name: Test CMake Static
working-directory: build/static-cmake
run: ctest --output-on-failure
- name: Build Automake
working-directory: hidapisrc
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ jobs:
- name: Install dependencies
run: |
sudo apt update
sudo apt install libudev-dev libusb-1.0-0-dev ninja-build
sudo apt install libudev1 libusb-1.0-0-dev ninja-build
- name: Configure
run: |
cmake -B build -S src -GNinja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DHIDAPI_WITH_TESTS=ON -DHIDAPI_BUILD_HIDTEST=ON -DCMAKE_C_COMPILER=gcc
Expand Down
10 changes: 5 additions & 5 deletions BUILD.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ Regardless of what build system you choose to use, there are specific dependenci
### Linux:

Depending on which backend you're going to build, you'll need to install
additional development packages. For `linux/hidraw` backend, you need a
development package for `libudev`. For `libusb` backend, naturally, you need
`libusb` development package.
additional packages. The `linux/hidraw` backend loads `libudev` dynamically,
so it only needs the runtime library. The `libusb` backend needs the `libusb`
development package.

On Debian/Ubuntu systems these can be installed by running:
```sh
# required only by hidraw backend
sudo apt install libudev-dev
# required at runtime by the hidraw backend
sudo apt install libudev1
# required only by libusb backend
sudo apt install libusb-1.0-0-dev
```
Expand Down
29 changes: 22 additions & 7 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ PKG_PROG_PKG_CONFIG

m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])

HIDAPI_HIDRAW_PRIVATE_LIBS=

hidapi_lib_error() {
echo ""
echo " Library $1 was not found on this system."
Expand Down Expand Up @@ -57,9 +59,13 @@ case $host in
threads="pthreads"

# HIDAPI/hidraw libs
PKG_CHECK_MODULES([libudev], [libudev], true, [hidapi_lib_error libudev])
LIBS_HIDRAW_PR="${LIBS_HIDRAW_PR} $libudev_LIBS"
CFLAGS_HIDRAW="${CFLAGS_HIDRAW} $libudev_CFLAGS"
hidapi_saved_LIBS="$LIBS"
AC_SEARCH_LIBS([dlopen], [dl], [], [hidapi_lib_error libdl])
if test "x$ac_cv_search_dlopen" != "xnone required"; then
LIBS_HIDRAW_PR="${LIBS_HIDRAW_PR} ${ac_cv_search_dlopen}"
HIDAPI_HIDRAW_PRIVATE_LIBS="${ac_cv_search_dlopen}"
fi
LIBS="$hidapi_saved_LIBS"

# HIDAPI/libusb libs
AC_CHECK_LIB([rt], [clock_gettime], [LIBS_LIBUSB_PRIVATE="${LIBS_LIBUSB_PRIVATE} -lrt"], [hidapi_lib_error librt])
Expand Down Expand Up @@ -243,45 +249,54 @@ 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_PRIVATE_LIBS@|$5|g" \
"$1" > "$1.tmp" &&
mv "$1.tmp" "$1"
], [$5])
], [$6])
])

HIDAPI_LIB_NAME=hidapi
HIDAPI_LIBUSB_LIB_NAME=hidapi
HIDAPI_PRIVATE_LIBS=
if test "x$os" = "xlinux"; then
HIDAPI_LIB_NAME=hidapi-hidraw
HIDAPI_LIBUSB_LIB_NAME=hidapi-libusb
HIDAPI_PRIVATE_LIBS="$HIDAPI_HIDRAW_PRIVATE_LIBS"
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_PRIVATE_LIBS],
[HIDAPI_HIDRAW_PRIVATE_LIBS="$HIDAPI_HIDRAW_PRIVATE_LIBS"])
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_PRIVATE_LIBS])
AC_CONFIG_FILES([pc/hidapi.pc])

AC_SUBST(LTLDFLAGS)
Expand Down
10 changes: 6 additions & 4 deletions linux/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ target_link_libraries(hidapi_hidraw PUBLIC hidapi_include)

find_package(Threads REQUIRED)

include(FindPkgConfig)
pkg_check_modules(libudev REQUIRED IMPORTED_TARGET libudev)
Comment thread
Youw marked this conversation as resolved.

target_link_libraries(hidapi_hidraw PRIVATE PkgConfig::libudev Threads::Threads)
target_link_libraries(hidapi_hidraw PRIVATE Threads::Threads ${CMAKE_DL_LIBS})

set_target_properties(hidapi_hidraw
PROPERTIES
Expand All @@ -28,6 +25,10 @@ add_library(hidapi::hidraw ALIAS hidapi_hidraw)
# compatibility with raw library link
add_library(hidapi-hidraw ALIAS hidapi_hidraw)

if(HIDAPI_WITH_TESTS)
add_subdirectory(test)
endif()

if(HIDAPI_INSTALL_TARGETS)
install(TARGETS hidapi_hidraw EXPORT hidapi
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
Expand All @@ -40,4 +41,5 @@ 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."
PRIVATE_LIBS "-ldl"
)
9 changes: 4 additions & 5 deletions linux/Makefile-manual
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,17 @@ LDFLAGS ?= -Wall -g

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


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

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

# Objects
$(COBJS): %.o: %.c
Expand Down
7 changes: 6 additions & 1 deletion linux/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,9 @@ libhidapi_hidraw_la_LIBADD = $(LIBS_HIDRAW)
hdrdir = $(includedir)/hidapi
hdr_HEADERS = $(top_srcdir)/hidapi/hidapi.h

EXTRA_DIST = Makefile-manual
EXTRA_DIST = \
Makefile-manual \
test/CMakeLists.txt \
test/dlopen_interposer.c \
test/hidapi_hidraw_loader_test.c \
test/incomplete_udev.c
Loading
Loading