-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBUILDCONFIG.gn
164 lines (138 loc) · 4.06 KB
/
BUILDCONFIG.gn
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
157
158
159
160
161
162
163
164
# =============================================================================
# PLATFORM SELECTION
# =============================================================================
if (target_os == "") {
target_os = host_os
}
if (target_cpu == "") {
if (target_os == "android") {
# If we're building for Android, we should assume that we want to
# build for ARM by default, not the host_cpu (which is likely x64).
# This allows us to not have to specify both target_os and target_cpu
# on the command line.
target_cpu = "arm"
} else {
target_cpu = host_cpu
}
}
if (current_cpu == "") {
current_cpu = target_cpu
}
if (current_os == "") {
current_os = target_os
}
# =============================================================================
# OS DEFINITIONS
# =============================================================================
is_android = current_os == "android"
is_chromeos = current_os == "chromeos"
is_fuchsia = current_os == "fuchsia"
is_ios = current_os == "ios"
is_linux = current_os == "linux"
is_mac = current_os == "mac"
is_nacl = current_os == "nacl"
is_win = current_os == "win" || current_os == "winuwp"
is_apple = is_ios || is_mac
is_posix = !is_win && !is_fuchsia
# =============================================================================
# BUILD FLAGS
# =============================================================================
declare_args() {
# Debug build
is_debug = false
}
declare_args() {
if (is_posix) {
c_std = "gnu17"
cc_std = "gnu++17"
} else {
c_std = "c17"
cc_std = "c++17"
}
}
declare_args() {
is_winxp = false # targeting to Windows XP
static_link_crt = is_win # static or dynamic link crt
winver = "" # to define WINVER, _WIN32_WINNT and NTDDI_VERSION
}
if (is_win) {
winver = "0x0A00"
if (is_winxp) {
winver = "0x0501"
}
}
# ==============================================================================
# TOOLCHAIN SETUP
# ==============================================================================
if (is_linux) {
set_default_toolchain("//build/toolchain/linux:gcc")
} else if (is_mac) {
set_default_toolchain("//build/toolchain/mac:clang")
} else if (is_win) {
# set environment variables for msvc build tools
import("config/win/setup_environment.gni")
set_default_toolchain("//build/toolchain/win:msvc")
} else {
assert(false, "Unsupported target_os: $target_os")
}
# =============================================================================
# TARGET DEFAULTS
# =============================================================================
_compile_defaults = [
"//build/config:default",
"//build/config:c_std",
"//build/config:cc_std",
]
if (is_posix) {
_compile_defaults += [
"//build/config/posix:default",
"//build/config/posix:optmize",
"//build/config/posix:target_arch",
]
}
if (is_win) {
_compile_defaults += [
"//build/config/win:default",
"//build/config/win:optmize",
"//build/config/win:crt_link",
"//build/config/win:core_libraries",
"//build/config/win:win_macros",
"//build/config/win:target_arch",
]
}
set_defaults("executable") {
configs = _compile_defaults
if (is_posix) {
configs += [ "//build/config/posix:rpath" ]
}
}
set_defaults("static_library") {
configs = _compile_defaults
}
set_defaults("shared_library") {
configs = _compile_defaults
}
set_defaults("source_set") {
configs = _compile_defaults
}
# =============================================================================
# IMPORTS
# =============================================================================
# help to build mac app bundle
if (is_mac) {
import("config/mac/app_bundle.gni")
}
# help to specify subsystem explicitly to build win32 application or console application
if (is_win) {
import("config/win/application.gni")
}
# help to build nested gn projects
import("tools/gn.gni")
# help to build makefile projects
import("tools/makefile.gni")
# help to build cmake projects
import("tools/cmake.gni")
# help to build boost
import("tools/boost.gni")
# help to build golang projects
import("tools/golang.gni")