diff --git a/.github/workflows/builds.yml b/.github/workflows/builds.yml
index c8bbc904..89b3a656 100644
--- a/.github/workflows/builds.yml
+++ b/.github/workflows/builds.yml
@@ -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
@@ -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:
@@ -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
@@ -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:
@@ -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: |
@@ -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
diff --git a/BUILD.md b/BUILD.md
index e348e3ca..24974707 100644
--- a/BUILD.md
+++ b/BUILD.md
@@ -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).
@@ -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.
+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:
diff --git a/meson.build b/meson.build
new file mode 100644
index 00000000..d7867cb4
--- /dev/null
+++ b/meson.build
@@ -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
diff --git a/subprojects/README.md b/subprojects/README.md
new file mode 100644
index 00000000..8ba8f60c
--- /dev/null
+++ b/subprojects/README.md
@@ -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.
\ No newline at end of file
diff --git a/subprojects/hidapi_build_cmake/CMakeLists.txt b/subprojects/hidapi_build_cmake/CMakeLists.txt
new file mode 100644
index 00000000..80aed67d
--- /dev/null
+++ b/subprojects/hidapi_build_cmake/CMakeLists.txt
@@ -0,0 +1,10 @@
+cmake_minimum_required(VERSION 3.1.3 FATAL_ERROR)
+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)