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
1 change: 1 addition & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ m4_undefine([HIDAPI_CONFIGURE_BACKEND_PC])

AC_SUBST([HIDAPI_LIB_NAME])
AC_SUBST([HIDAPI_GENERIC_REQUIRES_PRIVATE])
AC_SUBST([HIDAPI_PC_LIBS_PRIVATE_FIELD], [])

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this is for build compatibility, but it is not really populated properly for autotools.
If so - that's fine, but just to confirm it verbally.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirming, after running both build systems on Linux: this line only keeps the Autotools output valid, it does not populate anything.

Both .pc.in templates are shared between CMake and Autotools, so without this AC_SUBST the new @HIDAPI_PC_LIBS_PRIVATE_FIELD@ placeholder would be left verbatim in the Autotools-generated files. With it, the ./configure output of hidapi.pc, hidapi-hidraw.pc and hidapi-libusb.pc differs from master by one empty line and nothing else.

So an Autotools-built static library keeps the same gaps as before (no libudev / libusb / frameworks in its .pc files, apart from the existing FreeBSD Requires.private). That's fine given Autotools is deprecated.

A note in case someone wants to fix Autotools later: the placeholder is one name used by both templates and AC_SUBST is global, so hidraw and libusb cannot get different values through it. It would need the same GENERIC / BACKEND split that Requires.private has, plus one more sed argument in HIDAPI_CONFIGURE_BACKEND_PC. Not asking for that in this PR.

Drafted with Claude Code.

AC_CONFIG_FILES([pc/hidapi.pc])

AC_SUBST(LTLDFLAGS)
Expand Down
2 changes: 2 additions & 0 deletions freebsd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ endif()
hidapi_configure_pc("${PROJECT_ROOT}/pc/hidapi-backend-specific.pc.in"
OUTPUT_NAME "hidapi-hidraw"
LIBRARY_NAME "hidapi-hidraw"
BACKEND_TARGET hidapi_hidraw
LIBS_PRIVATE "${CMAKE_THREAD_LIBS_INIT}"
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"
)
5 changes: 5 additions & 0 deletions libusb/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ if(HIDAPI_BUILD_AS_CXX)
endif()
target_link_libraries(hidapi_libusb PUBLIC hidapi_include)

set(HIDAPI_LIBUSB_PC_REQUIRES_PRIVATE "")
if(TARGET usb-1.0)
target_link_libraries(hidapi_libusb PRIVATE usb-1.0)
else()
include(FindPkgConfig)
pkg_check_modules(libusb REQUIRED IMPORTED_TARGET libusb-1.0>=1.0.9)
target_link_libraries(hidapi_libusb PRIVATE PkgConfig::libusb)
set(HIDAPI_LIBUSB_PC_REQUIRES_PRIVATE "libusb-1.0 >= 1.0.9")
Comment thread
Youw marked this conversation as resolved.
Resolved
endif()

find_package(Threads REQUIRED)
Expand Down Expand Up @@ -110,6 +112,9 @@ endif()
hidapi_configure_pc("${PROJECT_ROOT}/pc/hidapi-backend-specific.pc.in"
OUTPUT_NAME "hidapi-libusb"
LIBRARY_NAME "hidapi-libusb"
BACKEND_TARGET hidapi_libusb
REQUIRES_PRIVATE "${HIDAPI_LIBUSB_PC_REQUIRES_PRIVATE}"
LIBS_PRIVATE "${CMAKE_THREAD_LIBS_INIT}"
DESCRIPTION "C Library for USB HID device access from Linux, Mac OS X, FreeBSD, and Windows. This is the libusb implementation."
)

