summaryrefslogtreecommitdiffstats
path: root/chromium/chrome/browser/browser_switcher/bho/BUILD.gn
blob: 66a05b4e65cb19cc2332337bbab93684b7ed7a2e (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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# Copyright 2019 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.

import("//build/config/compiler/compiler.gni")
import("//build/toolchain/win/midl.gni")
import("//testing/test.gni")

assert(is_win)
assert(target_cpu == "x86" || target_cpu == "x64")

declare_args() {
  # If true, compile a BHO that doesn't depend on the CRT to significantly
  # minimize binary size.
  use_mini_bho = false
}

shared_library("browser_switcher_bho") {
  if (current_cpu == "x64") {
    # Name the 32-bit and 64-bit output differently, since they'll be copied to
    # the same directory.
    output_name = "browser_switcher_bho_64"
  }

  visibility = [
    ":browser_switcher_dlls",
    ":copy_browser_switcher_binaries",
  ]

  defines = [
    # Needed to build COM objects that will be hosted in a DLL.
    "_WINDLL",
  ]

  if (use_mini_bho) {
    configs += [ "//build/config/win:sdk_link" ]

    no_default_deps = true

    libs = [
      # For buffer overflow checks with the /GS flag.
      "bufferoverflowU.lib",
    ]
    ldflags = [
      "/NODEFAULTLIB",
      "/ENTRY:DllMain",
    ]
  }

  # TODO(nicolaso): avoid code duplication, by using BrowserSwitcherSitelist and
  # AlternativeBrowserDriver classes from chrome/browser_switcher/.
  if (use_mini_bho) {
    sources = [
      "mini_bho.cc",
      "mini_bho.def",
      "mini_bho_util.cc",
      "mini_bho_util.h",
    ]
  } else {
    sources = [
      "//base/win/atl.h",
      "bho.cc",
      "bho.h",
      "browser_switcher_core.cc",
      "browser_switcher_core.h",
      "ie_bho.cc",
      "ie_bho.def",
      "logging.cc",
      "logging.h",
      "resource.h",
    ]
  }
  deps = [
    ":ie_bho_idl",
  ]
}

test("browser_switcher_bho_unittests") {
  sources = [
    "mini_bho_util.cc",
    "mini_bho_util.h",
    "mini_bho_util_unittest.cc",
  ]
  deps = [
    "//base",
    "//base/test:test_support",
    "//testing/gtest",
  ]
}

if (is_clang) {
  browser_switcher_x64_toolchain = "//build/toolchain/win:win_clang_x64"
  browser_switcher_x86_toolchain = "//build/toolchain/win:win_clang_x86"
} else {
  browser_switcher_x64_toolchain = "//build/toolchain/win:x64"
  browser_switcher_x86_toolchain = "//build/toolchain/win:x86"
}

browser_switcher_x64_label =
    ":browser_switcher_bho($browser_switcher_x64_toolchain)"
browser_switcher_x86_label =
    ":browser_switcher_bho($browser_switcher_x86_toolchain)"

copy("copy_browser_switcher_binaries") {
  # Make sure we have both bitnesses in the root out directory.
  if (target_cpu == "x86") {
    cross_build_label = browser_switcher_x64_label
    cross_build_dll = "browser_switcher_bho_64.dll"
  } else if (target_cpu == "x64") {
    cross_build_label = browser_switcher_x86_label
    cross_build_dll = "browser_switcher_bho.dll"
  }

  cross_build_out_dir = get_label_info(cross_build_label, "root_out_dir")

  sources = [
    "$cross_build_out_dir/$cross_build_dll",
  ]
  if (symbol_level > 0) {
    sources += [ "$cross_build_out_dir/$cross_build_dll.pdb" ]
  }

  outputs = [
    "$root_out_dir/{{source_file_part}}",
  ]
  deps = [
    browser_switcher_x64_label,
    browser_switcher_x86_label,
  ]
}

group("browser_switcher_dlls") {
  # Build a DLL for each bitness, and put them in the root out dir.
  deps = [
    ":copy_browser_switcher_binaries",
    browser_switcher_x64_label,
    browser_switcher_x86_label,
  ]
}

midl("ie_bho_idl") {
  sources = [
    "ie_bho_idl.idl",
  ]

  # We have a custom output directory (that excludes the toolchain details).
  generated_dir =
      "//third_party/win_build_output/midl/chrome/browser/browser_switcher/bho"
}