OLD | NEW |
---|---|
1 # Copyright 2016 Google Inc. | 1 # Copyright 2016 Google Inc. |
2 # | 2 # |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 declare_args() { | 6 declare_args() { |
7 ar = "ar" | 7 ar = "ar" |
8 cc = "cc" | 8 cc = "cc" |
9 cxx = "c++" | 9 cxx = "c++" |
10 | 10 |
11 if (is_android) { | 11 if (is_android) { |
12 ar = "$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/$ndk_target/bin/ar" | 12 ar = "$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/$ndk_target/bin/ar" |
13 cc = "$ndk/toolchains/llvm/prebuilt/$ndk_host/bin/clang" | 13 cc = "$ndk/toolchains/llvm/prebuilt/$ndk_host/bin/clang" |
14 cxx = "$ndk/toolchains/llvm/prebuilt/$ndk_host/bin/clang++" | 14 cxx = "$ndk/toolchains/llvm/prebuilt/$ndk_host/bin/clang++" |
15 } | 15 } |
16 | 16 |
17 windk = "" | |
18 | |
17 extra_cflags = "" | 19 extra_cflags = "" |
18 extra_cflags_c = "" | 20 extra_cflags_c = "" |
19 extra_cflags_cc = "" | 21 extra_cflags_cc = "" |
20 extra_ldflags = "" | 22 extra_ldflags = "" |
21 | 23 |
22 compiler_prefix = "" | 24 compiler_prefix = "" |
23 } | 25 } |
24 | 26 |
25 config("no_rtti") { | 27 if (is_win) { |
26 if (sanitize != "ASAN") { # -fsanitize=vptr requires RTTI | 28 config("default") { |
27 cflags_cc = [ "-fno-rtti" ] | 29 cflags = [ |
30 "/FS", # Preserve previous PDB behavior. | |
31 "/bigobj", # Some of our files are bigger than the regular limits. | |
32 ] | |
33 cflags_c = ["/TC"] | |
34 cflags_cc = ["/TP"] | |
35 defines = [ | |
36 "_HAS_EXCEPTIONS=0", | |
37 "WIN32_LEAN_AND_MEAN", | |
hal.canary
2016/09/16 21:04:36
this may not be necessary, since we have SkLeanWin
| |
38 "NOMINMAX", | |
39 ] | |
28 } | 40 } |
29 } | 41 config("no_rtti") { } |
30 | 42 |
31 config("debug_symbols") { | 43 config("debug_symbols") { } |
32 # It's annoying to wait for full debug symbols to push over | |
33 # to Android devices. -gline-tables-only is a lot slimmer. | |
34 if (is_android) { | |
35 cflags = [ "-gline-tables-only" ] | |
36 } else { | |
37 cflags = [ "-g" ] | |
38 } | |
39 } | |
40 | 44 |
41 config("default") { | 45 } else { |
42 asmflags = [] | 46 config("debug_symbols") { |
43 cflags = [ | 47 # It's annoying to wait for full debug symbols to push over |
44 "-O1", | 48 # to Android devices. -gline-tables-only is a lot slimmer. |
45 "-fstrict-aliasing", | 49 if (is_android) { |
46 "-fPIC", | 50 cflags = [ "-gline-tables-only" ] |
47 "-fvisibility=hidden", | 51 } else { |
48 | 52 cflags = [ "-g" ] |
49 "-Werror", | |
50 "-Wall", | |
51 "-Wextra", | |
52 "-Winit-self", | |
53 "-Wpointer-arith", | |
54 "-Wsign-compare", | |
55 "-Wvla", | |
56 | |
57 "-Wno-deprecated-declarations", | |
58 "-Wno-unused-parameter", | |
59 ] | |
60 cflags_cc = [ | |
61 "-std=c++11", | |
62 "-fno-exceptions", | |
63 "-fno-threadsafe-statics", | |
64 "-fvisibility-inlines-hidden", | |
65 | |
66 "-Wnon-virtual-dtor", | |
67 ] | |
68 ldflags = [] | |
69 | |
70 if (current_cpu == "arm") { | |
71 cflags += [ | |
72 "-march=armv7-a", | |
73 "-mfpu=neon", | |
74 "-mthumb", | |
75 ] | |
76 } else if (current_cpu == "mipsel") { | |
77 cflags += [ | |
78 "-march=mips32r2", | |
79 "-mdspr2", | |
80 ] | |
81 } else if (current_cpu == "x86") { | |
82 asmflags += [ "-m32" ] | |
83 cflags += [ | |
84 "-m32", | |
85 "-msse2", | |
86 "-mfpmath=sse", | |
87 ] | |
88 ldflags += [ "-m32" ] | |
89 } | |
90 | |
91 if (is_android) { | |
92 asmflags += [ | |
93 "--target=$ndk_target", | |
94 "-B$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/$ndk_target/bin", | |
95 ] | |
96 cflags += [ | |
97 "--sysroot=$ndk/platforms/$ndk_platform", | |
98 "--target=$ndk_target", | |
99 "-B$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/$ndk_target/bin", | |
100 ] | |
101 cflags_cc += [ | |
102 "-isystem$ndk/sources/android/support/include", | |
103 "-isystem$ndk/sources/cxx-stl/llvm-libc++/libcxx/include", | |
104 ] | |
105 ldflags += [ | |
106 "--sysroot=$ndk/platforms/$ndk_platform", | |
107 "--target=$ndk_target", | |
108 "-B$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/$ndk_target/bin", | |
109 "-pie", | |
110 ] | |
111 lib_dirs = [ | |
112 "$ndk/sources/cxx-stl/llvm-libc++/libs/$ndk_stdlib", | |
113 "$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/lib/gcc/$ndk_target/4. 9.x", | |
114 ] | |
115 libs = [ | |
116 # Order matters here! Keep these three in exactly this order. | |
117 "c++_static", | |
118 "c++abi", | |
119 "android_support", | |
120 ] | |
121 if (target_cpu == "arm") { | |
122 libs += [ "unwind" ] | |
123 } | 53 } |
124 } | 54 } |
125 | 55 |
126 if (is_linux) { | 56 config("no_rtti") { |
127 libs = [ "pthread" ] | 57 if (sanitize != "ASAN") { # -fsanitize=vptr requires RTTI |
58 cflags_cc = [ "-fno-rtti" ] | |
59 } | |
128 } | 60 } |
129 | 61 |
130 if (sanitize != "") { | 62 config("default") { |
131 # You can either pass the sanitizers directly, e.g. "address,undefined", | 63 asmflags = [] |
132 # or pass one of the couple common aliases used by the bots. | 64 cflags = [ |
133 sanitizers = sanitize | 65 "-O1", |
134 if (sanitize == "ASAN") { | 66 "-fstrict-aliasing", |
135 sanitizers = "address,bool,function,integer-divide-by-zero,nonnull-attribu te,null,object-size,return,returns-nonnull-attribute,shift,signed-integer-overfl ow,unreachable,vla-bound,vptr" | 67 "-fPIC", |
136 } else if (sanitize == "TSAN") { | 68 "-fvisibility=hidden", |
137 sanitizers = "thread" | 69 |
138 } else if (sanitize == "MSAN") { | 70 "-Werror", |
139 sanitizers = "memory" | 71 "-Wall", |
72 "-Wextra", | |
73 "-Winit-self", | |
74 "-Wpointer-arith", | |
75 "-Wsign-compare", | |
76 "-Wvla", | |
77 | |
78 "-Wno-deprecated-declarations", | |
79 "-Wno-unused-parameter", | |
80 ] | |
81 cflags_cc = [ | |
82 "-std=c++11", | |
83 "-fno-exceptions", | |
84 "-fno-threadsafe-statics", | |
85 "-fvisibility-inlines-hidden", | |
86 | |
87 "-Wnon-virtual-dtor", | |
88 ] | |
89 ldflags = [] | |
90 | |
91 if (current_cpu == "arm") { | |
92 cflags += [ | |
93 "-march=armv7-a", | |
94 "-mfpu=neon", | |
95 "-mthumb", | |
96 ] | |
97 } else if (current_cpu == "mipsel") { | |
98 cflags += [ | |
99 "-march=mips32r2", | |
100 "-mdspr2", | |
101 ] | |
102 } else if (current_cpu == "x86") { | |
103 asmflags += [ "-m32" ] | |
104 cflags += [ | |
105 "-m32", | |
106 "-msse2", | |
107 "-mfpmath=sse", | |
108 ] | |
109 ldflags += [ "-m32" ] | |
140 } | 110 } |
141 | 111 |
142 cflags += [ | 112 if (is_android) { |
143 "-fsanitize=$sanitizers", | 113 asmflags += [ |
144 "-fno-sanitize-recover=$sanitizers", | 114 "--target=$ndk_target", |
145 "-fsanitize-blacklist=" + rebase_path("../tools/xsan.blacklist"), | 115 "-B$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/$ndk_target/bin", |
146 ] | 116 ] |
147 ldflags += [ "-fsanitize=$sanitizers" ] | 117 cflags += [ |
148 if (sanitizers == "memory") { | 118 "--sysroot=$ndk/platforms/$ndk_platform", |
149 cflags += [ "-fsanitize-memory-track-origins" ] | 119 "--target=$ndk_target", |
150 cflags_cc += [ "-stdlib=libc++" ] | 120 "-B$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/$ndk_target/bin", |
151 ldflags += [ "-stdlib=libc++" ] | 121 ] |
122 cflags_cc += [ | |
123 "-isystem$ndk/sources/android/support/include", | |
124 "-isystem$ndk/sources/cxx-stl/llvm-libc++/libcxx/include", | |
125 ] | |
126 ldflags += [ | |
127 "--sysroot=$ndk/platforms/$ndk_platform", | |
128 "--target=$ndk_target", | |
129 "-B$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/$ndk_target/bin", | |
130 "-pie", | |
131 ] | |
132 lib_dirs = [ | |
133 "$ndk/sources/cxx-stl/llvm-libc++/libs/$ndk_stdlib", | |
134 "$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/lib/gcc/$ndk_target/ 4.9.x", | |
135 ] | |
136 | |
137 libs = [ | |
138 # Order matters here! Keep these three in exactly this order. | |
139 "c++_static", | |
140 "c++abi", | |
141 "android_support", | |
142 ] | |
143 if (target_cpu == "arm") { | |
144 libs += [ "unwind" ] | |
145 } | |
146 } | |
147 | |
148 if (is_linux) { | |
149 libs = [ "pthread" ] | |
150 } | |
151 | |
152 if (sanitize != "") { | |
153 # You can either pass the sanitizers directly, e.g. "address,undefined", | |
154 # or pass one of the couple common aliases used by the bots. | |
155 sanitizers = sanitize | |
156 if (sanitize == "ASAN") { | |
157 sanitizers = "address,bool,function,integer-divide-by-zero,nonnull-attri bute,null,object-size,return,returns-nonnull-attribute,shift,signed-integer-over flow,unreachable,vla-bound,vptr" | |
158 } else if (sanitize == "TSAN") { | |
159 sanitizers = "thread" | |
160 } else if (sanitize == "MSAN") { | |
161 sanitizers = "memory" | |
162 } | |
163 | |
164 cflags += [ | |
165 "-fsanitize=$sanitizers", | |
166 "-fno-sanitize-recover=$sanitizers", | |
167 "-fsanitize-blacklist=" + rebase_path("../tools/xsan.blacklist"), | |
168 ] | |
169 ldflags += [ "-fsanitize=$sanitizers" ] | |
170 if (sanitizers == "memory") { | |
171 cflags += [ "-fsanitize-memory-track-origins" ] | |
172 cflags_cc += [ "-stdlib=libc++" ] | |
173 ldflags += [ "-stdlib=libc++" ] | |
174 } | |
152 } | 175 } |
153 } | 176 } |
154 } | |
155 | 177 |
156 config("release") { | 178 config("release") { |
157 cflags = [ "-O3" ] | 179 cflags = [ "-O3" ] |
158 defines = [ "NDEBUG" ] | 180 defines = [ "NDEBUG" ] |
181 } | |
182 | |
159 } | 183 } |
160 | 184 |
161 config("executable") { | 185 config("executable") { |
162 if (is_mac) { | 186 if (is_mac) { |
163 ldflags = [ "-Wl,-rpath,@loader_path/." ] | 187 ldflags = [ "-Wl,-rpath,@loader_path/." ] |
164 } else if (is_linux) { | 188 } else if (is_linux) { |
165 ldflags = [ | 189 ldflags = [ |
166 "-rdynamic", | 190 "-rdynamic", |
167 "-Wl,-rpath,\$ORIGIN", | 191 "-Wl,-rpath,\$ORIGIN", |
168 ] | 192 ] |
169 } | 193 } |
170 } | 194 } |
171 | 195 |
196 toolchain("msvc") { | |
197 vc = "$windk\VC\bin\amd64\cl.exe" | |
198 vlink = "$windk\VC\bin\amd64\link.exe" | |
199 vlib = "$windk\VC\bin\amd64\lib.exe" | |
200 # TODO: add a python function that generates the includes using <VSPATH>/win_s dk/bin/SetEnv.<cpu>.json | |
201 windk_include_dirs = "/I$windk\win_sdk\bin\..\..\win_sdk\Include\10.0.10586.0\ um /I$windk\win_sdk\bin\..\..\win_sdk\Include\10.0.10586.0\shared /I$windk\win_s dk\bin\..\..\win_sdk\Include\10.0.10586.0\winrt /I$windk\win_sdk\bin\..\..\win_s dk\Include\10.0.10586.0\ucrt /I$windk\win_sdk\bin\..\..\VC\include /I$windk\win_ sdk\bin\..\..\VC\atlmfc\include " | |
202 | |
203 tool("cc") { | |
204 rspfile = "{{output}}.rsp" | |
205 precompiled_header_type = "msvc" | |
206 pdbname = "{{target_out_dir}}/{{label_name}}_c.pdb" | |
207 | |
208 # Label names may have spaces in them so the pdbname must be quoted. The | |
209 # source and output don't need to be quoted because GN knows they're a | |
210 # full file name and will quote automatically when necessary. | |
211 | |
212 command = "$vc /nologo /showIncludes /FC @$rspfile /c {{source}} /Fo{{output }} /Fd\"$pdbname\"" | |
213 depsformat = "msvc" | |
214 description = "CC {{output}}" | |
215 outputs = [ | |
216 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj", | |
217 # "$object_subdir/{{source_name_part}}.obj", | |
218 ] | |
219 rspfile_content = "$windk_include_dirs {{defines}} {{include_dirs}} {{cflags }} {{cflags_c}}" | |
220 } | |
221 | |
222 tool("cxx") { | |
223 rspfile = "{{output}}.rsp" | |
224 precompiled_header_type = "msvc" | |
225 pdbname = "{{target_out_dir}}/{{label_name}}_c.pdb" | |
226 | |
227 # Label names may have spaces in them so the pdbname must be quoted. The | |
228 # source and output don't need to be quoted because GN knows they're a | |
229 # full file name and will quote automatically when necessary. | |
230 command = "$vc /nologo /showIncludes /FC @$rspfile /c {{source}} /Fo{{output }} /Fd\"$pdbname\"" | |
231 depsformat = "msvc" | |
232 description = "C++ {{output}}" | |
233 outputs = [ | |
234 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj", | |
235 ] | |
236 rspfile_content = "$windk_include_dirs {{defines}} {{include_dirs}} {{cflags }} {{cflags_cc}}" | |
237 } | |
238 | |
239 tool("alink") { | |
240 rspfile = "{{output}}.rsp" | |
241 # gyp_win_tool_path = rebase_path("../third_party/externals/gyp/pylib/gyp/wi n_tool.py") | |
242 command = "$vlib /nologo {{arflags}} /OUT:{{output}} @$rspfile" | |
243 description = "LIB {{output}}" | |
244 outputs = [ | |
245 # Ignore {{output_extension}} and always use .lib, there's no reason to | |
246 # allow targets to override this extension on Windows. | |
247 "{{root_out_dir}}/{{target_output_name}}{{output_extension}}", | |
248 ] | |
249 default_output_extension = ".lib" | |
250 default_output_dir = "{{target_out_dir}}" | |
251 | |
252 # The use of inputs_newline is to work around a fixed per-line buffer | |
253 # size in the linker. | |
254 rspfile_content = "{{inputs_newline}}" | |
255 } | |
256 | |
257 tool("link") { | |
258 exename = "{{root_out_dir}}/{{target_output_name}}{{output_extension}}" | |
259 pdbname = "$exename.pdb" | |
260 rspfile = "$exename.rsp" | |
261 | |
262 # gyp_win_tool_path = rebase_path("../third_party/externals/gyp/pylib/gyp/wi n_tool.py") | |
263 command = "$vlink /nologo /OUT:$exename /PDB:$pdbname @$rspfile" | |
264 | |
265 default_output_extension = ".exe" | |
266 default_output_dir = "{{root_out_dir}}" | |
267 description = "LINK {{output}}" | |
268 outputs = [ | |
269 #"{{root_out_dir}}/{{target_output_name}}{{output_extension}}", | |
270 exename, | |
271 ] | |
272 #if (symbol_level != 0) { | |
273 # outputs += [ pdbname ] | |
274 #} | |
275 #runtime_outputs = outputs | |
276 | |
277 # The use of inputs_newline is to work around a fixed per-line buffer | |
278 # size in the linker. | |
279 rspfile_content = "{{inputs_newline}} {{libs}} {{solibs}} {{ldflags}}" | |
280 } | |
281 | |
282 | |
283 tool("stamp") { | |
284 win_stamp_path = rebase_path("win_stamp.py") | |
285 command = "python $win_stamp_path {{output}}" | |
286 } | |
287 } | |
288 | |
289 | |
172 toolchain("gcc_like") { | 290 toolchain("gcc_like") { |
173 lib_switch = "-l" | 291 lib_switch = "-l" |
174 lib_dir_switch = "-L" | 292 lib_dir_switch = "-L" |
175 | 293 |
176 tool("cc") { | 294 tool("cc") { |
177 depfile = "{{output}}.d" | 295 depfile = "{{output}}.d" |
178 command = "$compiler_prefix $cc -MMD -MF $depfile {{defines}} {{include_dirs }} {{cflags}} {{cflags_c}} $extra_cflags $extra_cflags_c -c {{source}} -o {{outp ut}}" | 296 command = "$compiler_prefix $cc -MMD -MF $depfile {{defines}} {{include_dirs }} {{cflags}} {{cflags_c}} $extra_cflags $extra_cflags_c -c {{source}} -o {{outp ut}}" |
179 depsformat = "gcc" | 297 depsformat = "gcc" |
180 outputs = [ | 298 outputs = [ |
181 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o", | 299 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o", |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
242 } | 360 } |
243 | 361 |
244 tool("stamp") { | 362 tool("stamp") { |
245 command = "touch {{output}}" | 363 command = "touch {{output}}" |
246 } | 364 } |
247 | 365 |
248 tool("copy") { | 366 tool("copy") { |
249 command = "ln -f {{source}} {{output}} 2>/dev/null || (rm -rf {{output}} && cp -af {{source}} {{output}})" | 367 command = "ln -f {{source}} {{output}} 2>/dev/null || (rm -rf {{output}} && cp -af {{source}} {{output}})" |
250 } | 368 } |
251 } | 369 } |
OLD | NEW |