aboutsummaryrefslogtreecommitdiffhomepage
path: root/gn/BUILDCONFIG.gn
blob: e294854aa7c4bc6fe772fd53d90d9b01b52bac27 (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
150
151
152
153
154
155
156
# Copyright 2016 Google Inc.
#
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

# It's best to keep the names and defaults of is_foo flags consistent with Chrome.

declare_args() {
  is_official_build = false
  is_component_build = false
  ndk = ""
  ndk_api = 0  # 0 == picked automatically for target_cpu.
  sanitize = ""
}
declare_args() {
  is_debug = !is_official_build
}

assert(!(is_debug && is_official_build))

# Platform detection
if (target_os == "") {
  target_os = host_os
  if (ndk != "") {
    target_os = "android"
  }
}
if (current_os == "") {
  current_os = target_os
}

is_android = current_os == "android"
is_fuchsia = current_os == "fuchsia"
is_ios = current_os == "ios"
is_linux = current_os == "linux"
is_mac = current_os == "mac"
is_win = current_os == "win"

if (target_cpu == "") {
  target_cpu = host_cpu
  if (is_android) {
    target_cpu = "arm64"
  }
}
if (current_cpu == "") {
  current_cpu = target_cpu
}

if (is_android) {
  ndk_host = ""
  ndk_target = ""
  ndk_platform = ""
  ndk_stdlib = ""
  ndk_gccdir = ""

  if (ndk_api == 0) {
    ndk_api = 18
    if (target_cpu == "arm64" || target_cpu == "mips64el" ||
        target_cpu == "x64") {
      ndk_api = 21
    }
  }

  if (host_os == "linux") {
    ndk_host = "linux-x86_64"
  } else if (host_os == "mac") {
    ndk_host = "darwin-x86_64"
  }

  if (target_cpu == "arm64") {
    ndk_target = "aarch64-linux-android"
    ndk_platform = "android-${ndk_api}/arch-arm64"
    ndk_stdlib = "arm64-v8a"
    ndk_gccdir = ndk_target
  } else if (target_cpu == "arm") {
    ndk_target = "arm-linux-androideabi"
    ndk_platform = "android-${ndk_api}/arch-arm"
    ndk_stdlib = "armeabi-v7a"
    ndk_gccdir = ndk_target
  } else if (target_cpu == "mips64el") {
    ndk_target = "mips64el-linux-android"
    ndk_platform = "android-${ndk_api}/arch-mips64"
    ndk_stdlib = "mips64"
    ndk_gccdir = ndk_target
  } else if (target_cpu == "mipsel") {
    ndk_target = "mipsel-linux-android"
    ndk_platform = "android-${ndk_api}/arch-mips"
    ndk_stdlib = "mips"
    ndk_gccdir = ndk_target
  } else if (target_cpu == "x64") {
    ndk_target = "x86_64-linux-android"
    ndk_platform = "android-${ndk_api}/arch-x86_64"
    ndk_stdlib = "x86_64"
    ndk_gccdir = ndk_stdlib
  } else if (target_cpu == "x86") {
    ndk_target = "i686-linux-android"
    ndk_platform = "android-${ndk_api}/arch-x86"
    ndk_stdlib = "x86"
    ndk_gccdir = ndk_stdlib
  }
}

# A component is either a static or a shared library.
template("component") {
  _component_mode = "static_library"
  if (is_component_build) {
    _component_mode = "shared_library"
  }

  target(_component_mode, target_name) {
    forward_variables_from(invoker, "*")
  }
}

# Default configs
default_configs = [
  "//gn:default",
  "//gn:no_rtti",
]
if (!is_debug) {
  default_configs += [ "//gn:release" ]
}
if (!is_official_build) {
  default_configs += [ "//gn:debug_symbols" ]
}

set_defaults("executable") {
  configs = default_configs + [ "//gn:executable" ]
}

set_defaults("source_set") {
  configs = default_configs
}

set_defaults("static_library") {
  configs = default_configs
}

set_defaults("shared_library") {
  configs = default_configs
}

set_defaults("component") {
  configs = default_configs
  if (!is_component_build) {
    complete_static_lib = true
  }
}

if (is_win) {
  # Windows tool chain
  set_default_toolchain("//gn:msvc")
} else {
  # GCC-like toolchains, including Clang.
  set_default_toolchain("//gn:gcc_like")
}