Skip to content

Commit

Permalink
Merge pull request #5 from libusb/master
Browse files Browse the repository at this point in the history
windows: Have a separate definition flag for export (libusb#515)
  • Loading branch information
fengjixuchui authored Mar 13, 2023
2 parents f74c72e + fc3eed3 commit 5e40a69
Show file tree
Hide file tree
Showing 97 changed files with 22,313 additions and 79 deletions.
149 changes: 122 additions & 27 deletions .github/workflows/builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: macos-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Install build tools
run: brew install autoconf automake libtool
- name: Configure Automake
Expand All @@ -34,32 +34,60 @@ jobs:
runs-on: macos-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
path: hidapisrc
- name: Install dependencies
run: brew install meson ninja
- name: Configure CMake
run: |
rm -rf build install
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}"
cmake -B build/shared -S hidapisrc -DCMAKE_BUILD_TYPE=RelWithDebInfo -DHIDAPI_ENABLE_ASAN=ON -DCMAKE_INSTALL_PREFIX=install/shared -DHIDAPI_BUILD_HIDTEST=ON "-DCMAKE_C_FLAGS=${NIX_COMPILE_FLAGS}"
cmake -B build/static -S hidapisrc -DCMAKE_BUILD_TYPE=RelWithDebInfo -DHIDAPI_ENABLE_ASAN=ON -DCMAKE_INSTALL_PREFIX=install/static -DBUILD_SHARED_LIBS=FALSE -DHIDAPI_BUILD_HIDTEST=ON "-DCMAKE_C_FLAGS=${NIX_COMPILE_FLAGS}"
cmake -B build/framework -S hidapisrc -DCMAKE_BUILD_TYPE=RelWithDebInfo -DHIDAPI_ENABLE_ASAN=ON -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
- name: Build CMake Static
working-directory: build/static
run: make install
- name: Build CMake Framework
working-directory: build/framework
run: make install
- name: Check artifacts
uses: andstor/file-existence-action@v1
uses: andstor/file-existence-action@v2
with:
files: "install/shared/lib/libhidapi.dylib, \
install/shared/include/hidapi/hidapi.h, \
install/shared/include/hidapi/hidapi_darwin.h, \
install/static/lib/libhidapi.a, \
install/static/include/hidapi/hidapi.h, \
install/static/include/hidapi/hidapi_darwin.h, \
install/framework/lib/hidapi.framework/hidapi, \
install/framework/lib/hidapi.framework/Headers/hidapi.h, \
install/framework/lib/hidapi.framework/Headers/hidapi_darwin.h"
allow_failure: true
fail: true
- name: Check CMake Export Package Shared
run: |
cmake \
-B build/shared_test \
-S hidapisrc/hidtest \
-Dhidapi_ROOT=install/shared \
-DCMAKE_INSTALL_PREFIX=install/shared_test \
"-DCMAKE_C_FLAGS=${NIX_COMPILE_FLAGS}"
cd build/shared_test
make install
- name: Check CMake Export Package Static
run: |
cmake \
-B build/static_test \
-S hidapisrc/hidtest \
-Dhidapi_ROOT=install/static \
-DCMAKE_INSTALL_PREFIX=install/static_test \
"-DCMAKE_C_FLAGS=${NIX_COMPILE_FLAGS}"
cd build/static_test
make install
- name: Check Meson build
run: |
meson setup build_meson hidapisrc
Expand All @@ -71,7 +99,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
path: hidapisrc
- name: Install dependencies
Expand All @@ -82,16 +110,16 @@ jobs:
- name: Configure CMake
run: |
rm -rf build install
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}"
cmake -B build/shared -S hidapisrc -DCMAKE_BUILD_TYPE=RelWithDebInfo -DHIDAPI_ENABLE_ASAN=ON -DCMAKE_INSTALL_PREFIX=install/shared -DHIDAPI_BUILD_HIDTEST=ON "-DCMAKE_C_FLAGS=${NIX_COMPILE_FLAGS}"
cmake -B build/static -S hidapisrc -DCMAKE_BUILD_TYPE=RelWithDebInfo -DHIDAPI_ENABLE_ASAN=ON -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
- name: Build CMake Static
working-directory: build/static
run: make install
- name: Check artifacts
uses: andstor/file-existence-action@v1
uses: andstor/file-existence-action@v2
with:
files: "install/shared/lib/libhidapi-libusb.so, \
install/shared/lib/libhidapi-hidraw.so, \
Expand All @@ -101,7 +129,28 @@ jobs:
install/static/lib/libhidapi-hidraw.a, \
install/static/include/hidapi/hidapi.h, \
install/static/include/hidapi/hidapi_libusb.h"
allow_failure: true
fail: true
- name: Check CMake Export Package Shared
run: |
cmake \
-B build/shared_test \
-S hidapisrc/hidtest \
-Dhidapi_ROOT=install/shared \
-DCMAKE_INSTALL_PREFIX=install/shared_test \
"-DCMAKE_C_FLAGS=${NIX_COMPILE_FLAGS}"
cd build/shared_test
make install
- name: Check CMake Export Package Static
run: |
cmake \
-B build/static_test \
-S hidapisrc/hidtest \
-Dhidapi_ROOT=install/static \
-DCMAKE_INSTALL_PREFIX=install/static_test \
"-DCMAKE_C_FLAGS=${NIX_COMPILE_FLAGS}"
cd build/static_test
make install
- name: Check Meson build
run: |
meson setup build_meson hidapisrc
Expand All @@ -113,7 +162,7 @@ jobs:
runs-on: windows-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
path: hidapisrc
- name: Install dependencies
Expand All @@ -124,54 +173,100 @@ jobs:
- name: Configure CMake MSVC
shell: cmd
run: |
cmake -B build\msvc -S hidapisrc -DCMAKE_INSTALL_PREFIX=install\msvc -DHIDAPI_BUILD_HIDTEST=ON "-DCMAKE_C_FLAGS=%MSVC_COMPILE_FLAGS%"
cmake -B build\msvc -S hidapisrc -DCMAKE_BUILD_TYPE=RelWithDebInfo -DHIDAPI_WITH_TESTS=ON -DHIDAPI_BUILD_PP_DATA_DUMP=ON -DHIDAPI_ENABLE_ASAN=ON -DCMAKE_INSTALL_PREFIX=install\msvc -DHIDAPI_BUILD_HIDTEST=ON "-DCMAKE_C_FLAGS=%MSVC_COMPILE_FLAGS%"
- name: Build CMake MSVC
working-directory: build/msvc
run: cmake --build . --target install
run: cmake --build . --config RelWithDebInfo --target install
- name: Check artifacts MSVC
uses: andstor/file-existence-action@v1
uses: andstor/file-existence-action@v2
with:
files: "install/msvc/lib/hidapi.lib, \
install/msvc/bin/hidapi.dll, \
install/msvc/include/hidapi/hidapi.h, \
install/msvc/include/hidapi/hidapi_winapi.h"
allow_failure: true
fail: true
- name: Check CMake Export Package
shell: cmd
run: |
cmake ^
-B build\msvc_test ^
-S hidapisrc\hidtest ^
-Dhidapi_ROOT=install\msvc ^
-DCMAKE_INSTALL_PREFIX=install\msvc_test ^
"-DCMAKE_C_FLAGS=%MSVC_COMPILE_FLAGS%"
cd build\msvc_test
cmake --build . --target install
- name: Run CTest MSVC
shell: cmd
working-directory: build/msvc
run: ctest -C RelWithDebInfo --rerun-failed --output-on-failure

