From 6b65cd405a56d09b00a609ef43f2846c2cc349f7 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Mon, 7 Feb 2022 08:52:17 +0100 Subject: [PATCH] Build for Windows with libusb support Fixes #2773 PR #3011 --- BUILD.md | 6 ++++-- app/meson.build | 15 ++++++++++++++- app/prebuilt-deps/prepare-libusb.sh | 28 ++++++++++++++++++++++++++++ cross_win32.txt | 2 ++ cross_win64.txt | 2 ++ release.mk | 4 ++++ 6 files changed, 54 insertions(+), 3 deletions(-) create mode 100755 app/prebuilt-deps/prepare-libusb.sh diff --git a/BUILD.md b/BUILD.md index e32ab684..60be752d 100644 --- a/BUILD.md +++ b/BUILD.md @@ -161,7 +161,8 @@ install the required packages: ```bash # runtime dependencies pacman -S mingw-w64-x86_64-SDL2 \ - mingw-w64-x86_64-ffmpeg + mingw-w64-x86_64-ffmpeg \ + mingw-w64-x86_64-libusb # client build dependencies pacman -S mingw-w64-x86_64-make \ @@ -175,7 +176,8 @@ For a 32 bits version, replace `x86_64` by `i686`: ```bash # runtime dependencies pacman -S mingw-w64-i686-SDL2 \ - mingw-w64-i686-ffmpeg + mingw-w64-i686-ffmpeg \ + mingw-w64-i686-libusb # client build dependencies pacman -S mingw-w64-i686-make \ diff --git a/app/meson.build b/app/meson.build index 9cd009fe..a0086619 100644 --- a/app/meson.build +++ b/app/meson.build @@ -74,7 +74,7 @@ if v4l2_support src += [ 'src/v4l2_sink.c' ] endif -usb_support = get_option('usb') and host_machine.system() != 'windows' +usb_support = get_option('usb') if usb_support src += [ 'src/usb/aoa_hid.c', @@ -141,9 +141,22 @@ else include_directories: include_directories(ffmpeg_include_dir) ) + prebuilt_libusb = meson.get_cross_property('prebuilt_libusb') + prebuilt_libusb_root = meson.get_cross_property('prebuilt_libusb_root') + libusb_bin_dir = meson.current_source_dir() + '/prebuilt-deps/data/' + prebuilt_libusb + '/dll' + libusb_include_dir = 'prebuilt-deps/data/' + prebuilt_libusb_root + '/include' + + libusb = declare_dependency( + dependencies: [ + cc.find_library('libusb-1.0', dirs: libusb_bin_dir), + ], + include_directories: include_directories(libusb_include_dir) + ) + dependencies = [ ffmpeg, sdl2, + libusb, cc.find_library('mingw32') ] diff --git a/app/prebuilt-deps/prepare-libusb.sh b/app/prebuilt-deps/prepare-libusb.sh new file mode 100755 index 00000000..54ead536 --- /dev/null +++ b/app/prebuilt-deps/prepare-libusb.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash +set -e +DIR=$(dirname ${BASH_SOURCE[0]}) +cd "$DIR" +. common +mkdir -p "$PREBUILT_DATA_DIR" +cd "$PREBUILT_DATA_DIR" + +DEP_DIR=libusb-1.0.25 + +FILENAME=libusb-1.0.25.7z +SHA256SUM=3d1c98416f454026034b2b5d67f8a294053898cb70a8b489874e75b136c6674d + +if [[ -d "$DEP_DIR" ]] +then + echo "$DEP_DIR" found + exit 0 +fi + +get_file "https://github.com/libusb/libusb/releases/download/v1.0.25/$FILENAME" "$FILENAME" "$SHA256SUM" + +mkdir "$DEP_DIR" +cd "$DEP_DIR" + +7z x "../$FILENAME" \ + MinGW32/dll/libusb-1.0.dll \ + MinGW64/dll/libusb-1.0.dll \ + include / diff --git a/cross_win32.txt b/cross_win32.txt index db448a00..750dbd78 100644 --- a/cross_win32.txt +++ b/cross_win32.txt @@ -21,3 +21,5 @@ ffmpeg_avformat = 'avformat-58' ffmpeg_avutil = 'avutil-56' prebuilt_ffmpeg = 'ffmpeg-win32-4.3.1' prebuilt_sdl2 = 'SDL2-2.0.20/i686-w64-mingw32' +prebuilt_libusb_root = 'libusb-1.0.25' +prebuilt_libusb = prebuilt_libusb_root + '/MinGW32' diff --git a/cross_win64.txt b/cross_win64.txt index 9d169a71..114b0c22 100644 --- a/cross_win64.txt +++ b/cross_win64.txt @@ -21,3 +21,5 @@ ffmpeg_avformat = 'avformat-59' ffmpeg_avutil = 'avutil-57' prebuilt_ffmpeg = 'ffmpeg-win64-5.0' prebuilt_sdl2 = 'SDL2-2.0.20/x86_64-w64-mingw32' +prebuilt_libusb_root = 'libusb-1.0.25' +prebuilt_libusb = prebuilt_libusb_root + '/MinGW64' diff --git a/release.mk b/release.mk index aff9bd89..00d2389f 100644 --- a/release.mk +++ b/release.mk @@ -66,11 +66,13 @@ prepare-deps-win32: @app/prebuilt-deps/prepare-adb.sh @app/prebuilt-deps/prepare-sdl.sh @app/prebuilt-deps/prepare-ffmpeg-win32.sh + @app/prebuilt-deps/prepare-libusb.sh prepare-deps-win64: @app/prebuilt-deps/prepare-adb.sh @app/prebuilt-deps/prepare-sdl.sh @app/prebuilt-deps/prepare-ffmpeg-win64.sh + @app/prebuilt-deps/prepare-libusb.sh build-win32: prepare-deps-win32 [ -d "$(WIN32_BUILD_DIR)" ] || ( mkdir "$(WIN32_BUILD_DIR)" && \ @@ -107,6 +109,7 @@ dist-win32: build-server build-win32 cp app/prebuilt-deps/data/platform-tools-31.0.3/AdbWinApi.dll "$(DIST)/$(WIN32_TARGET_DIR)/" cp app/prebuilt-deps/data/platform-tools-31.0.3/AdbWinUsbApi.dll "$(DIST)/$(WIN32_TARGET_DIR)/" cp app/prebuilt-deps/data/SDL2-2.0.20/i686-w64-mingw32/bin/SDL2.dll "$(DIST)/$(WIN32_TARGET_DIR)/" + cp app/prebuilt-deps/data/libusb-1.0.25/MinGW32/dll/libusb-1.0.dll "$(DIST)/$(WIN32_TARGET_DIR)/" dist-win64: build-server build-win64 mkdir -p "$(DIST)/$(WIN64_TARGET_DIR)" @@ -125,6 +128,7 @@ dist-win64: build-server build-win64 cp app/prebuilt-deps/data/platform-tools-31.0.3/AdbWinApi.dll "$(DIST)/$(WIN64_TARGET_DIR)/" cp app/prebuilt-deps/data/platform-tools-31.0.3/AdbWinUsbApi.dll "$(DIST)/$(WIN64_TARGET_DIR)/" cp app/prebuilt-deps/data/SDL2-2.0.20/x86_64-w64-mingw32/bin/SDL2.dll "$(DIST)/$(WIN64_TARGET_DIR)/" + cp app/prebuilt-deps/data/libusb-1.0.25/MinGW64/dll/libusb-1.0.dll "$(DIST)/$(WIN64_TARGET_DIR)/" zip-win32: dist-win32 cd "$(DIST)/$(WIN32_TARGET_DIR)"; \