diff --git a/CMakeLists.txt b/CMakeLists.txt index a0d8366..fed51c6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,8 +11,8 @@ if(APPLE) elseif(NOT WIN32) if(CMAKE_SYSTEM_NAME MATCHES "Linux") option(HIDAPI_WITH_HIDRAW "Build HIDRAW-based implementation of HIDAPI" ON) + option(HIDAPI_WITH_LIBUSB "Build LIBUSB-based implementation of HIDAPI" ON) endif() - option(HIDAPI_WITH_LIBUSB "Build LIBUSB-based implementation of HIDAPI" ON) endif() option(BUILD_SHARED_LIBS "When set: build shared version of the libraries, otherwise - static" ON) diff --git a/libusb/CMakeLists.txt b/libusb/CMakeLists.txt index 3c0e670..da18a89 100644 --- a/libusb/CMakeLists.txt +++ b/libusb/CMakeLists.txt @@ -34,4 +34,10 @@ if(HIDAPI_INSTALL_TARGETS) ) endif() +if(HIDAPI_LIBNAME_VERBOSE) + hidapi_configure_pc("${PROJECT_ROOT}/pc/hidapi-libusb.pc.in") +else() + hidapi_configure_pc("${PROJECT_ROOT}/pc/hidapi.pc.in") +endif() + add_library(hidapi ALIAS hidapi_libusb) diff --git a/linux/CMakeLists.txt b/linux/CMakeLists.txt index 40ccec8..643f34f 100644 --- a/linux/CMakeLists.txt +++ b/linux/CMakeLists.txt @@ -29,6 +29,8 @@ if(HIDAPI_INSTALL_TARGETS) ) endif() +hidapi_configure_pc("${PROJECT_ROOT}/pc/hidapi-hidraw.pc.in") + if(NOT HIDAPI_WITH_LIBUSB) add_library(hidapi ALIAS hidapi_hidraw) endif() diff --git a/mac/CMakeLists.txt b/mac/CMakeLists.txt index f44145e..96f8cbb 100644 --- a/mac/CMakeLists.txt +++ b/mac/CMakeLists.txt @@ -38,4 +38,6 @@ if(HIDAPI_INSTALL_TARGETS) ) endif() +hidapi_configure_pc("${PROJECT_ROOT}/pc/hidapi.pc.in") + add_library(hidapi ALIAS hidapi_darwin) diff --git a/pc/hidapi-hidraw.pc.in b/pc/hidapi-hidraw.pc.in index e20558d..28b9fe6 100644 --- a/pc/hidapi-hidraw.pc.in +++ b/pc/hidapi-hidraw.pc.in @@ -5,6 +5,7 @@ includedir=@includedir@ 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. +URL: https://github.com/libusb/hidapi Version: @VERSION@ Libs: -L${libdir} -lhidapi-hidraw Cflags: -I${includedir}/hidapi diff --git a/pc/hidapi-libusb.pc.in b/pc/hidapi-libusb.pc.in index 2e49506..d51e98f 100644 --- a/pc/hidapi-libusb.pc.in +++ b/pc/hidapi-libusb.pc.in @@ -5,6 +5,7 @@ includedir=@includedir@ Name: hidapi-libusb Description: C Library for USB HID device access from Linux, Mac OS X, FreeBSD, and Windows. This is the libusb implementation. +URL: https://github.com/libusb/hidapi Version: @VERSION@ Libs: -L${libdir} -lhidapi-libusb Cflags: -I${includedir}/hidapi diff --git a/pc/hidapi.pc.in b/pc/hidapi.pc.in index 5835c99..75b11a5 100644 --- a/pc/hidapi.pc.in +++ b/pc/hidapi.pc.in @@ -5,6 +5,7 @@ includedir=@includedir@ 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 Cflags: -I${includedir}/hidapi diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2c56a43..b9eb132 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -5,7 +5,7 @@ file(READ "${PROJECT_ROOT}/VERSION" VERSION_STR) string(REGEX MATCH "^([0-9]+\\.[0-9]+\\.[0-9]+)(.*)" VERSION_STR "${VERSION_STR}") set(VERSION "${CMAKE_MATCH_1}") -set(VERSION_SUFFIX "${CMAKE_MATCH_2}") +string(STRIP "${CMAKE_MATCH_2}" VERSION_SUFFIX) # project(hidapi VERSION "${VERSION}" LANGUAGES C) @@ -15,17 +15,38 @@ project(hidapi VERSION "${VERSION}" LANGUAGES C) if(NOT DEFINED BUILD_SHARED_LIBS) set(BUILD_SHARED_LIBS ON) endif() -if(NOT DEFINED HIDAPI_WITH_HIDRAW) - set(HIDAPI_WITH_HIDRAW ON) -endif() -if(NOT DEFINED HIDAPI_WITH_LIBUSB) - set(HIDAPI_WITH_LIBUSB ON) -endif() if(NOT DEFINED HIDAPI_INSTALL_TARGETS) set(HIDAPI_INSTALL_TARGETS OFF) endif() +if(NOT DEFINED CMAKE_POSITION_INDEPENDENT_CODE) + set(CMAKE_POSITION_INDEPENDENT_CODE ON) +endif() -set(CMAKE_POSITION_INDEPENDENT_CODE ON) +# Helper(s) + +function(hidapi_configure_pc PC_IN_FILE) + file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/pc") + + set(VERSION "${VERSION}${VERSION_SUFFIX}") + set(prefix "${CMAKE_INSTALL_PREFIX}") + set(exec_prefix "\${prefix}") + if(IS_ABSOLUTE "${CMAKE_INSTALL_LIBDIR}") + set(libdir "${CMAKE_INSTALL_LIBDIR}") + else() + set(libdir "\${exec_prefix}/${CMAKE_INSTALL_LIBDIR}") + endif() + if(IS_ABSOLUTE "${CMAKE_INSTALL_INCLUDEDIR}") + set(includedir "${CMAKE_INSTALL_INCLUDEDIR}") + else() + set(includedir "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}") + endif() + + get_filename_component(PC_IN_FILENAME "${PC_IN_FILE}" NAME_WE) + set(PC_FILE "${CMAKE_CURRENT_BINARY_DIR}/pc/${PC_IN_FILENAME}.pc") + configure_file("${PC_IN_FILE}" "${PC_FILE}" @ONLY) + + install(FILES "${PC_FILE}" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig/") +endfunction() # The library @@ -42,15 +63,21 @@ if(WIN32) elseif(APPLE) add_subdirectory("${PROJECT_ROOT}/mac" mac) else() + if(NOT DEFINED HIDAPI_WITH_LIBUSB) + set(HIDAPI_WITH_LIBUSB ON) + endif() if(CMAKE_SYSTEM_NAME MATCHES "Linux") - if(HIDAPI_WITH_HIDRAW) + if(NOT DEFINED HIDAPI_WITH_HIDRAW OR HIDAPI_WITH_HIDRAW) add_subdirectory("${PROJECT_ROOT}/linux" linux) endif() set(HIDAPI_LIBNAME_VERBOSE ON) else() + set(HIDAPI_WITH_LIBUSB ON) set(HIDAPI_LIBNAME_VERBOSE OFF) endif() if(HIDAPI_WITH_LIBUSB) add_subdirectory("${PROJECT_ROOT}/libusb" libusb) + elseif(NOT TARGET hidapi_hidraw) + message(FATAL_ERROR "Select at least one option to build: HIDAPI_WITH_LIBUSB or HIDAPI_WITH_HIDRAW") endif() endif() diff --git a/windows/CMakeLists.txt b/windows/CMakeLists.txt index ad8fd6e..a41fb7d 100644 --- a/windows/CMakeLists.txt +++ b/windows/CMakeLists.txt @@ -24,4 +24,6 @@ if(HIDAPI_INSTALL_TARGETS) ) endif() +hidapi_configure_pc("${PROJECT_ROOT}/pc/hidapi.pc.in") + add_library(hidapi ALIAS hidapi_winapi)