Skip to content
Merged
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
26 changes: 26 additions & 0 deletions .github/workflows/builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,15 @@ jobs:
cd build/static_test
make install

- name: Check C++ portability build
run: |
rm -rf build/cxx
cmake -B build/cxx -S hidapisrc \
-DCMAKE_BUILD_TYPE=Release \
-DHIDAPI_BUILD_AS_CXX=ON \
"-DCMAKE_CXX_FLAGS=-Wall -Wextra -Werror"
cmake --build build/cxx

- name: Check Meson build
run: |
meson setup build_meson hidapisrc
Expand Down Expand Up @@ -154,6 +163,15 @@ jobs:
cd build/static_test
make install

- name: Check C++ portability build
run: |
rm -rf build/cxx
cmake -B build/cxx -S hidapisrc \
-DCMAKE_BUILD_TYPE=Release \
-DHIDAPI_BUILD_AS_CXX=ON \
"-DCMAKE_CXX_FLAGS=-Wall -Wextra -Werror -Wformat-signedness"
cmake --build build/cxx

- name: Check Meson build
run: |
meson setup build_meson hidapisrc
Expand Down Expand Up @@ -206,6 +224,14 @@ jobs:
working-directory: build/msvc
run: ctest -C RelWithDebInfo --no-compress-output --output-on-failure

- name: Configure CMake MSVC C++
shell: cmd
run: |
cmake -B build\msvc_cxx -S hidapisrc -DCMAKE_BUILD_TYPE=Release -DHIDAPI_BUILD_AS_CXX=ON -DCMAKE_CXX_STANDARD=20 "-DCMAKE_CXX_FLAGS=%MSVC_COMPILE_FLAGS%"
- name: Build CMake MSVC C++
working-directory: build/msvc_cxx
run: cmake --build . --config Release

- name: Configure CMake NMake MSVC
shell: cmd
run: |
Expand Down
7 changes: 7 additions & 0 deletions BUILD.cmake.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,13 @@ currently this option is only available on Windows, since only Windows backend h

</details><br>

<details>
<summary>Testing-only variables</summary>

- `HIDAPI_BUILD_AS_CXX` - when set to TRUE, the HIDAPI C source files are compiled with a C++ compiler instead of a C compiler. Useful to confirm that HIDAPI's sources stay compatible with consumers that include them into a C++ translation unit. Not intended for production builds; defaults to FALSE.

</details><br>

To see all most-useful CMake variables available for HIDAPI, one of the most convenient ways is too use [`cmake-gui`](https://cmake.org/cmake/help/latest/manual/cmake-gui.1.html) tool ([example](https://cmake.org/runningcmake/)).

_NOTE_: HIDAPI packages built by CMake can be used with `pkg-config`, as if built with [Autotools](BUILD.autotools.md).
Expand Down
3 changes: 3 additions & 0 deletions libusb/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ add_library(hidapi_libusb
${HIDAPI_PUBLIC_HEADERS}
hid.c
)
if(HIDAPI_BUILD_AS_CXX)
set_source_files_properties(hid.c PROPERTIES LANGUAGE CXX)
endif()
target_link_libraries(hidapi_libusb PUBLIC hidapi_include)

if(TARGET usb-1.0)
Expand Down
3 changes: 3 additions & 0 deletions linux/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ add_library(hidapi_hidraw
${HIDAPI_PUBLIC_HEADERS}
hid.c
)
if(HIDAPI_BUILD_AS_CXX)
set_source_files_properties(hid.c PROPERTIES LANGUAGE CXX)
endif()
target_link_libraries(hidapi_hidraw PUBLIC hidapi_include)

find_package(Threads REQUIRED)
Expand Down
3 changes: 3 additions & 0 deletions mac/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ add_library(hidapi_darwin
${HIDAPI_PUBLIC_HEADERS}
hid.c
)
if(HIDAPI_BUILD_AS_CXX)
set_source_files_properties(hid.c PROPERTIES LANGUAGE CXX)
endif()

find_package(Threads REQUIRED)

Expand Down
6 changes: 3 additions & 3 deletions mac/hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ static bool try_get_ioregistry_int_property(io_service_t service, CFStringRef pr

if (ref) {
if (CFGetTypeID(ref) == CFNumberGetTypeID()) {
result = CFNumberGetValue(ref, kCFNumberSInt32Type, out_val);
result = CFNumberGetValue((CFNumberRef) ref, kCFNumberSInt32Type, out_val);
}

CFRelease(ref);
Expand Down Expand Up @@ -544,7 +544,7 @@ static struct hid_device_info *create_device_info_with_usage(IOHIDDeviceRef dev,
{
unsigned short dev_vid;
unsigned short dev_pid;
int BUF_LEN = 256;
const int BUF_LEN = 256;
wchar_t buf[BUF_LEN];
CFTypeRef transport_prop;

Expand Down Expand Up @@ -586,7 +586,7 @@ static struct hid_device_info *create_device_info_with_usage(IOHIDDeviceRef dev,
so for (max) "path" string 'DevSrvsID:18446744073709551615' we would need
9+1+20+1=31 bytes buffer, but allocate 32 for simple alignment */
const size_t path_len = 32;
cur_dev->path = calloc(1, path_len);
cur_dev->path = (char *) calloc(1, path_len);
if (cur_dev->path != NULL) {
snprintf(cur_dev->path, path_len, "DevSrvsID:%llu", entry_id);
}
Expand Down
3 changes: 3 additions & 0 deletions netbsd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ add_library(hidapi_netbsd
${HIDAPI_PUBLIC_HEADERS}
hid.c
)
if(HIDAPI_BUILD_AS_CXX)
set_source_files_properties(hid.c PROPERTIES LANGUAGE CXX)
endif()
target_link_libraries(hidapi_netbsd PUBLIC hidapi_include)

find_package(Threads REQUIRED)
Expand Down
6 changes: 6 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ endif()
if(NOT DEFINED CMAKE_POSITION_INDEPENDENT_CODE)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
endif()
if(NOT DEFINED HIDAPI_BUILD_AS_CXX)
set(HIDAPI_BUILD_AS_CXX FALSE)
endif()
if(HIDAPI_BUILD_AS_CXX)
enable_language(CXX)
endif()

get_directory_property(IS_EXCLUDE_FROM_ALL EXCLUDE_FROM_ALL)
if(IS_EXCLUDE_FROM_ALL)
Expand Down
3 changes: 3 additions & 0 deletions windows/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ add_library(hidapi_winapi
${HIDAPI_PUBLIC_HEADERS}
${SOURCES}
)
if(HIDAPI_BUILD_AS_CXX)
set_source_files_properties(hid.c hidapi_descriptor_reconstruct.c PROPERTIES LANGUAGE CXX)
endif()
target_link_libraries(hidapi_winapi
PUBLIC hidapi_include
)
Expand Down
Loading