Skip to content

Commit

Permalink
CI checks for CMake package files (#485)
Browse files Browse the repository at this point in the history
Add build steps to check different flavours of the CMake package builds.
  • Loading branch information
Youw committed Jan 2, 2023
1 parent 987fd0a commit c3a6150
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 1 deletion.
85 changes: 85 additions & 0 deletions .github/workflows/builds.yml
Expand Up @@ -43,10 +43,14 @@ jobs:
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/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
- name: Build CMake Static
working-directory: build/static
run: make install
- name: Build CMake Framework
working-directory: build/framework
run: make install
Expand All @@ -56,10 +60,34 @@ jobs:
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
- 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 Down Expand Up @@ -102,6 +130,27 @@ jobs:
install/static/include/hidapi/hidapi.h, \
install/static/include/hidapi/hidapi_libusb.h"
allow_failure: 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 Down Expand Up @@ -136,6 +185,17 @@ jobs:
install/msvc/include/hidapi/hidapi.h, \
install/msvc/include/hidapi/hidapi_winapi.h"
allow_failure: 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: Configure CMake NMake
shell: cmd
Expand All @@ -156,6 +216,19 @@ jobs:
install/nmake/include/hidapi/hidapi.h, \
install/nmake/include/hidapi/hidapi_winapi.h"
allow_failure: 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: Configure CMake MinGW
shell: cmd
Expand All @@ -172,6 +245,18 @@ jobs:
install/mingw/include/hidapi/hidapi.h, \
install/mingw/include/hidapi/hidapi_winapi.h"
allow_failure: true
- name: Check CMake Export Package MinGW
shell: cmd
run: |
cmake ^
-G"MinGW Makefiles" ^
-B build\ming_test ^
-S hidapisrc\hidtest ^
-Dhidapi_ROOT=install\mingw ^
-DCMAKE_INSTALL_PREFIX=install\mingw_test ^
"-DCMAKE_C_FLAGS=%NIX_COMPILE_FLAGS%"
cd build\ming_test
cmake --build . --target install
- name: Check Meson build
shell: cmd
Expand Down
16 changes: 16 additions & 0 deletions hidtest/CMakeLists.txt
@@ -1,5 +1,21 @@
cmake_minimum_required(VERSION 3.1.3 FATAL_ERROR)
project(hidtest C)

if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
# hidtest is build as a standalone project

if(POLICY CMP0074)
# allow using hidapi_ROOT if CMake supports it
cmake_policy(SET CMP0074 NEW)
endif()

find_package(hidapi 0.12 REQUIRED)
message(STATUS "Using HIDAPI: ${hidapi_VERSION}")
else()
# hidtest is built as part of the main HIDAPI build
message(STATUS "Building hidtest")
endif()

set(HIDAPI_HIDTEST_TARGETS)
if(NOT WIN32 AND NOT APPLE AND CMAKE_SYSTEM_NAME MATCHES "Linux")
if(TARGET hidapi::hidraw)
Expand Down
8 changes: 7 additions & 1 deletion src/CMakeLists.txt
Expand Up @@ -78,8 +78,14 @@ endif()
add_library(hidapi_include INTERFACE)
target_include_directories(hidapi_include INTERFACE
"$<BUILD_INTERFACE:${PROJECT_ROOT}/hidapi>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/hidapi>"
)
if(APPLE AND CMAKE_FRAMEWORK)
# FIXME: https://github.com/libusb/hidapi/issues/492: it is untrivial to set the include path for Framework correctly
else()
target_include_directories(hidapi_include INTERFACE
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/hidapi>"
)
endif()
set_target_properties(hidapi_include PROPERTIES EXPORT_NAME "include")
set(HIDAPI_PUBLIC_HEADERS "${PROJECT_ROOT}/hidapi/hidapi.h")

Expand Down

0 comments on commit c3a6150

Please sign in to comment.