Skip to content

Commit c3a6150

Browse files
authored
CI checks for CMake package files (#485)
Add build steps to check different flavours of the CMake package builds.
1 parent 987fd0a commit c3a6150

File tree

3 files changed

+108
-1
lines changed

3 files changed

+108
-1
lines changed

.github/workflows/builds.yml

+85
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,14 @@ jobs:
4343
run: |
4444
rm -rf build install
4545
cmake -B build/shared -S hidapisrc -DCMAKE_INSTALL_PREFIX=install/shared -DHIDAPI_BUILD_HIDTEST=ON "-DCMAKE_C_FLAGS=${NIX_COMPILE_FLAGS}"
46+
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}"
4647
cmake -B build/framework -S hidapisrc -DCMAKE_INSTALL_PREFIX=install/framework -DCMAKE_FRAMEWORK=ON -DHIDAPI_BUILD_HIDTEST=ON "-DCMAKE_C_FLAGS=${NIX_COMPILE_FLAGS}"
4748
- name: Build CMake Shared
4849
working-directory: build/shared
4950
run: make install
51+
- name: Build CMake Static
52+
working-directory: build/static
53+
run: make install
5054
- name: Build CMake Framework
5155
working-directory: build/framework
5256
run: make install
@@ -56,10 +60,34 @@ jobs:
5660
files: "install/shared/lib/libhidapi.dylib, \
5761
install/shared/include/hidapi/hidapi.h, \
5862
install/shared/include/hidapi/hidapi_darwin.h, \
63+
install/static/lib/libhidapi.a, \
64+
install/static/include/hidapi/hidapi.h, \
65+
install/static/include/hidapi/hidapi_darwin.h, \
5966
install/framework/lib/hidapi.framework/hidapi, \
6067
install/framework/lib/hidapi.framework/Headers/hidapi.h, \
6168
install/framework/lib/hidapi.framework/Headers/hidapi_darwin.h"
6269
allow_failure: true
70+
- name: Check CMake Export Package Shared
71+
run: |
72+
cmake \
73+
-B build/shared_test \
74+
-S hidapisrc/hidtest \
75+
-Dhidapi_ROOT=install/shared \
76+
-DCMAKE_INSTALL_PREFIX=install/shared_test \
77+
"-DCMAKE_C_FLAGS=${NIX_COMPILE_FLAGS}"
78+
cd build/shared_test
79+
make install
80+
- name: Check CMake Export Package Static
81+
run: |
82+
cmake \
83+
-B build/static_test \
84+
-S hidapisrc/hidtest \
85+
-Dhidapi_ROOT=install/static \
86+
-DCMAKE_INSTALL_PREFIX=install/static_test \
87+
"-DCMAKE_C_FLAGS=${NIX_COMPILE_FLAGS}"
88+
cd build/static_test
89+
make install
90+
6391
- name: Check Meson build
6492
run: |
6593
meson setup build_meson hidapisrc
@@ -102,6 +130,27 @@ jobs:
102130
install/static/include/hidapi/hidapi.h, \
103131
install/static/include/hidapi/hidapi_libusb.h"
104132
allow_failure: true
133+
- name: Check CMake Export Package Shared
134+
run: |
135+
cmake \
136+
-B build/shared_test \
137+
-S hidapisrc/hidtest \
138+
-Dhidapi_ROOT=install/shared \
139+
-DCMAKE_INSTALL_PREFIX=install/shared_test \
140+
"-DCMAKE_C_FLAGS=${NIX_COMPILE_FLAGS}"
141+
cd build/shared_test
142+
make install
143+
- name: Check CMake Export Package Static
144+
run: |
145+
cmake \
146+
-B build/static_test \
147+
-S hidapisrc/hidtest \
148+
-Dhidapi_ROOT=install/static \
149+
-DCMAKE_INSTALL_PREFIX=install/static_test \
150+
"-DCMAKE_C_FLAGS=${NIX_COMPILE_FLAGS}"
151+
cd build/static_test
152+
make install
153+
105154
- name: Check Meson build
106155
run: |
107156
meson setup build_meson hidapisrc
@@ -136,6 +185,17 @@ jobs:
136185
install/msvc/include/hidapi/hidapi.h, \
137186
install/msvc/include/hidapi/hidapi_winapi.h"
138187
allow_failure: true
188+
- name: Check CMake Export Package
189+
shell: cmd
190+
run: |
191+
cmake ^
192+
-B build\msvc_test ^
193+
-S hidapisrc\hidtest ^
194+
-Dhidapi_ROOT=install\msvc ^
195+
-DCMAKE_INSTALL_PREFIX=install\msvc_test ^
196+
"-DCMAKE_C_FLAGS=%MSVC_COMPILE_FLAGS%"
197+
cd build\msvc_test
198+
cmake --build . --target install
139199
140200
- name: Configure CMake NMake
141201
shell: cmd
@@ -156,6 +216,19 @@ jobs:
156216
install/nmake/include/hidapi/hidapi.h, \
157217
install/nmake/include/hidapi/hidapi_winapi.h"
158218
allow_failure: true
219+
- name: Check CMake Export Package NMake
220+
shell: cmd
221+
run: |
222+
call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat"
223+
cmake ^
224+
-G"NMake Makefiles" ^
225+
-B build\nmake_test ^
226+
-S hidapisrc\hidtest ^
227+
-Dhidapi_ROOT=install\nmake ^
228+
-DCMAKE_INSTALL_PREFIX=install\nmake_test ^
229+
"-DCMAKE_C_FLAGS=%MSVC_COMPILE_FLAGS%"
230+
cd build\nmake_test
231+
nmake install
159232
160233
- name: Configure CMake MinGW
161234
shell: cmd
@@ -172,6 +245,18 @@ jobs:
172245
install/mingw/include/hidapi/hidapi.h, \
173246
install/mingw/include/hidapi/hidapi_winapi.h"
174247
allow_failure: true
248+
- name: Check CMake Export Package MinGW
249+
shell: cmd
250+
run: |
251+
cmake ^
252+
-G"MinGW Makefiles" ^
253+
-B build\ming_test ^
254+
-S hidapisrc\hidtest ^
255+
-Dhidapi_ROOT=install\mingw ^
256+
-DCMAKE_INSTALL_PREFIX=install\mingw_test ^
257+
"-DCMAKE_C_FLAGS=%NIX_COMPILE_FLAGS%"
258+
cd build\ming_test
259+
cmake --build . --target install
175260
176261
- name: Check Meson build
177262
shell: cmd

