diff --git a/.github/workflows/builds.yml b/.github/workflows/builds.yml index 49c6e2927..9e745ef36 100644 --- a/.github/workflows/builds.yml +++ b/.github/workflows/builds.yml @@ -2,6 +2,10 @@ name: GitHub Builds on: [push, pull_request] +env: + NIX_COMPILE_FLAGS: -Wall -Wextra -pedantic -Werror + MSVC_COMPILE_FLAGS: /W4 /WX + jobs: macos-automake: @@ -36,8 +40,8 @@ jobs: - name: Configure CMake run: | rm -rf build install - cmake -B build/shared -S hidapisrc -DCMAKE_INSTALL_PREFIX=install/shared - cmake -B build/framework -S hidapisrc -DCMAKE_INSTALL_PREFIX=install/framework -DCMAKE_FRAMEWORK=ON + cmake -B build/shared -S hidapisrc -DCMAKE_INSTALL_PREFIX=install/shared -DHIDAPI_BUILD_HIDTEST=ON "-DCMAKE_C_FLAGS=${NIX_COMPILE_FLAGS}" + cmake -B build/framework -S hidapisrc -DCMAKE_INSTALL_PREFIX=install/framework -DCMAKE_FRAMEWORK=ON -DHIDAPI_BUILD_HIDTEST=ON "-DCMAKE_C_FLAGS=${NIX_COMPILE_FLAGS}" - name: Build CMake Shared working-directory: build/shared run: make install @@ -70,8 +74,8 @@ jobs: - name: Configure CMake run: | rm -rf build install - cmake -B build/shared -S hidapisrc -DCMAKE_INSTALL_PREFIX=install/shared - cmake -B build/static -S hidapisrc -DCMAKE_INSTALL_PREFIX=install/static -DBUILD_SHARED_LIBS=FALSE + cmake -B build/shared -S hidapisrc -DCMAKE_INSTALL_PREFIX=install/shared -DHIDAPI_BUILD_HIDTEST=ON "-DCMAKE_C_FLAGS=${NIX_COMPILE_FLAGS}" + cmake -B build/static -S hidapisrc -DCMAKE_INSTALL_PREFIX=install/static -DBUILD_SHARED_LIBS=FALSE -DHIDAPI_BUILD_HIDTEST=ON "-DCMAKE_C_FLAGS=${NIX_COMPILE_FLAGS}" - name: Build CMake Shared working-directory: build/shared run: make install @@ -103,7 +107,7 @@ jobs: shell: cmd run: | RMDIR /Q /S build install - cmake -B build -S hidapisrc -DCMAKE_INSTALL_PREFIX=install + cmake -B build -S hidapisrc -DCMAKE_INSTALL_PREFIX=install -DHIDAPI_BUILD_HIDTEST=ON "-DCMAKE_C_FLAGS=%MSVC_COMPILE_FLAGS%" - name: Build CMake working-directory: build run: cmake --build . --target install @@ -126,7 +130,7 @@ jobs: run: | RMDIR /Q /S build install call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat" - cmake -G"NMake Makefiles" -B build -S hidapisrc -DCMAKE_INSTALL_PREFIX=install + cmake -G"NMake Makefiles" -B build -S hidapisrc -DCMAKE_INSTALL_PREFIX=install -DHIDAPI_BUILD_HIDTEST=ON "-DCMAKE_C_FLAGS=%MSVC_COMPILE_FLAGS%" - name: Build CMake working-directory: build shell: cmd @@ -151,7 +155,7 @@ jobs: shell: cmd run: | RMDIR /Q /S build install - cmake -G"MinGW Makefiles" -B build -S hidapisrc -DCMAKE_INSTALL_PREFIX=install + cmake -G"MinGW Makefiles" -B build -S hidapisrc -DCMAKE_INSTALL_PREFIX=install -DHIDAPI_BUILD_HIDTEST=ON "-DCMAKE_C_FLAGS=%NIX_COMPILE_FLAGS%" - name: Build CMake working-directory: build run: cmake --build . --target install diff --git a/hidtest/CMakeLists.txt b/hidtest/CMakeLists.txt index ae9b961b9..717ffec03 100644 --- a/hidtest/CMakeLists.txt +++ b/hidtest/CMakeLists.txt @@ -9,6 +9,7 @@ if(NOT WIN32 AND NOT APPLE AND CMAKE_SYSTEM_NAME MATCHES "Linux") endif() if(TARGET hidapi::libusb) add_executable(hidtest_libusb test.c) + target_compile_definitions(hidtest_libusb PRIVATE USING_HIDAPI_LIBUSB) target_link_libraries(hidtest_libusb hidapi::libusb) list(APPEND HIDAPI_HIDTEST_TARGETS hidtest_libusb) endif() diff --git a/hidtest/Makefile.am b/hidtest/Makefile.am index 119126630..b6013077a 100644 --- a/hidtest/Makefile.am +++ b/hidtest/Makefile.am @@ -22,3 +22,7 @@ endif if OS_DARWIN AM_CPPFLAGS += -I$(top_srcdir)/mac/ endif + +if OS_WINDOWS +AM_CPPFLAGS += -I$(top_srcdir)/windows/ +endif diff --git a/hidtest/test.c b/hidtest/test.c index 2d38651db..157ce6f90 100644 --- a/hidtest/test.c +++ b/hidtest/test.c @@ -36,10 +36,21 @@ #define HID_API_VERSION HID_API_MAKE_VERSION(HID_API_VERSION_MAJOR, HID_API_VERSION_MINOR, HID_API_VERSION_PATCH) #endif +// +// Sample using platform-specific headers #if defined(__APPLE__) && HID_API_VERSION >= HID_API_MAKE_VERSION(0, 12, 0) #include #endif +#if defined(_WIN32) && HID_API_VERSION >= HID_API_MAKE_VERSION(0, 12, 0) +#include +#endif + +#if defined(USING_HIDAPI_LIBUSB) && HID_API_VERSION >= HID_API_MAKE_VERSION(0, 12, 0) +#include +#endif +// + int main(int argc, char* argv[]) { (void)argc; @@ -161,7 +172,7 @@ int main(int argc, char* argv[]) // Print out the returned buffer. printf("Feature Report\n "); for (i = 0; i < res; i++) - printf("%02hhx ", buf[i]); + printf("%02x ", (unsigned int) buf[i]); printf("\n"); } @@ -204,7 +215,7 @@ int main(int argc, char* argv[]) printf("Data read:\n "); // Print out the returned buffer. for (i = 0; i < res; i++) - printf("%02hhx ", buf[i]); + printf("%02x ", (unsigned int) buf[i]); printf("\n"); hid_close(handle); diff --git a/libusb/Makefile.freebsd b/libusb/Makefile.freebsd index cb24d6a94..c52b355d1 100644 --- a/libusb/Makefile.freebsd +++ b/libusb/Makefile.freebsd @@ -15,7 +15,7 @@ CFLAGS ?= -Wall -g -fPIC COBJS = hid.o ../hidtest/test.o OBJS = $(COBJS) -INCLUDES = -I../hidapi -I/usr/local/include +INCLUDES = -I../hidapi -I. -I/usr/local/include LDFLAGS = -L/usr/local/lib LIBS = -lusb -liconv -pthread diff --git a/libusb/Makefile.haiku b/libusb/Makefile.haiku index 975e8ba67..b3622ad85 100644 --- a/libusb/Makefile.haiku +++ b/libusb/Makefile.haiku @@ -15,7 +15,7 @@ CFLAGS ?= -Wall -g -fPIC COBJS = hid.o ../hidtest/test.o OBJS = $(COBJS) -INCLUDES = -I../hidapi -I/usr/local/include +INCLUDES = -I../hidapi -I. -I/usr/local/include LDFLAGS = -L/usr/local/lib LIBS = -lusb -liconv -pthread diff --git a/libusb/Makefile.linux b/libusb/Makefile.linux index 4b338ec9b..527f6b38b 100644 --- a/libusb/Makefile.linux +++ b/libusb/Makefile.linux @@ -20,7 +20,7 @@ COBJS = $(COBJS_LIBUSB) ../hidtest/test.o OBJS = $(COBJS) LIBS_USB = `pkg-config libusb-1.0 --libs` -lrt -lpthread LIBS = $(LIBS_USB) -INCLUDES ?= -I../hidapi `pkg-config libusb-1.0 --cflags` +INCLUDES ?= -I../hidapi -I. `pkg-config libusb-1.0 --cflags` # Console Test Program diff --git a/mac/hid.c b/mac/hid.c index dbc6a4ef5..d78ac9bee 100644 --- a/mac/hid.c +++ b/mac/hid.c @@ -790,12 +790,12 @@ static io_registry_entry_t hid_open_service_registry_from_path(const char *path) char *endptr; uint64_t entry_id = strtoull(path + 10, &endptr, 10); if (*endptr == '\0') { - return IOServiceGetMatchingService(NULL, IORegistryEntryIDMatching(entry_id)); + return IOServiceGetMatchingService((mach_port_t) 0, IORegistryEntryIDMatching(entry_id)); } } else { /* Fallback to older format of the path */ - return IORegistryEntryFromPath(NULL, path); + return IORegistryEntryFromPath((mach_port_t) 0, path); } return MACH_PORT_NULL; diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 64304b5ac..504b20548 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -95,10 +95,16 @@ set(HIDAPI_NEED_EXPORT_LIBUDEV FALSE) set(HIDAPI_NEED_EXPORT_ICONV FALSE) if(WIN32) + target_include_directories(hidapi_include INTERFACE + "$" + ) add_subdirectory("${PROJECT_ROOT}/windows" windows) set(EXPORT_ALIAS winapi) list(APPEND EXPORT_COMPONENTS winapi) elseif(APPLE) + target_include_directories(hidapi_include INTERFACE + "$" + ) add_subdirectory("${PROJECT_ROOT}/mac" mac) set(EXPORT_ALIAS darwin) list(APPEND EXPORT_COMPONENTS darwin) diff --git a/windows/Makefile.mingw b/windows/Makefile.mingw index c8c463849..857e4fb98 100644 --- a/windows/Makefile.mingw +++ b/windows/Makefile.mingw @@ -11,7 +11,7 @@ all: hidtest libhidapi.dll CC=gcc COBJS=hid.o ../hidtest/test.o OBJS=$(COBJS) -CFLAGS=-I../hidapi -g -c +CFLAGS=-I../hidapi -I. -g -c LIBS= DLL_LDFLAGS = -mwindows diff --git a/windows/hidapi_cfgmgr32.h b/windows/hidapi_cfgmgr32.h index b9e705b03..720906e3d 100644 --- a/windows/hidapi_cfgmgr32.h +++ b/windows/hidapi_cfgmgr32.h @@ -54,15 +54,15 @@ typedef CONFIGRET(__stdcall* CM_Get_Device_Interface_List_SizeW_)(PULONG pulLen, typedef CONFIGRET(__stdcall* CM_Get_Device_Interface_ListW_)(LPGUID InterfaceClassGuid, DEVINSTID_W pDeviceID, PZZWSTR Buffer, ULONG BufferLen, ULONG ulFlags); // from devpkey.h -static DEVPROPKEY DEVPKEY_NAME = { { 0xb725f130, 0x47ef, 0x101a, 0xa5, 0xf1, 0x02, 0x60, 0x8c, 0x9e, 0xeb, 0xac }, 10 }; // DEVPROP_TYPE_STRING -static DEVPROPKEY DEVPKEY_Device_InstanceId = { { 0x78c34fc8, 0x104a, 0x4aca, 0x9e, 0xa4, 0x52, 0x4d, 0x52, 0x99, 0x6e, 0x57 }, 256 }; // DEVPROP_TYPE_STRING -static DEVPROPKEY DEVPKEY_Device_HardwareIds = { { 0xa45c254e, 0xdf1c, 0x4efd, 0x80, 0x20, 0x67, 0xd1, 0x46, 0xa8, 0x50, 0xe0}, 3 }; // DEVPROP_TYPE_STRING_LIST -static DEVPROPKEY DEVPKEY_Device_CompatibleIds = { { 0xa45c254e, 0xdf1c, 0x4efd, 0x80, 0x20, 0x67, 0xd1, 0x46, 0xa8, 0x50, 0xe0}, 4 }; // DEVPROP_TYPE_STRING_LIST -static DEVPROPKEY DEVPKEY_Device_ContainerId = { { 0x8c7ed206, 0x3f8a, 0x4827, 0xb3, 0xab, 0xae, 0x9e, 0x1f, 0xae, 0xfc, 0x6c}, 2 }; // DEVPROP_TYPE_GUID +static DEVPROPKEY DEVPKEY_NAME = { { 0xb725f130, 0x47ef, 0x101a, {0xa5, 0xf1, 0x02, 0x60, 0x8c, 0x9e, 0xeb, 0xac} }, 10 }; // DEVPROP_TYPE_STRING +static DEVPROPKEY DEVPKEY_Device_InstanceId = { { 0x78c34fc8, 0x104a, 0x4aca, {0x9e, 0xa4, 0x52, 0x4d, 0x52, 0x99, 0x6e, 0x57} }, 256 }; // DEVPROP_TYPE_STRING +static DEVPROPKEY DEVPKEY_Device_HardwareIds = { { 0xa45c254e, 0xdf1c, 0x4efd, {0x80, 0x20, 0x67, 0xd1, 0x46, 0xa8, 0x50, 0xe0} }, 3 }; // DEVPROP_TYPE_STRING_LIST +static DEVPROPKEY DEVPKEY_Device_CompatibleIds = { { 0xa45c254e, 0xdf1c, 0x4efd, {0x80, 0x20, 0x67, 0xd1, 0x46, 0xa8, 0x50, 0xe0} }, 4 }; // DEVPROP_TYPE_STRING_LIST +static DEVPROPKEY DEVPKEY_Device_ContainerId = { { 0x8c7ed206, 0x3f8a, 0x4827, {0xb3, 0xab, 0xae, 0x9e, 0x1f, 0xae, 0xfc, 0x6c} }, 2 }; // DEVPROP_TYPE_GUID // from propkey.h -static PROPERTYKEY PKEY_DeviceInterface_Bluetooth_DeviceAddress = { { 0x2bd67d8b, 0x8beb, 0x48d5, 0x87, 0xe0, 0x6c, 0xda, 0x34, 0x28, 0x04, 0x0a }, 1 }; // DEVPROP_TYPE_STRING -static PROPERTYKEY PKEY_DeviceInterface_Bluetooth_Manufacturer = { { 0x2bd67d8b, 0x8beb, 0x48d5, 0x87, 0xe0, 0x6c, 0xda, 0x34, 0x28, 0x04, 0x0a }, 4 }; // DEVPROP_TYPE_STRING +static PROPERTYKEY PKEY_DeviceInterface_Bluetooth_DeviceAddress = { { 0x2bd67d8b, 0x8beb, 0x48d5, {0x87, 0xe0, 0x6c, 0xda, 0x34, 0x28, 0x04, 0x0a} }, 1 }; // DEVPROP_TYPE_STRING +static PROPERTYKEY PKEY_DeviceInterface_Bluetooth_Manufacturer = { { 0x2bd67d8b, 0x8beb, 0x48d5, {0x87, 0xe0, 0x6c, 0xda, 0x34, 0x28, 0x04, 0x0a} }, 4 }; // DEVPROP_TYPE_STRING #endif diff --git a/windows/hidtest.vcproj b/windows/hidtest.vcproj index abee0eb2b..2918fc441 100644 --- a/windows/hidtest.vcproj +++ b/windows/hidtest.vcproj @@ -40,7 +40,7 @@ Disabled - ..\hidapi;%(AdditionalIncludeDirectories) + ..\hidapi;.;%(AdditionalIncludeDirectories) true EnableFastChecks MultiThreadedDebugDLL @@ -105,7 +105,7 @@ Disabled - ..\hidapi;%(AdditionalIncludeDirectories) + ..\hidapi;.;%(AdditionalIncludeDirectories) EnableFastChecks MultiThreadedDebugDLL Level3 @@ -122,7 +122,7 @@ MaxSpeed true - ..\hidapi;%(AdditionalIncludeDirectories) + ..\hidapi;.;%(AdditionalIncludeDirectories) MultiThreaded true Level3 @@ -142,7 +142,7 @@ MaxSpeed true - ..\hidapi;%(AdditionalIncludeDirectories) + ..\hidapi;.;%(AdditionalIncludeDirectories) MultiThreaded true Level3