Skip to content

Meson support#410

Merged
Youw merged 14 commits intomasterfrom
meson_support
Sep 10, 2022
Merged

Meson support#410
Youw merged 14 commits intomasterfrom
meson_support

Conversation

@Youw
Copy link
Member

@Youw Youw commented May 4, 2022

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

@Youw Youw marked this pull request as draft May 4, 2022 14:23
@Youw Youw mentioned this pull request May 4, 2022
@mcuee mcuee added the build system/CI Anything related to building the project or running on CI label May 5, 2022
@Youw Youw force-pushed the meson_support branch from e94d514 to e89a7d7 Compare May 5, 2022 11:59
@Youw Youw force-pushed the meson_support branch from 718bf37 to 496e78f Compare May 5, 2022 12:56
@Youw Youw force-pushed the meson_support branch from bfdd42a to 9d6c110 Compare May 5, 2022 13:01
@Youw Youw requested a review from z3ntu May 5, 2022 13:14
@Youw Youw marked this pull request as ready for review May 5, 2022 13:18
@Youw Youw mentioned this pull request Jun 12, 2022
# Conflicts:
#	.github/workflows/builds.yml
@neheb
Copy link

neheb commented Jun 22, 2022

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,
)
@Youw
Copy link
Member Author

Youw commented Jun 22, 2022

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.

@neheb
Copy link

neheb commented Jun 23, 2022

The sandbox violation was before ceb5e43 . Now all files are copied.

@Youw
Copy link
Member Author

Youw commented Jun 23, 2022

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

@neheb
Copy link

neheb commented Jul 11, 2022

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

@mcuee
Copy link
Member

mcuee commented Jul 16, 2022

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

@Youw
Copy link
Member Author

Youw commented Jul 16, 2022

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

@Youw
Copy link
Member Author

Youw commented Jul 16, 2022

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

@mcuee
Copy link
Member

mcuee commented Jul 16, 2022

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
Copy link
Member

mcuee commented Jul 16, 2022

@Youw
How to build hidtest using meson?

@Youw
Copy link
Member Author

Youw commented Jul 16, 2022

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

@mcuee
Copy link
Member

mcuee commented Jul 16, 2022

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
@Youw Youw merged commit 8068574 into master Sep 10, 2022
@Youw Youw deleted the meson_support branch September 10, 2022 13:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build system/CI Anything related to building the project or running on CI

3 participants