Skip to content

Commit

Permalink
CMake: Add option to use bundled libusb library
Browse files Browse the repository at this point in the history
  • Loading branch information
Biswa96 committed Aug 10, 2024
1 parent 3378069 commit 350235e
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ jobs:
mkdir build && cd build
cmake \
-DANDROID_TOOLS_USE_BUNDLED_FMT=ON \
-DANDROID_TOOLS_USE_BUNDLED_LIBUSB=ON \
..
make package_source
for x in sha1sum sha256sum sha512sum b2sum; do
Expand Down Expand Up @@ -147,6 +148,7 @@ jobs:
-DCMAKE_CXX_FLAGS="$CXXFLAGS" \
-DCMAKE_BUILD_TYPE=Release \
-DANDROID_TOOLS_USE_BUNDLED_FMT=ON \
-DANDROID_TOOLS_USE_BUNDLED_LIBUSB=ON \
-GNinja \
..
ninja --verbose
Expand Down Expand Up @@ -198,6 +200,7 @@ jobs:
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=$HOME/android-tools \
-DANDROID_TOOLS_USE_BUNDLED_FMT=ON \
-DANDROID_TOOLS_USE_BUNDLED_LIBUSB=ON \
-GNinja \
..
ninja --verbose
Expand Down
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,7 @@
shallow = true
path = vendor/libufdt
url = https://android.googlesource.com/platform/system/libufdt.git
[submodule "vendor/libusb"]
shallow=true
path = vendor/libusb
url = https://android.googlesource.com/platform/external/libusb.git
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ include(GNUInstallDirs)
# files are changed in vendor projects those can be retained with this option.
option(ANDROID_TOOLS_PATCH_VENDOR "Patch vendor projects using patches directory" ON)
option(ANDROID_TOOLS_USE_BUNDLED_FMT "Use bundled fmt library instead of system provided one" OFF)
option(ANDROID_TOOLS_USE_BUNDLED_LIBUSB "Use bundled libusb library instead of system provided one" OFF)

# Install bash/zsh completion files.
set(COMPLETION_COMMON_DIR "${CMAKE_INSTALL_FULL_DATADIR}/android-tools/completions")
Expand Down
7 changes: 6 additions & 1 deletion vendor/CMakeLists.adb.txt
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,15 @@ target_link_libraries(adb
PkgConfig::libbrotlienc
PkgConfig::liblz4
Threads::Threads
PkgConfig::libusb-1.0
z
PkgConfig::libzstd)

if(ANDROID_TOOLS_USE_BUNDLED_LIBUSB)
target_link_libraries(adb android_tools_libusb)
else()
target_link_libraries(adb PkgConfig::libusb-1.0)
endif()

if(APPLE)
target_link_libraries(adb
"-framework CoreFoundation"
Expand Down
48 changes: 48 additions & 0 deletions vendor/CMakeLists.libusb.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# SPDX-License-Identifier: Apache-2.0
# CMakeLists.libusb.txt: CMake file for libusb directory

set(android_tools_libusb_SOURCES
libusb/libusb/core.c
libusb/libusb/descriptor.c
libusb/libusb/hotplug.c
libusb/libusb/io.c
libusb/libusb/sync.c
libusb/libusb/strerror.c)

if(WIN32)
list(APPEND android_tools_libusb_SOURCES
libusb/libusb/os/events_windows.c
libusb/libusb/os/threads_windows.c
libusb/libusb/os/windows_common.c
libusb/libusb/os/windows_usbdk.c
libusb/libusb/os/windows_winusb.c)
elseif(APPLE)
list(APPEND android_tools_libusb_SOURCES
libusb/libusb/os/events_posix.c
libusb/libusb/os/darwin_usb.c
libusb/libusb/os/threads_posix.c)
else()
list(APPEND android_tools_libusb_SOURCES
libusb/libusb/os/events_posix.c
libusb/libusb/os/linux_usbfs.c
libusb/libusb/os/threads_posix.c
libusb/libusb/os/linux_netlink.c)
endif()

add_library(android_tools_libusb STATIC ${android_tools_libusb_SOURCES})

target_include_directories(android_tools_libusb PRIVATE libusb/libusb libusb/libusb/os)

if(WIN32)
target_include_directories(android_tools_libusb PRIVATE libusb/windows)
elseif(APPLE)
target_include_directories(android_tools_libusb PRIVATE libusb/darwin)

target_link_libraries(android_tools_libusb PRIVATE
"-framework CoreFoundation"
"-framework IOKit"
"-framework Security"
"-lobjc")
else()
target_include_directories(android_tools_libusb PRIVATE libusb/linux)
endif()
6 changes: 5 additions & 1 deletion vendor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,11 @@ pkg_check_modules(libbrotlidec REQUIRED IMPORTED_TARGET libbrotlidec)
pkg_check_modules(libbrotlienc REQUIRED IMPORTED_TARGET libbrotlienc)
pkg_check_modules(liblz4 REQUIRED IMPORTED_TARGET liblz4)
pkg_check_modules(libpcre2-8 REQUIRED IMPORTED_TARGET libpcre2-8)
pkg_check_modules(libusb-1.0 REQUIRED IMPORTED_TARGET libusb-1.0)
if(ANDROID_TOOLS_USE_BUNDLED_LIBUSB)
include(CMakeLists.libusb.txt)
else()
pkg_check_modules(libusb-1.0 REQUIRED IMPORTED_TARGET libusb-1.0)
endif()
pkg_check_modules(libzstd REQUIRED IMPORTED_TARGET libzstd)

find_package(Protobuf CONFIG)
Expand Down
1 change: 1 addition & 0 deletions vendor/libusb
Submodule libusb added at c96048

0 comments on commit 350235e

Please sign in to comment.