hidtest/CMakeLists.txt

+16
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
1+
cmake_minimum_required(VERSION 3.1.3 FATAL_ERROR)
12
project(hidtest C)
23

4+
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
5+
# hidtest is build as a standalone project
6+
7+
if(POLICY CMP0074)
8+
# allow using hidapi_ROOT if CMake supports it
9+
cmake_policy(SET CMP0074 NEW)
10+
endif()
11+
12+
find_package(hidapi 0.12 REQUIRED)
13+
message(STATUS "Using HIDAPI: ${hidapi_VERSION}")
14+
else()
15+
# hidtest is built as part of the main HIDAPI build
16+
message(STATUS "Building hidtest")
17+
endif()
18+
319
set(HIDAPI_HIDTEST_TARGETS)
420
if(NOT WIN32 AND NOT APPLE AND CMAKE_SYSTEM_NAME MATCHES "Linux")
521
if(TARGET hidapi::hidraw)

src/CMakeLists.txt

+7-1
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,14 @@ endif()
7878
add_library(hidapi_include INTERFACE)
7979
target_include_directories(hidapi_include INTERFACE
8080
"$<BUILD_INTERFACE:${PROJECT_ROOT}/hidapi>"
81-
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/hidapi>"
8281
)
82+
if(APPLE AND CMAKE_FRAMEWORK)
83+
# FIXME: https://github.com/libusb/hidapi/issues/492: it is untrivial to set the include path for Framework correctly
84+
else()
85+
target_include_directories(hidapi_include INTERFACE
86+
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/hidapi>"
87+
)
88+
endif()
8389
set_target_properties(hidapi_include PROPERTIES EXPORT_NAME "include")
8490
set(HIDAPI_PUBLIC_HEADERS "${PROJECT_ROOT}/hidapi/hidapi.h")
8591

0 commit comments

Comments
 (0)