hidapi icon indicating copy to clipboard operation
hidapi copied to clipboard

Meson support

Open Youw opened this issue 3 years ago • 12 comments

As a wrapepr over CMake. Still experimental support and definitely not a primary build system.

Youw avatar May 04 '22 14:05 Youw

From IRC:

<> The hidapi PR is more cursed than any other possible use of the cmake module I ever did see
<> eye-wateringly bad
<> it also inherently doesn't work, it's a sandbox violation

I would add WrapDB support if possible. Something like

hidapi_dep = declare_dependency(
  include_directories : ???,
  link_with : hidapi,
)

neheb avatar Jun 22 '22 22:06 neheb

it also inherently doesn't work

Samples please. I've tried standalone builds and a subproject dependencies - all compiles and runs just fine.

it's a sandbox violation

Please elaborate.

Something like

Ultimately you need to specify sources + compilation flags + link flags per-platform. And if those are going to change - meson will be another full-scale build system which needs to be supported/updated, and that's not something I'm looking forward to.


CMake is introduced for HIDAPI as a long-term replacement for autotools+MSVC build scripts, which (CMake) provides all the same functionality as autotools and a bit more (e.g. convenience for CMake users).

Having full-scale Meson build system for HIDAPI only for Meson users - not something I vote for. Having Meson wraper over CMake for Meson users - something I'm willing to provide myself.

If that is ultimately not accepted by Meson users/community - someone needs to volunteer and support a separate build system. Possibly as it is done by cython-hidapi or node-hid - in a separate repository.

Youw avatar Jun 22 '22 23:06 Youw

The sandbox violation was before https://github.com/libusb/hidapi/pull/410/commits/ceb5e437bfbdc65bf91b6ab65555330be815943a . Now all files are copied.

neheb avatar Jun 23 '22 01:06 neheb

That I don't like either... Maybe I can improve it someohow - need to check.

Youw avatar Jun 23 '22 09:06 Youw

wrapdb now has a libusb wrap. might as well use it here.

neheb avatar Jul 11 '22 23:07 neheb

No idea about meson. But the branch does not seem to work.

mcuee@mcuees-Mac-mini hidapi_meson % git branch -a
  master
* meson_support
  remotes/origin/HEAD -> origin/master
  remotes/origin/connection-callback
  remotes/origin/get-descriptor
  remotes/origin/github_pages
  remotes/origin/hid_get_device_info
  remotes/origin/master
  remotes/origin/meson_support
  remotes/origin/windows_report_descriptor_reconstructor_unit_test

mcuee@mcuees-Mac-mini hidapi_meson % meson build_darwin && cd build_darwin
The Meson build system
Version: 0.63.0
Source dir: /Users/mcuee/build/hidapi/hidapi_test/hidapi_meson
Build dir: /Users/mcuee/build/hidapi/hidapi_test/hidapi_meson/build_darwin
Build type: native build
Project name: hidapi
Project version: 0.12.0
Host machine cpu family: aarch64
Host machine cpu: arm64

Executing subproject hidapi_build_cmake method cmake 

hidapi_build_cmake| Found CMake: /opt/homebrew/bin/cmake (3.23.2)

| Configuring the build directory with CMake version 3.23.2
| Running CMake with: -G Ninja -DCMAKE_INSTALL_PREFIX=/usr/local
|   - build directory:          /Users/mcuee/build/hidapi/hidapi_test/hidapi_meson/build_darwin/subprojects/hidapi_build_cmake/__CMake_build
|   - source directory:         /Users/mcuee/build/hidapi/hidapi_test/hidapi_meson/subprojects/hidapi_build_cmake
|   - toolchain file:           /Users/mcuee/build/hidapi/hidapi_test/hidapi_meson/build_darwin/subprojects/hidapi_build_cmake/__CMake_build/CMakeMesonToolchainFile.cmake
|   - preload file:             /opt/homebrew/Cellar/meson/0.63.0/libexec/lib/python3.10/site-packages/mesonbuild/cmake/data/preload.cmake
|   - trace args:               --trace-expand --trace-format=json-v1 --no-warn-unused-cli --trace-redirect=cmake_trace.txt
|   - disabled policy warnings: [CMP0025, CMP0047, CMP0056, CMP0060, CMP0065, CMP0066, CMP0067, CMP0082, CMP0089, CMP0102]