Expand Down
3 changes: 3 additions & 0 deletions linux/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,8 @@ endif()
hidapi_configure_pc("${PROJECT_ROOT}/pc/hidapi-backend-specific.pc.in"
OUTPUT_NAME "hidapi-hidraw"
LIBRARY_NAME "hidapi-hidraw"
BACKEND_TARGET hidapi_hidraw
REQUIRES_PRIVATE "libudev"
LIBS_PRIVATE "${CMAKE_THREAD_LIBS_INIT}"
DESCRIPTION "C Library for USB/Bluetooth HID device access from Linux, Mac OS X, FreeBSD, and Windows. This is the hidraw implementation."
)
2 changes: 2 additions & 0 deletions mac/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,7 @@ endif()
hidapi_configure_pc("${PROJECT_ROOT}/pc/hidapi-backend-specific.pc.in"
OUTPUT_NAME "hidapi-darwin"
LIBRARY_NAME "hidapi"
BACKEND_TARGET hidapi_darwin
LIBS_PRIVATE "-framework IOKit -framework CoreFoundation ${CMAKE_THREAD_LIBS_INIT}"
DESCRIPTION "C Library for USB/Bluetooth HID device access from Linux, Mac OS X, FreeBSD, and Windows. This is the Darwin implementation."
)
2 changes: 2 additions & 0 deletions netbsd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,7 @@ endif()
hidapi_configure_pc("${PROJECT_ROOT}/pc/hidapi-backend-specific.pc.in"
OUTPUT_NAME "hidapi-netbsd"
LIBRARY_NAME "hidapi-netbsd"
BACKEND_TARGET hidapi_netbsd
LIBS_PRIVATE "${CMAKE_THREAD_LIBS_INIT}"
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/hidapi-backend-specific.pc.in
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ URL: https://github.com/libusb/hidapi
Version: @VERSION@
Libs: -L${libdir} -l@HIDAPI_BACKEND_LIBRARY_NAME@
@HIDAPI_BACKEND_REQUIRES_PRIVATE@
@HIDAPI_PC_LIBS_PRIVATE_FIELD@
Cflags: -I${includedir}/hidapi
1 change: 1 addition & 0 deletions pc/hidapi.pc.in
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ URL: https://github.com/libusb/hidapi
Version: @VERSION@
Libs: -L${libdir} -l@HIDAPI_LIB_NAME@
@HIDAPI_GENERIC_REQUIRES_PRIVATE@
@HIDAPI_PC_LIBS_PRIVATE_FIELD@
Cflags: -I${includedir}/hidapi
25 changes: 17 additions & 8 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ endif()
# Helper(s)

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

Expand Down Expand Up @@ -87,12 +87,25 @@ function(hidapi_configure_pc PC_IN_FILE)
set(HIDAPI_BACKEND_NAME "${PC_IN_FILENAME}")
set(HIDAPI_BACKEND_DESCRIPTION "${HIDAPI_PC_DESCRIPTION}")
set(HIDAPI_BACKEND_LIBRARY_NAME "${HIDAPI_LIB_NAME}")
if(HIDAPI_PC_BACKEND_TARGET)
foreach(field IN ITEMS REQUIRES_PRIVATE LIBS_PRIVATE)
if(DEFINED HIDAPI_PC_${field})
set_property(TARGET "${HIDAPI_PC_BACKEND_TARGET}" PROPERTY "HIDAPI_PC_${field}" "${HIDAPI_PC_${field}}")
else()
get_property(HIDAPI_PC_${field} TARGET "${HIDAPI_PC_BACKEND_TARGET}" PROPERTY "HIDAPI_PC_${field}")
endif()
endforeach()
endif()
set(HIDAPI_BACKEND_REQUIRES_PRIVATE "")
if(HIDAPI_PC_REQUIRES_PRIVATE)
set(HIDAPI_BACKEND_REQUIRES_PRIVATE "Requires.private: ${HIDAPI_PC_REQUIRES_PRIVATE}")
else()
set(HIDAPI_BACKEND_REQUIRES_PRIVATE "")
endif()
set(HIDAPI_GENERIC_REQUIRES_PRIVATE "${HIDAPI_BACKEND_REQUIRES_PRIVATE}")
set(HIDAPI_PC_LIBS_PRIVATE_FIELD "")
string(STRIP "${HIDAPI_PC_LIBS_PRIVATE}" HIDAPI_PC_LIBS_PRIVATE)
if(HIDAPI_PC_LIBS_PRIVATE)
set(HIDAPI_PC_LIBS_PRIVATE_FIELD "Libs.private: ${HIDAPI_PC_LIBS_PRIVATE}")
endif()
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 @@ -227,13 +240,9 @@ endif()
add_library(hidapi::hidapi ALIAS hidapi_${EXPORT_ALIAS})

get_target_property(HIDAPI_LIB_NAME hidapi_${EXPORT_ALIAS} OUTPUT_NAME)
set(HIDAPI_REQUIRES_PRIVATE "")
if(CMAKE_SYSTEM_NAME MATCHES "FreeBSD" AND EXPORT_ALIAS STREQUAL "hidraw")
set(HIDAPI_REQUIRES_PRIVATE "libusb-1.0 >= 1.0.9")
endif()
hidapi_configure_pc("${PROJECT_ROOT}/pc/hidapi.pc.in"
LIBRARY_NAME "${HIDAPI_LIB_NAME}"
REQUIRES_PRIVATE "${HIDAPI_REQUIRES_PRIVATE}"
BACKEND_TARGET "hidapi_${EXPORT_ALIAS}"
)

if(HIDAPI_INSTALL_TARGETS)
Expand Down
Loading