- name: Configure CMake NMake
shell: cmd
run: |
call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat"
cmake -G"NMake Makefiles" -B build\nmake -S hidapisrc -DCMAKE_INSTALL_PREFIX=install\nmake -DHIDAPI_BUILD_HIDTEST=ON "-DCMAKE_C_FLAGS=%MSVC_COMPILE_FLAGS%"
cmake -G"NMake Makefiles" -B build\nmake -S hidapisrc -DCMAKE_BUILD_TYPE=RelWithDebInfo -DHIDAPI_WITH_TESTS=ON -DHIDAPI_BUILD_PP_DATA_DUMP=ON -DHIDAPI_ENABLE_ASAN=ON -DCMAKE_INSTALL_PREFIX=install\nmake -DHIDAPI_BUILD_HIDTEST=ON "-DCMAKE_C_FLAGS=%MSVC_COMPILE_FLAGS%"
- name: Build CMake NMake
working-directory: build\nmake
shell: cmd
run: |
call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat"
nmake install
- name: Check artifacts NMake
uses: andstor/file-existence-action@v1
uses: andstor/file-existence-action@v2
with:
files: "install/nmake/lib/hidapi.lib, \
install/nmake/bin/hidapi.dll, \
install/nmake/include/hidapi/hidapi.h, \
install/nmake/include/hidapi/hidapi_winapi.h"
allow_failure: true
fail: true
- name: Check CMake Export Package NMake
shell: cmd
run: |
call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat"
cmake ^
-G"NMake Makefiles" ^
-B build\nmake_test ^
-S hidapisrc\hidtest ^
-Dhidapi_ROOT=install\nmake ^
-DCMAKE_INSTALL_PREFIX=install\nmake_test ^
"-DCMAKE_C_FLAGS=%MSVC_COMPILE_FLAGS%"
cd build\nmake_test
nmake install
- name: Run CTest NMake
working-directory: build\nmake
run: ctest --rerun-failed --output-on-failure

