Skip to content

Commit

Permalink
Add meson.build as a wrapper over CMake (signal11#410)
Browse files Browse the repository at this point in the history
- not an independent build system, but a wrapper over CMake;
- may be used as a standalone Meson build or as a subproject;
  • Loading branch information
Youw committed Sep 10, 2022
1 parent dbd1681 commit 8068574
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 2 deletions.
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)
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)

0 comments on commit 8068574

Please sign in to comment.