1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
5 import("//build/toolchain/toolchain.gni")
8 # Generate a binary Mojo application in a self-named directory.
9 # Application resources are copied to a "resources" directory alongside the app.
10 # The parameters of this template are those of a shared library.
11 template("mojo_native_application") {
12 base_target_name = target_name
13 if (defined(invoker.output_name)) {
14 base_target_name = invoker.output_name
17 final_target_name = target_name
20 if (defined(invoker.deps)) {
21 mojo_deps += invoker.deps
24 if (defined(invoker.resources)) {
25 copy_step_name = "${base_target_name}__copy_resources"
26 copy(copy_step_name) {
27 sources = invoker.resources
29 "${root_out_dir}/${base_target_name}/resources/{{source_file_part}}",
31 if (defined(invoker.testonly)) {
32 testonly = invoker.testonly
36 mojo_deps += [ ":$copy_step_name" ]
40 output = base_target_name + ".mojo"
41 library_target_name = base_target_name + "_library"
42 library_name = "${shlib_prefix}${library_target_name}${shlib_extension}"
44 shared_library(library_target_name) {
45 if (defined(invoker.cflags)) {
46 cflags = invoker.cflags
48 if (defined(invoker.cflags_c)) {
49 cflags_c = invoker.cflags_c
51 if (defined(invoker.cflags_cc)) {
52 cflags_cc = invoker.cflags_cc
54 if (defined(invoker.cflags_objc)) {
55 cflags_objc = invoker.cflags_objc
57 if (defined(invoker.cflags_objcc)) {
58 cflags_objcc = invoker.cflags_objcc
60 if (defined(invoker.defines)) {
61 defines = invoker.defines
63 if (defined(invoker.include_dirs)) {
64 include_dirs = invoker.include_dirs
66 if (defined(invoker.ldflags)) {
67 ldflags = invoker.ldflags
69 if (defined(invoker.lib_dirs)) {
70 lib_dirs = invoker.lib_dirs
72 if (defined(invoker.libs)) {
77 if (defined(invoker.data_deps)) {
78 data_deps = invoker.data_deps
81 # Copy any necessary prebuilt artifacts.
82 if (mojo_use_prebuilt_mojo_shell) {
84 [ rebase_path("mojo/public/tools:copy_mojo_shell", ".", mojo_root) ]
86 if (mojo_use_prebuilt_network_service) {
87 data_deps += [ rebase_path("mojo/public/tools:copy_network_service",
93 "mojo/public/c/system",
94 "mojo/public/platform/native:system",
99 if (defined(invoker.forward_dependent_configs_from)) {
100 forward_dependent_configs_from = invoker.forward_dependent_configs_from
102 if (defined(invoker.public_deps)) {
103 public_deps = invoker.public_deps
105 if (defined(invoker.all_dependent_configs)) {
106 all_dependent_configs = invoker.all_dependent_configs
108 if (defined(invoker.public_configs)) {
109 public_configs = invoker.public_configs
111 if (defined(invoker.check_includes)) {
112 check_includes = invoker.check_includes
114 if (defined(invoker.configs)) {
115 configs += invoker.configs
117 if (defined(invoker.data)) {
120 if (defined(invoker.inputs)) {
121 inputs = invoker.inputs
123 if (defined(invoker.public)) {
124 public = invoker.public
126 if (defined(invoker.sources)) {
127 sources = invoker.sources
129 if (defined(invoker.testonly)) {
130 testonly = invoker.testonly
133 visibility = [ ":${final_target_name}" ]
136 copy(final_target_name) {
137 if (defined(invoker.testonly)) {
138 testonly = invoker.testonly
140 if (defined(invoker.visibility)) {
141 visibility = invoker.visibility
144 ":${library_target_name}",
148 "${root_shlib_dir}/${library_name}",
151 "${root_out_dir}/${base_target_name}/${output}",
155 nexe_target_name = base_target_name + "_nexe"
156 nexe_name = base_target_name + ".nexe"
158 output = "${base_target_name}_${target_cpu}.nexe.mojo"
160 executable(nexe_target_name) {
161 output_name = base_target_name
163 if (defined(invoker.cflags)) {
164 cflags = invoker.cflags
166 if (defined(invoker.cflags_c)) {
167 cflags_c = invoker.cflags_c
169 if (defined(invoker.cflags_cc)) {
170 cflags_cc = invoker.cflags_cc
172 if (defined(invoker.cflags_objc)) {
173 cflags_objc = invoker.cflags_objc
175 if (defined(invoker.cflags_objcc)) {
176 cflags_objcc = invoker.cflags_objcc
178 if (defined(invoker.defines)) {
179 defines = invoker.defines
181 if (defined(invoker.include_dirs)) {
182 include_dirs = invoker.include_dirs
184 if (defined(invoker.ldflags)) {
185 ldflags = invoker.ldflags
187 if (defined(invoker.lib_dirs)) {
188 lib_dirs = invoker.lib_dirs
190 if (defined(invoker.libs)) {
195 if (defined(invoker.data_deps)) {
196 data_deps = invoker.data_deps
199 # Copy any necessary prebuilt artifacts.
200 if (mojo_use_prebuilt_mojo_shell) {
202 [ rebase_path("mojo/public/tools:copy_mojo_shell", ".", mojo_root) ]
204 if (mojo_use_prebuilt_network_service) {
205 data_deps += [ rebase_path("mojo/public/tools:copy_network_service",
211 "mojo/public/c/system",
212 "mojo/public/platform/nacl:system",
217 if (defined(invoker.forward_dependent_configs_from)) {
218 forward_dependent_configs_from = invoker.forward_dependent_configs_from
220 if (defined(invoker.public_deps)) {
221 public_deps = invoker.public_deps
223 if (defined(invoker.all_dependent_configs)) {
224 all_dependent_configs = invoker.all_dependent_configs
226 if (defined(invoker.public_configs)) {
227 public_configs = invoker.public_configs
229 if (defined(invoker.check_includes)) {
230 check_includes = invoker.check_includes
232 if (defined(invoker.configs)) {
233 configs += invoker.configs
235 if (defined(invoker.data)) {
238 if (defined(invoker.inputs)) {
239 inputs = invoker.inputs
241 if (defined(invoker.public)) {
242 public = invoker.public
244 if (defined(invoker.sources)) {
245 sources = invoker.sources
247 if (defined(invoker.testonly)) {
248 testonly = invoker.testonly
251 visibility = [ ":${final_target_name}" ]
254 action(target_name) {
255 if (defined(invoker.testonly)) {
256 testonly = invoker.testonly
258 if (defined(invoker.visibility)) {
259 visibility = invoker.visibility
262 script = rebase_path("mojo/public/tools/prepend.py", ".", mojo_root)
264 input_path = "${root_out_dir}/${nexe_name}"
269 output_path = "${root_build_dir}/${base_target_name}/${output}"
275 ":${nexe_target_name}",
278 rebase_input = rebase_path(input_path, root_build_dir)
279 rebase_output = rebase_path(output_path, root_build_dir)
281 "--input=$rebase_input",
282 "--output=$rebase_output",
283 "--line=#!mojo mojo:nacl_content_handler",
290 # Declares an Android Mojo application consisting of an .so file and a
291 # corresponding .dex.jar file.
294 # input_so: the .so file to bundle
295 # input_dex_jar: the .dex.jar file to bundle
296 # deps / public_deps / data_deps (optional):
297 # Dependencies. The targets that generate the .so/jar inputs should be
298 # listed in either deps or public_deps.
299 # output_name (optional): override for the output file name
300 template("mojo_android_application") {
301 assert(defined(invoker.input_so))
302 assert(defined(invoker.input_dex_jar))
305 if (defined(invoker.resources)) {
306 base_target_name = target_name
307 if (defined(invoker.output_name)) {
308 base_target_name = invoker.output_name
311 copy_step_name = "${base_target_name}__copy_resources"
312 copy(copy_step_name) {
313 sources = invoker.resources
315 "${root_out_dir}/${base_target_name}/resources/{{source_file_part}}",
317 if (defined(invoker.testonly)) {
318 testonly = invoker.testonly
320 if (defined(invoker.deps)) {
324 mojo_deps += [ ":$copy_step_name" ]
327 zip_action_name = "${target_name}_zip"
328 zip_action_output = "$target_gen_dir/${target_name}.zip"
329 prepend_action_name = target_name
330 action(zip_action_name) {
331 visibility = [ ":$prepend_action_name" ]
332 script = "//build/android/gn/zip.py"
336 invoker.input_dex_jar,
339 output = zip_action_output
344 rebase_inputs = rebase_path(inputs, root_build_dir)
345 rebase_output = rebase_path(output, root_build_dir)
347 "--inputs=$rebase_inputs",
348 "--output=$rebase_output",
351 if (defined(invoker.deps)) {
354 if (defined(invoker.public_deps)) {
355 public_deps = invoker.public_deps
357 if (defined(invoker.data_deps)) {
358 data_deps = invoker.data_deps
362 action(target_name) {
363 script = rebase_path("mojo/public/tools/prepend.py", ".", mojo_root)
365 base_target_name = target_name
366 if (defined(invoker.output_name)) {
367 base_target_name = invoker.output_name
370 input = zip_action_output
375 output = "${root_out_dir}/${base_target_name}/${base_target_name}.mojo"
380 rebase_input = rebase_path(input, root_build_dir)
381 rebase_output = rebase_path(output, root_build_dir)
383 "--input=$rebase_input",
384 "--output=$rebase_output",
385 "--line=#!mojo mojo:android_handler",