Skip to content

Commit 8068574

Browse files
authored
Add meson.build as a wrapper over CMake (signal11#410)
- not an independent build system, but a wrapper over CMake; - may be used as a standalone Meson build or as a subproject;
1 parent dbd1681 commit 8068574

File tree

5 files changed

+68
-2
lines changed

5 files changed

+68
-2
lines changed

.github/workflows/builds.yml

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ jobs:
3737
- uses: actions/checkout@v2
3838
with:
3939
path: hidapisrc
40+
- name: Install dependencies
41+
run: brew install meson ninja
4042
- name: Configure CMake
4143
run: |
4244
rm -rf build install
@@ -58,6 +60,11 @@ jobs:
5860
install/framework/lib/hidapi.framework/Headers/hidapi.h, \
5961
install/framework/lib/hidapi.framework/Headers/hidapi_darwin.h"
6062
allow_failure: true
63+
- name: Check Meson build
64+
run: |
65+
meson setup build_meson hidapisrc
66+
cd build_meson
67+
ninja
6168
6269
ubuntu-cmake:
6370

@@ -70,7 +77,8 @@ jobs:
7077
- name: Install dependencies
7178
run: |
7279
sudo apt update
73-
sudo apt install libudev-dev libusb-1.0-0-dev
80+
sudo apt install libudev-dev libusb-1.0-0-dev python3-pip ninja-build
81+
sudo -H pip3 install meson
7482
- name: Configure CMake
7583
run: |
7684
rm -rf build install
@@ -94,6 +102,11 @@ jobs:
94102
install/static/include/hidapi/hidapi.h, \
95103
install/static/include/hidapi/hidapi_libusb.h"
96104
allow_failure: true
105+
- name: Check Meson build
106+
run: |
107+
meson setup build_meson hidapisrc
108+
cd build_meson
109+
ninja
97110
98111
windows-cmake:
99112

@@ -103,6 +116,11 @@ jobs:
103116
- uses: actions/checkout@v2
104117
with:
105118
path: hidapisrc
119+
- name: Install dependencies
120+
run: |
121+
choco install ninja
122+
pip3 install meson
123+
refreshenv
106124
- name: Configure CMake MSVC
107125
shell: cmd
108126
run: |
@@ -155,6 +173,14 @@ jobs:
155173
install/mingw/include/hidapi/hidapi_winapi.h"
156174
allow_failure: true
157175

176+
- name: Check Meson build
177+
shell: cmd
178+
run: |
179+
call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat"
180+
meson setup build_meson hidapisrc
181+
cd build_meson
182+
ninja
183+
158184
windows-msbuild:
159185

160186
runs-on: windows-latest

BUILD.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ For various reasons you may need to build HIDAPI on your own.
1919
It can be done in several different ways:
2020
- using [CMake](BUILD.cmake.md);
2121
- using [Autotools](BUILD.autotools.md) (deprecated);
22-
- using [manual makefiles](#building-the-manual-way-on-unix-platforms).
22+
- using [manual makefiles](#building-the-manual-way-on-unix-platforms);
23+
- using `Meson` (requires CMake);
2324

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

34+
**Meson** build system for HIDAPI is designed as a [wrapper](https://mesonbuild.com/CMake-module.html) over CMake build script.
35+
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>
36+
In the Meson script of your project you need a `hidapi = subproject('hidapi')` subproject, and `hidapi.get_variable('hidapi_dep')` as your dependency.
37+
There are also backend/platform-specific dependencies available: `hidapi_winapi`, `hidapi_darwin`, `hidapi_hidraw`, `hidapi_libusb`.
38+
3339
If you don't know where to start to build HIDAPI, we recommend starting with [CMake](BUILD.cmake.md) build.
3440

3541
## Prerequisites:

meson.build

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
project('hidapi', meson_version: '>=0.57.0', version: files('VERSION'))
2+
3+
cmake = import('cmake')
4+
5+
hidapi_build_options = cmake.subproject_options()
6+
hidapi_build_options.set_install(true)
7+
8+
hidapi_build = cmake.subproject('hidapi_build_cmake', options: hidapi_build_options)
9+
10+
if (hidapi_build.target_list().contains('hidapi_winapi'))
11+
hidapi_winapi_dep = hidapi_build.dependency('hidapi_winapi')
12+
hidapi_dep = hidapi_winapi_dep
13+
elif (hidapi_build.target_list().contains('hidapi_darwin'))
14+
hidapi_darwin_dep = hidapi_build.dependency('hidapi_darwin')
15+
hidapi_dep = hidapi_darwin_dep
16+
elif (hidapi_build.target_list().contains('hidapi_hidraw'))
17+
hidapi_hidraw_dep = hidapi_build.dependency('hidapi_hidraw')
18+
hidapi_dep = hidapi_hidraw_dep
19+
elif (hidapi_build.target_list().contains('hidapi_libusb'))
20+
hidapi_libusb_dep = hidapi_build.dependency('hidapi_libusb')
21+
hidapi_dep = hidapi_libusb_dep
22+
endif

subprojects/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
This folder is used only to support [meson.build](../meson.build) `subproject` command
2+
which would only look for a subproject in a "subprojects" directory.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
cmake_minimum_required(VERSION 3.1.3 FATAL_ERROR)
2+
project(hidapi LANGUAGES C)
3+
4+
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/root")
5+
6+
foreach(ROOT_ELEMENT CMakeLists.txt hidapi src windows linux mac libusb pc VERSION)
7+
file(COPY "${CMAKE_CURRENT_LIST_DIR}/../../${ROOT_ELEMENT}" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/root/")
8+
endforeach()
9+
10+
add_subdirectory("${CMAKE_CURRENT_BINARY_DIR}/root" hidapi_root)

0 commit comments

Comments
 (0)