| CMake Warning (dev) in CMakeLists.txt:
| No project() command is present.  The top-level CMakeLists.txt file must
| contain a literal, direct call to the project() command.  Add a line of
| code such as

| project(ProjectName)

| near the top of the file, but after cmake_minimum_required().

| CMake is pretending there is a "project(Project)" command on the first
| line.
| This warning is for project developers.  Use -Wno-dev to suppress it.
| Running with expanded trace output on.
| Not searching for unused variables given on the command line.
| Trace will be written to cmake_trace.txt

| -- The C compiler identification is AppleClang 13.1.6.13160021
| -- The CXX compiler identification is AppleClang 13.1.6.13160021
| -- Detecting C compiler ABI info
| -- Detecting C compiler ABI info - done
| -- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc - skipped
| -- Detecting C compile features
| -- Detecting C compile features - done
| -- Detecting CXX compiler ABI info
| -- Detecting CXX compiler ABI info - done
| -- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++ - skipped
| -- Detecting CXX compile features
| -- Detecting CXX compile features - done
| -- Looking for pthread.h
| -- Looking for pthread.h - found
| -- Performing Test CMAKE_HAVE_LIBC_PTHREAD
| -- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
| -- Found Threads: TRUE
| -- Configuring done
| -- Generating done
| -- Build files have been written to: /Users/mcuee/build/hidapi/hidapi_test/hidapi_meson/build_darwin/subprojects/hidapi_build_cmake/__CMake_build

hidapi_build_cmake| CMake configuration: SUCCEEDED
hidapi_build_cmake| CMake project Project has 2 build targets.

cmake-ast| Processing generated meson AST
cmake-ast| Build file: /Users/mcuee/build/hidapi/hidapi_test/hidapi_meson/build_darwin/subprojects/hidapi_build_cmake/meson.build

hidapi_build_cmake| Project name: Project
hidapi_build_cmake| Project version: undefined
hidapi_build_cmake| C compiler for the host machine: cc (clang 13.1.6 "Apple clang version 13.1.6 (clang-1316.0.21.2.5)")
hidapi_build_cmake| C linker for the host machine: cc ld64 764

subprojects/hidapi_build_cmake/meson.build:5:0: ERROR: Sandbox violation: Tried to grab file hid.c outside current (sub)project.

A full log can be found at /Users/mcuee/build/hidapi/hidapi_test/hidapi_meson/build_darwin/meson-logs/meson-log.txt

meson-log.txt

mcuee avatar Jul 16 '22 13:07 mcuee

Are you sure this is the latest commit of the branch?

Youw avatar Jul 16 '22 13:07 Youw

Maybe the build directory has to be outside of the sourse tree? E.g.: meson ../build_darwin && cd ../build_darwin

Youw avatar Jul 16 '22 13:07 Youw

Maybe the build directory has to be outside of the sourse tree? E.g.: meson ../build_darwin && cd ../build_darwin

That is it. Thanks.

mcuee@mcuees-Mac-mini hidapi_meson % meson ../build_darwin && cd ../build_darwin
The Meson build system
Version: 0.63.0
Source dir: /Users/mcuee/build/hidapi/hidapi_test/hidapi_meson
Build dir: /Users/mcuee/build/hidapi/hidapi_test/build_darwin
Build type: native build
Project name: hidapi
Project version: 0.12.0
Host machine cpu family: aarch64
Host machine cpu: arm64

Executing subproject hidapi_build_cmake method cmake 

hidapi_build_cmake| Found CMake: /opt/homebrew/bin/cmake (3.23.2)

