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
12 changes: 11 additions & 1 deletion .github/workflows/builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ jobs:
- name: Install dependencies
run: |
sudo apt update
sudo apt install libudev-dev libusb-1.0-0-dev python3-pip ninja-build
sudo apt install autoconf automake libudev-dev libusb-1.0-0-dev pkg-config python3-pip ninja-build
sudo -H pip3 install meson
- name: Configure CMake
run: |
Expand All @@ -138,6 +138,15 @@ jobs:
- name: Build CMake Static
working-directory: build/static
run: make install
- name: Check pkg-config package
run: |
autoreconf --install --force hidapisrc/tests/pkg-config
mkdir -p build/pkg-config-test
cd build/pkg-config-test
CFLAGS="${GNU_COMPILE_FLAGS}" \
PKG_CONFIG_PATH="${GITHUB_WORKSPACE}/install/shared/lib/pkgconfig" \
"${GITHUB_WORKSPACE}/hidapisrc/tests/pkg-config/configure"
make V=1
- name: Run virtual-device tests (uhid -> hidraw; raw-gadget self-skips)
working-directory: build/shared
run: |
Expand All @@ -156,6 +165,7 @@ jobs:
with:
files: "install/shared/lib/libhidapi-libusb.so, \
install/shared/lib/libhidapi-hidraw.so, \
install/shared/lib/pkgconfig/hidapi.pc, \
install/shared/include/hidapi/hidapi.h, \
install/shared/include/hidapi/hidapi_libusb.h, \
install/static/lib/libhidapi-libusb.a, \
Expand Down
33 changes: 29 additions & 4 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,30 @@ else
pkgconfigdir=$(libdir)/pkgconfig
endif

if OS_LINUX
pkgconfig_DATA=pc/hidapi-hidraw.pc pc/hidapi-libusb.pc
else
pkgconfig_DATA=pc/hidapi.pc

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

if OS_DARWIN
pkgconfig_DATA += pc/hidapi-darwin.pc
endif

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

if OS_KFREEBSD
pkgconfig_DATA += pc/hidapi-libusb.pc
endif

if OS_HAIKU
pkgconfig_DATA += pc/hidapi-libusb.pc
endif

if OS_WINDOWS
pkgconfig_DATA += pc/hidapi-winapi.pc
endif

SUBDIRS=
Expand Down Expand Up @@ -45,7 +65,12 @@ if BUILD_TESTGUI
SUBDIRS += testgui
endif

EXTRA_DIST = udev doxygen
EXTRA_DIST = \
udev \
doxygen \
tests/pkg-config/configure.ac \
tests/pkg-config/Makefile.am \
tests/pkg-config/test.c

dist_doc_DATA = \
README.md \
Expand Down
48 changes: 44 additions & 4 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -237,12 +237,52 @@ AM_CONDITIONAL(OS_WINDOWS, test "x$os" = xwindows)

AC_CONFIG_HEADERS([config.h])

m4_define([HIDAPI_CONFIGURE_BACKEND_PC], [
AC_CONFIG_FILES([$1:pc/hidapi-backend-specific.pc.in], [
sed \
-e "s|@HIDAPI_BACKEND_NAME@|$2|g" \
-e "s|@HIDAPI_BACKEND_DESCRIPTION@|$3|g" \
-e "s|@HIDAPI_BACKEND_LIBRARY_NAME@|$4|g" \
"$1" > "$1.tmp" &&
mv "$1.tmp" "$1"
], [$5])
])

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

AC_SUBST(LTLDFLAGS)

Expand Down
6 changes: 5 additions & 1 deletion libusb/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,8 @@ if(HIDAPI_INSTALL_TARGETS)
)
endif()

hidapi_configure_pc("${PROJECT_ROOT}/pc/hidapi-libusb.pc.in")
hidapi_configure_pc("${PROJECT_ROOT}/pc/hidapi-backend-specific.pc.in"
OUTPUT_NAME "hidapi-libusb"
LIBRARY_NAME "hidapi-libusb"
DESCRIPTION "C Library for USB HID device access from Linux, Mac OS X, FreeBSD, and Windows. This is the libusb implementation."
)
6 changes: 5 additions & 1 deletion linux/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,8 @@ if(HIDAPI_INSTALL_TARGETS)
)
endif()

hidapi_configure_pc("${PROJECT_ROOT}/pc/hidapi-hidraw.pc.in")
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."
)
6 changes: 5 additions & 1 deletion mac/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,8 @@ if(HIDAPI_INSTALL_TARGETS)
)
endif()

hidapi_configure_pc("${PROJECT_ROOT}/pc/hidapi.pc.in")
hidapi_configure_pc("${PROJECT_ROOT}/pc/hidapi-backend-specific.pc.in"
OUTPUT_NAME "hidapi-darwin"
LIBRARY_NAME "hidapi"
DESCRIPTION "C Library for USB/Bluetooth HID device access from Linux, Mac OS X, FreeBSD, and Windows. This is the Darwin implementation."
)
6 changes: 5 additions & 1 deletion netbsd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,8 @@ if(HIDAPI_INSTALL_TARGETS)
)
endif()

hidapi_configure_pc("${PROJECT_ROOT}/pc/hidapi-netbsd.pc.in")
hidapi_configure_pc("${PROJECT_ROOT}/pc/hidapi-backend-specific.pc.in"
OUTPUT_NAME "hidapi-netbsd"
LIBRARY_NAME "hidapi-netbsd"
DESCRIPTION "C Library for USB/Bluetooth HID device access from Linux, Mac OS X, FreeBSD, and Windows. This is the netbsd implementation."
)
1 change: 1 addition & 0 deletions pc/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
*.pc
*.pc.tmp
11 changes: 11 additions & 0 deletions pc/hidapi-backend-specific.pc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
prefix=@prefix@
exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@