- name: Configure CMake MinGW
shell: cmd
run: |
cmake -G"MinGW Makefiles" -B build\mingw -S hidapisrc -DCMAKE_INSTALL_PREFIX=install\mingw -DHIDAPI_BUILD_HIDTEST=ON "-DCMAKE_C_FLAGS=%NIX_COMPILE_FLAGS%"
cmake -G"MinGW Makefiles" -B build\mingw -S hidapisrc -DCMAKE_BUILD_TYPE=RelWithDebInfo -DHIDAPI_WITH_TESTS=ON -DHIDAPI_BUILD_PP_DATA_DUMP=ON -DCMAKE_INSTALL_PREFIX=install\mingw -DHIDAPI_BUILD_HIDTEST=ON "-DCMAKE_C_FLAGS=%NIX_COMPILE_FLAGS%"
- name: Build CMake MinGW
working-directory: build\mingw
run: cmake --build . --target install
- name: Check artifacts MinGW
uses: andstor/file-existence-action@v1
uses: andstor/file-existence-action@v2
with:
files: "install/mingw/lib/libhidapi.dll.a, \
install/mingw/bin/libhidapi.dll, \
install/mingw/include/hidapi/hidapi.h, \
install/mingw/include/hidapi/hidapi_winapi.h"
allow_failure: true
fail: true
- name: Check CMake Export Package MinGW
shell: cmd
run: |
cmake ^
-G"MinGW Makefiles" ^
-B build\mingw_test ^
-S hidapisrc\hidtest ^
-Dhidapi_ROOT=install\mingw ^
-DCMAKE_INSTALL_PREFIX=install\mingw_test ^
"-DCMAKE_C_FLAGS=%NIX_COMPILE_FLAGS%"
cd build\mingw_test
cmake --build . --target install
- name: Run CTest MinGW
working-directory: build\mingw
run: ctest --rerun-failed --output-on-failure

- name: Check Meson build
shell: cmd
Expand All @@ -186,22 +281,22 @@ jobs:
runs-on: windows-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: microsoft/setup-msbuild@v1.1
- name: MSBuild x86
run: msbuild windows\hidapi.sln /p:Configuration=Release /p:Platform=Win32
- name: Check artifacts x86
uses: andstor/file-existence-action@v1
uses: andstor/file-existence-action@v2
with:
files: "windows/Release/hidapi.dll, windows/Release/hidapi.lib, windows/Release/hidapi.pdb"
allow_failure: true
fail: true
- name: MSBuild x64
run: msbuild windows\hidapi.sln /p:Configuration=Release /p:Platform=x64
- name: Check artifacts x64
uses: andstor/file-existence-action@v1
uses: andstor/file-existence-action@v2
with:
files: "windows/x64/Release/hidapi.dll, windows/x64/Release/hidapi.lib, windows/x64/Release/hidapi.pdb"
allow_failure: true
fail: true
- name: Gather artifacts
run: |
md artifacts
Expand Down
2 changes: 2 additions & 0 deletions BUILD.cmake.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ Some of the [standard](https://cmake.org/cmake/help/latest/manual/cmake-variable
HIDAPI-specific CMake variables:

- `HIDAPI_BUILD_HIDTEST` - when set to TRUE, build a small test application `hidtest`;
- `HIDAPI_WITH_TESTS` - when set to TRUE, build all (unit-)tests;
currently this option is only available on Windows, since only Windows backend has tests;

<details>
<summary>Linux-specific variables</summary>
Expand Down
54 changes: 49 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,57 @@ option(BUILD_SHARED_LIBS "Build shared version of the libraries, otherwise build
set(HIDAPI_INSTALL_TARGETS ON)
set(HIDAPI_PRINT_VERSION ON)

add_subdirectory(src)

set(BUILD_HIDTEST_DEFAULT OFF)
set(IS_DEBUG_BUILD OFF)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(BUILD_HIDTEST_DEFAULT ON)
set(IS_DEBUG_BUILD ON)
endif()

option(HIDAPI_ENABLE_ASAN "Build HIDAPI with ASAN address sanitizer instrumentation" OFF)

if(HIDAPI_ENABLE_ASAN)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address")
if(MSVC)
# the default is to have "/INCREMENTAL" which causes a warning when "-fsanitize=address" is present
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /INCREMENTAL:NO")
set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} /INCREMENTAL:NO")
set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO} /INCREMENTAL:NO")
set(CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO} /INCREMENTAL:NO")
endif()
endif()