| Configuring the build directory with CMake version 3.23.2
| Running CMake with: -G Ninja -DCMAKE_INSTALL_PREFIX=/usr/local
|   - build directory:          /Users/mcuee/build/hidapi/hidapi_test/build_darwin/subprojects/hidapi_build_cmake/__CMake_build
|   - source directory:         /Users/mcuee/build/hidapi/hidapi_test/hidapi_meson/subprojects/hidapi_build_cmake
|   - toolchain file:           /Users/mcuee/build/hidapi/hidapi_test/build_darwin/subprojects/hidapi_build_cmake/__CMake_build/CMakeMesonToolchainFile.cmake
|   - preload file:             /opt/homebrew/Cellar/meson/0.63.0/libexec/lib/python3.10/site-packages/mesonbuild/cmake/data/preload.cmake
|   - trace args:               --trace-expand --trace-format=json-v1 --no-warn-unused-cli --trace-redirect=cmake_trace.txt
|   - disabled policy warnings: [CMP0025, CMP0047, CMP0056, CMP0060, CMP0065, CMP0066, CMP0067, CMP0082, CMP0089, CMP0102]

| CMake Warning (dev) in CMakeLists.txt:
| No project() command is present.  The top-level CMakeLists.txt file must
| contain a literal, direct call to the project() command.  Add a line of
| code such as

| project(ProjectName)

| near the top of the file, but after cmake_minimum_required().

| CMake is pretending there is a "project(Project)" command on the first
| line.
| This warning is for project developers.  Use -Wno-dev to suppress it.
| Running with expanded trace output on.
| Not searching for unused variables given on the command line.
| Trace will be written to cmake_trace.txt

| -- The C compiler identification is AppleClang 13.1.6.13160021
| -- The CXX compiler identification is AppleClang 13.1.6.13160021
| -- Detecting C compiler ABI info
| -- Detecting C compiler ABI info - done
| -- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc - skipped
| -- Detecting C compile features
| -- Detecting C compile features - done
| -- Detecting CXX compiler ABI info
| -- Detecting CXX compiler ABI info - done
| -- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++ - skipped
| -- Detecting CXX compile features
| -- Detecting CXX compile features - done
| -- Looking for pthread.h
| -- Looking for pthread.h - found
| -- Performing Test CMAKE_HAVE_LIBC_PTHREAD
| -- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
| -- Found Threads: TRUE
| -- Configuring done
| -- Generating done
| -- Build files have been written to: /Users/mcuee/build/hidapi/hidapi_test/build_darwin/subprojects/hidapi_build_cmake/__CMake_build

hidapi_build_cmake| CMake configuration: SUCCEEDED
hidapi_build_cmake| CMake project Project has 2 build targets.

cmake-ast| Processing generated meson AST
cmake-ast| Build file: /Users/mcuee/build/hidapi/hidapi_test/build_darwin/subprojects/hidapi_build_cmake/meson.build

hidapi_build_cmake| Project name: Project
hidapi_build_cmake| Project version: undefined
hidapi_build_cmake| C compiler for the host machine: cc (clang 13.1.6 "Apple clang version 13.1.6 (clang-1316.0.21.2.5)")
hidapi_build_cmake| C linker for the host machine: cc ld64 764
hidapi_build_cmake| Build targets in project: 1
hidapi_build_cmake| Subproject hidapi_build_cmake finished.


Build targets in project: 1

hidapi 0.12.0

  Subprojects
    hidapi_build_cmake: YES

Found ninja-1.11.0 at /opt/homebrew/bin/ninja

mcuee@mcuees-Mac-mini build_darwin % meson compile
[2/2] Linking target subprojects/hidapi_build_cmake/libhidapi_darwin.dylib

mcuee@mcuees-Mac-mini build_darwin % meson test
No tests defined.

mcuee avatar Jul 16 '22 13:07 mcuee

@Youw How to build hidtest using meson?

