Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Meson support #410

Merged
merged 14 commits into from
Sep 10, 2022
28 changes: 27 additions & 1 deletion .github/workflows/builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ jobs:
- uses: actions/checkout@v2
with:
path: hidapisrc
- name: Install dependencies
run: brew install meson ninja
- name: Configure CMake
run: |
rm -rf build install
Expand All @@ -58,6 +60,11 @@ jobs:
install/framework/lib/hidapi.framework/Headers/hidapi.h, \
install/framework/lib/hidapi.framework/Headers/hidapi_darwin.h"
allow_failure: true
- name: Check Meson build
run: |
meson setup build_meson hidapisrc
cd build_meson
ninja

ubuntu-cmake:

Expand All @@ -70,7 +77,8 @@ jobs:
- name: Install dependencies
run: |
sudo apt update
sudo apt install libudev-dev libusb-1.0-0-dev
sudo apt install libudev-dev libusb-1.0-0-dev python3-pip ninja-build
sudo -H pip3 install meson
- name: Configure CMake
run: |
rm -rf build install
Expand All @@ -94,6 +102,11 @@ jobs:
install/static/include/hidapi/hidapi.h, \
install/static/include/hidapi/hidapi_libusb.h"
allow_failure: true
- name: Check Meson build
run: |
meson setup build_meson hidapisrc
cd build_meson
ninja

windows-cmake:

Expand All @@ -103,6 +116,11 @@ jobs:
- uses: actions/checkout@v2
with:
path: hidapisrc
- name: Install dependencies
run: |
choco install ninja
pip3 install meson
refreshenv
- name: Configure CMake MSVC
shell: cmd
run: |
Expand Down Expand Up @@ -155,6 +173,14 @@ jobs:
install/mingw/include/hidapi/hidapi_winapi.h"
allow_failure: true

- name: Check Meson build
shell: cmd
run: |
call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat"
meson setup build_meson hidapisrc
cd build_meson
ninja

windows-msbuild:

runs-on: windows-latest
Expand Down
8 changes: 7 additions & 1 deletion BUILD.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ For various reasons you may need to build HIDAPI on your own.
It can be done in several different ways:
- using [CMake](BUILD.cmake.md);
- using [Autotools](BUILD.autotools.md) (deprecated);
- using [manual makefiles](#building-the-manual-way-on-unix-platforms).
- using [manual makefiles](#building-the-manual-way-on-unix-platforms);
- using `Meson` (requires CMake);

**Autotools** build system is historically first mature build system for
HIDAPI. Most common usage of it is in its separate README: [BUILD.autotools.md](BUILD.autotools.md).<br/>
Expand All @@ -30,6 +31,11 @@ HIDAPI Team recommends using CMake build for HIDAPI.
HIDAPI is one of the projects which uses the power of CMake for its advantage.
More documentation is available in its separate README: [BUILD.cmake.md](BUILD.cmake.md).

**Meson** build system for HIDAPI is designed as a [wrapper](https://mesonbuild.com/CMake-module.html) over CMake build script.
It is present for the convenience of Meson users who need to use HIDAPI and need to be sure HIDAPI is built in accordance with officially supported build scripts.<br>
In the Meson script of your project you need a `hidapi = subproject('hidapi')` subproject, and `hidapi.get_variable('hidapi_dep')` as your dependency.
There are also backend/platform-specific dependencies available: `hidapi_winapi`, `hidapi_darwin`, `hidapi_hidraw`, `hidapi_libusb`.

If you don't know where to start to build HIDAPI, we recommend starting with [CMake](BUILD.cmake.md) build.

## Prerequisites:
Expand Down
22 changes: 22 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
project('hidapi', meson_version: '>=0.57.0', version: files('VERSION'))

cmake = import('cmake')

hidapi_build_options = cmake.subproject_options()
hidapi_build_options.set_install(true)

hidapi_build = cmake.subproject('hidapi_build_cmake', options: hidapi_build_options)

if (hidapi_build.target_list().contains('hidapi_winapi'))
hidapi_winapi_dep = hidapi_build.dependency('hidapi_winapi')
hidapi_dep = hidapi_winapi_dep
elif (hidapi_build.target_list().contains('hidapi_darwin'))
hidapi_darwin_dep = hidapi_build.dependency('hidapi_darwin')
hidapi_dep = hidapi_darwin_dep
elif (hidapi_build.target_list().contains('hidapi_hidraw'))
hidapi_hidraw_dep = hidapi_build.dependency('hidapi_hidraw')
hidapi_dep = hidapi_hidraw_dep
elif (hidapi_build.target_list().contains('hidapi_libusb'))
hidapi_libusb_dep = hidapi_build.dependency('hidapi_libusb')
hidapi_dep = hidapi_libusb_dep
endif
2 changes: 2 additions & 0 deletions subprojects/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This folder is used only to support [meson.build](../meson.build) `subproject` command
which would only look for a subproject in a "subprojects" directory.
10 changes: 10 additions & 0 deletions subprojects/hidapi_build_cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
cmake_minimum_required(VERSION 3.1.3 FATAL_ERROR)
Youw marked this conversation as resolved.
Show resolved Hide resolved
project(hidapi LANGUAGES C)

file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/root")

foreach(ROOT_ELEMENT CMakeLists.txt hidapi src windows linux mac libusb pc VERSION)
file(COPY "${CMAKE_CURRENT_LIST_DIR}/../../${ROOT_ELEMENT}" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/root/")
endforeach()

add_subdirectory("${CMAKE_CURRENT_BINARY_DIR}/root" hidapi_root)