summaryrefslogtreecommitdiffstats
path: root/third_party/libusb/BUILD.gn
blob: cce639ea327da46bc41dc93d6468770a284f4bd0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

assert(!is_android && !is_ios)

import("//build/config/features.gni")

config("libusb_config") {
  include_dirs = [ "src/libusb" ]
}

static_library("libusb") {
  sources = [
    "src/config.h",
    "src/libusb/core.c",
    "src/libusb/descriptor.c",
    "src/libusb/hotplug.c",
    "src/libusb/hotplug.h",
    "src/libusb/interrupt.c",
    "src/libusb/interrupt.h",
    "src/libusb/io.c",
    "src/libusb/libusb.h",
    "src/libusb/libusbi.h",
    "src/libusb/os/darwin_usb.c",
    "src/libusb/os/darwin_usb.h",
    "src/libusb/os/poll_posix.c",
    "src/libusb/os/poll_posix.h",
    "src/libusb/os/poll_windows.c",
    "src/libusb/os/poll_windows.h",
    "src/libusb/os/threads_posix.c",
    "src/libusb/os/threads_posix.h",
    "src/libusb/os/threads_windows.c",
    "src/libusb/os/threads_windows.h",
    "src/libusb/os/windows_common.h",
    "src/libusb/os/windows_usb.c",
    "src/libusb/os/windows_usb.h",
    "src/libusb/strerror.c",
    "src/libusb/sync.c",
    "src/libusb/version.h",
    "src/libusb/version_nano.h",
    "src/msvc/config.h",
    "src/msvc/inttypes.h",
    "src/msvc/stdint.h",
  ]
  deps = []
  include_dirs = [ "src/libusb/os" ]

  config("libusb_warnings") {
    if (is_clang) {
      # guid_eq in windows_usb.c is unused.
      cflags = [ "-Wno-unused-function" ]
      if (is_linux && !use_udev) {
        cflags += [ "-Wno-pointer-sign" ]
      }
    }
  }
  configs -= [ "//build/config/compiler:chromium_code" ]
  configs += [ "//build/config/compiler:no_chromium_code" ]
  configs += [ ":libusb_warnings" ]

  public_configs = [ ":libusb_config" ]

  if (is_posix) {
    defines = [
      "DEFAULT_VISIBILITY=",
      "HAVE_GETTIMEOFDAY=1",
      "HAVE_POLL_H=1",
      "HAVE_SYS_TIME_H=1",
      "LIBUSB_DESCRIBE=\"1.0.16\"",
      "POLL_NFDS_TYPE=nfds_t",
      "THREADS_POSIX=1",
    ]
  }

  if (is_mac) {
    defines += [ "OS_DARWIN=1" ]
  } else {
    sources -= [
      "src/libusb/os/darwin_usb.c",
      "src/libusb/os/darwin_usb.h",
    ]
  }

  if (is_linux) {
    sources += [
      "src/libusb/os/linux_usbfs.c",
      "src/libusb/os/linux_usbfs.h",
    ]
    defines += [
      "OS_LINUX=1",
      "_GNU_SOURCE=1",
    ]
  }

  if (use_udev) {
    sources += [ "src/libusb/os/linux_udev.cc" ]
    defines += [
      "HAVE_LIBUDEV=1",
      "USE_UDEV=1",
    ]
    deps += [ "//build/linux:udev" ]
  }

  if (is_linux && !use_udev) {
    sources += [ "src/libusb/os/linux_netlink.c" ]
    defines += [ "HAVE_LINUX_NETLINK_H" ]
  }

  if (is_win) {
    include_dirs += [ "src/msvc" ]
    sources -= [
      "src/libusb/os/poll_posix.c",
      "src/libusb/os/threads_posix.c",
    ]
    libs = [ "setupapi.lib" ]
  } else {
    include_dirs += [ "src" ]
    sources -= [
      "src/libusb/os/poll_windows.c",
      "src/libusb/os/poll_windows.h",
      "src/libusb/os/threads_windows.c",
      "src/libusb/os/threads_windows.h",
      "src/libusb/os/windows_common.h",
      "src/libusb/os/windows_usb.c",
      "src/libusb/os/windows_usb.h",
      "src/msvc/config.h",
      "src/msvc/inttypes.h",
      "src/msvc/stdint.h",
    ]
  }
}