mcuee avatar Jul 16 '22 13:07 mcuee

There is no way right now. Unless one writes a Mason build script for hidtest

Youw avatar Jul 16 '22 14:07 Youw

There is no way right now. Unless one writes a Mason build script for hidtest

I see.

Test of latest version under MSYS2 mingw64.

MINGW64 /c/work/libusb/hidapi_test/hidapi_meson
$ git checkout meson_support
branch 'meson_support' set up to track 'origin/meson_support'.
Switched to a new branch 'meson_support'

$ meson ../build_mingw64 && cd ../build_mingw64
The Meson build system
Version: 0.62.1
Source dir: C:/work/libusb/hidapi_test/hidapi_meson
Build dir: C:/work/libusb/hidapi_test/build_mingw64
Build type: native build
Project name: hidapi
Project version: 0.12.0
Host machine cpu family: x86_64
Host machine cpu: x86_64

Executing subproject hidapi_build_cmake method cmake

hidapi_build_cmake| Found CMake: C:\msys64\mingw64\bin/cmake.EXE (3.23.1)

| Configuring the build directory with CMake version 3.23.1
| Running CMake with: -G Ninja -DCMAKE_INSTALL_PREFIX=C:/msys64/mingw64
|   - build directory:          C:/work/libusb/hidapi_test/build_mingw64/subprojects/hidapi_build_cmake/__CMake_build
|   - source directory:         C:/work/libusb/hidapi_test/hidapi_meson/subprojects/hidapi_build_cmake
|   - toolchain file:           C:/work/libusb/hidapi_test/build_mingw64/subprojects/hidapi_build_cmake/__CMake_build/CMakeMesonToolchainFile.cmake
|   - preload file:             C:/msys64/mingw64/lib/python3.9/site-packages/mesonbuild/cmake/data/preload.cmake
|   - trace args:               --trace-expand --trace-format=json-v1 --no-warn-unused-cli --trace-redirect=cmake_trace.txt
|   - disabled policy warnings: [CMP0025, CMP0047, CMP0056, CMP0060, CMP0065, CMP0066, CMP0067, CMP0082, CMP0089, CMP0102]

| Running with expanded trace output on.
| Not searching for unused variables given on the command line.
| Trace will be written to cmake_trace.txt
| -- The C compiler identification is GNU 11.3.0
| -- Detecting C compiler ABI info
| -- Detecting C compiler ABI info - done
| -- Check for working C compiler: C:/msys64/mingw64/bin/cc.exe - skipped
| -- Detecting C compile features
| -- Detecting C compile features - done
| -- Configuring done
| -- Generating done
| -- Build files have been written to: C:/work/libusb/hidapi_test/build_mingw64/subprojects/hidapi_build_cmake/__CMake_build

hidapi_build_cmake| CMake configuration: SUCCEEDED
hidapi_build_cmake| CMake project hidapi has 2 build targets.

cmake-ast| Processing generated meson AST
cmake-ast| Build file: C:/work/libusb/hidapi_test/build_mingw64/subprojects/hidapi_build_cmake/meson.build

hidapi_build_cmake| Project name: hidapi
hidapi_build_cmake| Project version: undefined
hidapi_build_cmake| C compiler for the host machine: cc (gcc 11.3.0 "cc (Rev1, Built by MSYS2 project) 11.3.0")
hidapi_build_cmake| C linker for the host machine: cc ld.bfd 2.38
hidapi_build_cmake| Build targets in project: 1
hidapi_build_cmake| Subproject hidapi_build_cmake finished.


Build targets in project: 1

hidapi 0.12.0

  Subprojects
    hidapi_build_cmake: YES

Found ninja-1.10.2 at C:\msys64\mingw64\bin/ninja.EXE

$ meson compile
[2/2] Linking target subprojects/hidapi_build_cmake/libhidapi_winapi.dll

mcuee avatar Jul 16 '22 14:07 mcuee