if(WIN32)
# so far only Windows has tests
option(HIDAPI_WITH_TESTS "Build HIDAPI (unit-)tests" ${IS_DEBUG_BUILD})
else()
set(HIDAPI_WITH_TESTS OFF)
endif()

if(HIDAPI_WITH_TESTS)
enable_testing()
endif()

if(WIN32)
option(HIDAPI_BUILD_PP_DATA_DUMP "Build small Windows console application pp_data_dump.exe" ${IS_DEBUG_BUILD})
endif()
option(HIDAPI_BUILD_HIDTEST "Build small console test application hidtest" ${BUILD_HIDTEST_DEFAULT})

add_subdirectory(src)

option(HIDAPI_BUILD_HIDTEST "Build small console test application hidtest" ${IS_DEBUG_BUILD})
if(HIDAPI_BUILD_HIDTEST)
add_subdirectory(hidtest)
endif()

if(HIDAPI_ENABLE_ASAN)
if(NOT MSVC)
# MSVC doesn't recognize those options, other compilers - requiring it
foreach(HIDAPI_TARGET hidapi_winapi hidapi_darwin hidapi_hidraw hidapi_libusb hidtest_hidraw hidtest_libusb hidtest)
if(TARGET ${HIDAPI_TARGET})
if(BUILD_SHARED_LIBS)
target_link_options(${HIDAPI_TARGET} PRIVATE -fsanitize=address)
else()
target_link_options(${HIDAPI_TARGET} PUBLIC -fsanitize=address)
endif()
endif()
endforeach()
endif()
endif()
9 changes: 6 additions & 3 deletions HACKING.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ Updating a Version:

Firing a new release:
1. Update the Version (if not yet updated).
2. Build hidapi.dll/.lib for x86/x64.
3. Upload Windows binaries to Github release page.
4. Make sure to tag the release as: `hidapi-<VERSION>`, where <VERSION> as in VERSION file.
2. Prepare the Release Notes.
3. Store the Release Notes into a file.
4. Create locally an annotated git tag with release notes attached, e.g.: `git tag -aF ../hidapi_release_notes hidapi-<VERSION>`
5. Push newly created tag: `git push origin hidapi-<VERSION>`
6. Grab the hidapi-win.zip from Summary page of "GitHub Builds" Action for latest master build.
7. Create a Github Release with hidapi-win.zip attached, for newly created tag.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.13.0
0.14.0
2 changes: 2 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,15 @@ case $host in
os="windows"
threads="windows"
win_implementation="mingw"
LDFLAGS="${LDFLAGS} -static-libgcc"
;;
*-msys*)
AC_MSG_RESULT([ (Windows back-end, using MSYS2)])
backend="windows"
os="windows"
threads="windows"
win_implementation="mingw"
LDFLAGS="${LDFLAGS} -static-libgcc"
;;
*-cygwin*)
AC_MSG_RESULT([ (Windows back-end, using Cygwin)])
Expand Down
Loading

0 comments on commit 5e40a69

Please sign in to comment.