1# Copyright (c) 2021 Huawei Device Co., Ltd. 2# 3# Permission is hereby granted, free of charge, to any person obtaining a copy 4# of this software and associated documentation files (the "Software"), to 5# deal in the Software without restriction, including without limitation the 6# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7# sell copies of the Software, and to permit persons to whom the Software is 8# furnished to do so, subject to the following conditions: 9# 10# The above copyright notice and this permission notice shall be included in 11# all copies or substantial portions of the Software. 12# 13# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19# IN THE SOFTWARE. 20 21import("//build/ohos.gni") 22 23LIBUSB_DIR = rebase_path("//third_party/libusb") 24exec_script("install.sh", [ "${LIBUSB_DIR}" ]) 25 26SRC_PATH = rebase_path("//third_party/libusb/libusb-1.0.26") 27 28common_source = [ 29 "${SRC_PATH}/libusb/core.c", 30 "${SRC_PATH}/libusb/descriptor.c", 31 "${SRC_PATH}/libusb/hotplug.c", 32 "${SRC_PATH}/libusb/io.c", 33 "${SRC_PATH}/libusb/sync.c", 34 "${SRC_PATH}/libusb/strerror.c", 35] 36 37# Configuration for libusb itself. 38config("libusb_config") { 39 include_dirs = [ 40 "${SRC_PATH}/libusb", 41 "${SRC_PATH}/libusb/os", 42 ] 43 cflags = [ 44 "-U__ANDROID__", 45 "-UUSE_UDEV", 46 "-Wno-#warnings", 47 "-Wno-error=sign-compare", 48 "-Wno-error=switch", 49 "-Wno-error=pragma-pack", 50 ] 51 if (is_linux || is_ohos) { 52 include_dirs += [ "${LIBUSB_DIR}/linux" ] 53 cflags += [ "-DPLATFORM_POSIX" ] 54 } else if (is_mingw || is_win) { 55 cflags += [ 56 "-Werror", 57 "-Wno-unused-function", 58 "-Wno-unused-parameter", 59 "-DPLATFORM_WINDOWS", 60 ] 61 include_dirs += [ "${LIBUSB_DIR}/windows" ] 62 } else if (is_mac) { 63 cflags += [ 64 "-Wno-unused-parameter", 65 "-Wno-deprecated-declarations", 66 "-DPLATFORM_POSIX", 67 ] 68 include_dirs += [ "${LIBUSB_DIR}/darwin" ] 69 frameworks = [ 70 "CoreFoundation.framework", 71 "IOKit.framework", 72 "Security.framework", 73 ] 74 libs = [ "objc" ] 75 } 76} 77 78ohos_source_set("libusb_source") { 79 configs = [ ":libusb_config" ] 80 sources = common_source 81 82 if (is_mac) { 83 sources += [ 84 "${SRC_PATH}/libusb/os/darwin_usb.c", 85 "${SRC_PATH}/libusb/os/events_posix.c", 86 "${SRC_PATH}/libusb/os/threads_posix.c", 87 ] 88 } else if (is_mingw || is_win) { 89 sources += [ 90 "${SRC_PATH}/libusb/os/events_windows.c", 91 "${SRC_PATH}/libusb/os/threads_windows.c", 92 "${SRC_PATH}/libusb/os/windows_common.c", 93 "${SRC_PATH}/libusb/os/windows_usbdk.c", 94 "${SRC_PATH}/libusb/os/windows_winusb.c", 95 ] 96 } else if (is_linux || is_ohos) { 97 sources += [ 98 "${SRC_PATH}/libusb/os/events_posix.c", 99 "${SRC_PATH}/libusb/os/linux_netlink.c", 100 "${SRC_PATH}/libusb/os/linux_usbfs.c", 101 "${SRC_PATH}/libusb/os/threads_posix.c", 102 ] 103 } 104} 105 106config("libusb_public_config") { 107 include_dirs = [ "${SRC_PATH}" ] 108} 109 110ohos_shared_library("libusb") { 111 deps = [ ":libusb_source" ] 112 public_configs = [ ":libusb_public_config" ] 113 output_name = "libusb_shared" 114} 115