Name: @HIDAPI_BACKEND_NAME@
Description: @HIDAPI_BACKEND_DESCRIPTION@
URL: https://github.com/libusb/hidapi
Version: @VERSION@
Libs: -L${libdir} -l@HIDAPI_BACKEND_LIBRARY_NAME@
Cflags: -I${includedir}/hidapi
11 changes: 0 additions & 11 deletions pc/hidapi-hidraw.pc.in

This file was deleted.

11 changes: 0 additions & 11 deletions pc/hidapi-libusb.pc.in

This file was deleted.

11 changes: 0 additions & 11 deletions pc/hidapi-netbsd.pc.in

This file was deleted.

2 changes: 1 addition & 1 deletion pc/hidapi.pc.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ Name: hidapi
Description: C Library for USB/Bluetooth HID device access from Linux, Mac OS X, FreeBSD, and Windows.
URL: https://github.com/libusb/hidapi
Version: @VERSION@
Libs: -L${libdir} -lhidapi
Libs: -L${libdir} -l@HIDAPI_LIB_NAME@
Cflags: -I${includedir}/hidapi
21 changes: 20 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,16 @@ endif()
# Helper(s)

function(hidapi_configure_pc PC_IN_FILE)
set(oneValueArgs OUTPUT_NAME LIBRARY_NAME DESCRIPTION)
cmake_parse_arguments(HIDAPI_PC "" "${oneValueArgs}" "" ${ARGN})
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/pc")

set(VERSION "${VERSION}${VERSION_SUFFIX}")
if(HIDAPI_PC_LIBRARY_NAME)
set(HIDAPI_LIB_NAME "${HIDAPI_PC_LIBRARY_NAME}")
else()
set(HIDAPI_LIB_NAME "hidapi")
endif()
set(prefix "${CMAKE_INSTALL_PREFIX}")
set(exec_prefix "\${prefix}")
if(IS_ABSOLUTE "${CMAKE_INSTALL_LIBDIR}")
Expand All @@ -71,7 +78,14 @@ function(hidapi_configure_pc PC_IN_FILE)
set(includedir "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}")
endif()

get_filename_component(PC_IN_FILENAME "${PC_IN_FILE}" NAME_WE)
if(HIDAPI_PC_OUTPUT_NAME)
set(PC_IN_FILENAME "${HIDAPI_PC_OUTPUT_NAME}")
else()
get_filename_component(PC_IN_FILENAME "${PC_IN_FILE}" NAME_WE)
endif()
set(HIDAPI_BACKEND_NAME "${PC_IN_FILENAME}")
set(HIDAPI_BACKEND_DESCRIPTION "${HIDAPI_PC_DESCRIPTION}")
set(HIDAPI_BACKEND_LIBRARY_NAME "${HIDAPI_LIB_NAME}")
set(PC_FILE "${CMAKE_CURRENT_BINARY_DIR}/pc/${PC_IN_FILENAME}.pc")
configure_file("${PC_IN_FILE}" "${PC_FILE}" @ONLY)
if(HIDAPI_INSTALL_TARGETS)
Expand Down Expand Up @@ -187,6 +201,11 @@ endif()

add_library(hidapi::hidapi ALIAS hidapi_${EXPORT_ALIAS})

get_target_property(HIDAPI_LIB_NAME hidapi_${EXPORT_ALIAS} OUTPUT_NAME)
hidapi_configure_pc("${PROJECT_ROOT}/pc/hidapi.pc.in"
LIBRARY_NAME "${HIDAPI_LIB_NAME}"
)

if(HIDAPI_INSTALL_TARGETS)
include(CMakePackageConfigHelpers)
set(EXPORT_DENERATED_LOCATION "${CMAKE_BINARY_DIR}/export_generated")
Expand Down
5 changes: 5 additions & 0 deletions tests/pkg-config/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
noinst_PROGRAMS = hidapi-pkg-config-test

hidapi_pkg_config_test_SOURCES = test.c
hidapi_pkg_config_test_CPPFLAGS = $(HIDAPI_CFLAGS)
hidapi_pkg_config_test_LDADD = $(HIDAPI_LIBS)
11 changes: 11 additions & 0 deletions tests/pkg-config/configure.ac
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
AC_PREREQ([2.69])
AC_INIT([hidapi-pkg-config-test], [1.0])
AC_CONFIG_SRCDIR([test.c])
AM_INIT_AUTOMAKE([foreign])

AC_PROG_CC
PKG_PROG_PKG_CONFIG
PKG_CHECK_MODULES([HIDAPI], [hidapi])

AC_CONFIG_FILES([Makefile])
AC_OUTPUT
6 changes: 6 additions & 0 deletions tests/pkg-config/test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <hidapi.h>

int main(void)
{
return hid_version() ? 0 : 1;
}
6 changes: 5 additions & 1 deletion windows/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ if(HIDAPI_INSTALL_TARGETS)
)
endif()

hidapi_configure_pc("${PROJECT_ROOT}/pc/hidapi.pc.in")
hidapi_configure_pc("${PROJECT_ROOT}/pc/hidapi-backend-specific.pc.in"
OUTPUT_NAME "hidapi-winapi"
LIBRARY_NAME "hidapi"
DESCRIPTION "C Library for USB/Bluetooth HID device access from Linux, Mac OS X, FreeBSD, and Windows. This is the WinAPI implementation."
)

if(HIDAPI_WITH_TESTS)
add_subdirectory(test)
Expand Down
Loading