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.
7 import("//build/config/android/config.gni")
10 # Generate a binary Mojo application in a self-named directory.
11 # Application resources are copied to a "resources" directory alongside the app.
12 # The parameters of this template are those of a shared library.
13 template("mojo_native_application") {
14 base_target_name = target_name
15 if (defined(invoker.output_name)) {
16 base_target_name = invoker.output_name
19 final_target_name = target_name
22 if (defined(invoker.deps)) {
23 mojo_deps += invoker.deps
26 if (defined(invoker.resources)) {
27 copy_step_name = "${base_target_name}__copy_resources"
28 copy(copy_step_name) {
29 sources = invoker.resources
31 "${root_out_dir}/${base_target_name}/resources/{{source_file_part}}",
33 if (defined(invoker.testonly)) {
34 testonly = invoker.testonly
38 mojo_deps += [ ":$copy_step_name" ]
42 output = base_target_name + ".mojo"
43 library_target_name = base_target_name + "_library"
46 library_name = "lib${library_target_name}.so"
47 } else if (is_android) {
48 library_name = "lib${library_target_name}${android_product_extension}"
50 library_name = "${library_target_name}.dll"
52 library_name = "lib${library_target_name}.dylib"
54 assert(false, "Platform not supported.")
58 # On android, use the stripped version of the library, because
59 # applications are always fetched over the network.
60 library_dir = "${root_out_dir}/lib.stripped"
62 library_dir = root_out_dir
65 shared_library(library_target_name) {
66 if (defined(invoker.cflags)) {
67 cflags = invoker.cflags
69 if (defined(invoker.cflags_c)) {
70 cflags_c = invoker.cflags_c
72 if (defined(invoker.cflags_cc)) {
73 cflags_cc = invoker.cflags_cc
75 if (defined(invoker.cflags_objc)) {
76 cflags_objc = invoker.cflags_objc
78 if (defined(invoker.cflags_objcc)) {
79 cflags_objcc = invoker.cflags_objcc
81 if (defined(invoker.defines)) {
82 defines = invoker.defines
84 if (defined(invoker.include_dirs)) {
85 include_dirs = invoker.include_dirs
87 if (defined(invoker.ldflags)) {
88 ldflags = invoker.ldflags
90 if (defined(invoker.lib_dirs)) {
91 lib_dirs = invoker.lib_dirs
93 if (defined(invoker.libs)) {
98 if (defined(invoker.data_deps)) {
99 data_deps = invoker.data_deps
102 # Copy any necessary prebuilt artifacts.
103 if (mojo_use_prebuilt_mojo_shell) {
105 [ rebase_path("mojo/public/tools:copy_mojo_shell", ".", mojo_root) ]
107 if (mojo_use_prebuilt_network_service) {
108 data_deps += [ rebase_path("mojo/public/tools:copy_network_service",
114 "mojo/public/c/system",
115 "mojo/public/platform/native:system",
120 if (defined(invoker.forward_dependent_configs_from)) {
121 forward_dependent_configs_from = invoker.forward_dependent_configs_from
123 if (defined(invoker.public_deps)) {
124 public_deps = invoker.public_deps
126 if (defined(invoker.all_dependent_configs)) {
127 all_dependent_configs = invoker.all_dependent_configs
129 if (defined(invoker.public_configs)) {
130 public_configs = invoker.public_configs
132 if (defined(invoker.check_includes)) {
133 check_includes = invoker.check_includes
135 if (defined(invoker.configs)) {
136 configs += invoker.configs
138 if (defined(invoker.data)) {
141 if (defined(invoker.inputs)) {
142 inputs = invoker.inputs
144 if (defined(invoker.public)) {
145 public = invoker.public
147 if (defined(invoker.sources)) {
148 sources = invoker.sources
150 if (defined(invoker.testonly)) {
151 testonly = invoker.testonly
154 visibility = [ ":${final_target_name}" ]
157 copy(final_target_name) {
158 if (defined(invoker.testonly)) {
159 testonly = invoker.testonly
161 if (defined(invoker.visibility)) {
162 visibility = invoker.visibility
165 ":${library_target_name}",
169 "${library_dir}/${library_name}",
172 "${root_out_dir}/${base_target_name}/${output}",
176 nexe_target_name = base_target_name + "_nexe"
177 nexe_name = base_target_name + ".nexe"
179 output = "${base_target_name}_${target_cpu}.nexe.mojo"
181 executable(nexe_target_name) {
182 output_name = base_target_name
184 if (defined(invoker.cflags)) {
185 cflags = invoker.cflags
187 if (defined(invoker.cflags_c)) {
188 cflags_c = invoker.cflags_c
190 if (defined(invoker.cflags_cc)) {
191 cflags_cc = invoker.cflags_cc
193 if (defined(invoker.cflags_objc)) {
194 cflags_objc = invoker.cflags_objc
196 if (defined(invoker.cflags_objcc)) {
197 cflags_objcc = invoker.cflags_objcc
199 if (defined(invoker.defines)) {
200 defines = invoker.defines
202 if (defined(invoker.include_dirs)) {
203 include_dirs = invoker.include_dirs
205 if (defined(invoker.ldflags)) {
206 ldflags = invoker.ldflags
208 if (defined(invoker.lib_dirs)) {
209 lib_dirs = invoker.lib_dirs
211 if (defined(invoker.libs)) {
216 if (defined(invoker.data_deps)) {
217 data_deps = invoker.data_deps
220 # Copy any necessary prebuilt artifacts.
221 if (mojo_use_prebuilt_mojo_shell) {
223 [ rebase_path("mojo/public/tools:copy_mojo_shell", ".", mojo_root) ]
225 if (mojo_use_prebuilt_network_service) {
226 data_deps += [ rebase_path("mojo/public/tools:copy_network_service",
232 "mojo/public/c/system",
233 "mojo/public/platform/nacl:system",
238 if (defined(invoker.forward_dependent_configs_from)) {
239 forward_dependent_configs_from = invoker.forward_dependent_configs_from
241 if (defined(invoker.public_deps)) {
242 public_deps = invoker.public_deps
244 if (defined(invoker.all_dependent_configs)) {
245 all_dependent_configs = invoker.all_dependent_configs
247 if (defined(invoker.public_configs)) {
248 public_configs = invoker.public_configs
250 if (defined(invoker.check_includes)) {
251 check_includes = invoker.check_includes
253 if (defined(invoker.configs)) {
254 configs += invoker.configs
256 if (defined(invoker.data)) {
259 if (defined(invoker.inputs)) {
260 inputs = invoker.inputs
262 if (defined(invoker.public)) {
263 public = invoker.public
265 if (defined(invoker.sources)) {
266 sources = invoker.sources
268 if (defined(invoker.testonly)) {
269 testonly = invoker.testonly
272 visibility = [ ":${final_target_name}" ]
275 action(target_name) {
276 if (defined(invoker.testonly)) {
277 testonly = invoker.testonly
279 if (defined(invoker.visibility)) {
280 visibility = invoker.visibility
283 script = rebase_path("mojo/public/tools/prepend.py", ".", mojo_root)
285 input_path = "${root_out_dir}/${nexe_name}"
290 output_path = "${root_build_dir}/${base_target_name}/${output}"
296 ":${nexe_target_name}",
299 rebase_input = rebase_path(input_path, root_build_dir)
300 rebase_output = rebase_path(output_path, root_build_dir)
302 "--input=$rebase_input",
303 "--output=$rebase_output",
304 "--line=#!mojo mojo:nacl_content_handler",
311 # Declares an Android Mojo application consisting of an .so file and a
312 # corresponding .dex.jar file.
315 # input_so: the .so file to bundle
316 # input_dex_jar: the .dex.jar file to bundle
317 # deps / public_deps / data_deps (optional):
318 # Dependencies. The targets that generate the .so/jar inputs should be
319 # listed in either deps or public_deps.
320 # output_name (optional): override for the output file name
321 template("mojo_android_application") {
322 assert(defined(invoker.input_so))
323 assert(defined(invoker.input_dex_jar))
326 if (defined(invoker.resources)) {
327 base_target_name = target_name
328 if (defined(invoker.output_name)) {
329 base_target_name = invoker.output_name
332 copy_step_name = "${base_target_name}__copy_resources"
333 copy(copy_step_name) {
334 sources = invoker.resources
336 "${root_out_dir}/${base_target_name}/resources/{{source_file_part}}",
338 if (defined(invoker.testonly)) {
339 testonly = invoker.testonly
341 if (defined(invoker.deps)) {
345 mojo_deps += [ ":$copy_step_name" ]
348 zip_action_name = "${target_name}_zip"
349 zip_action_output = "$target_gen_dir/${target_name}.zip"
350 prepend_action_name = target_name
351 action(zip_action_name) {
352 visibility = [ ":$prepend_action_name" ]
353 script = "//build/android/gn/zip.py"
357 invoker.input_dex_jar,
360 output = zip_action_output
365 rebase_inputs = rebase_path(inputs, root_build_dir)
366 rebase_output = rebase_path(output, root_build_dir)
368 "--inputs=$rebase_inputs",
369 "--output=$rebase_output",
372 if (defined(invoker.deps)) {
375 if (defined(invoker.public_deps)) {
376 public_deps = invoker.public_deps
378 if (defined(invoker.data_deps)) {
379 data_deps = invoker.data_deps
383 action(target_name) {
384 script = rebase_path("mojo/public/tools/prepend.py", ".", mojo_root)
386 base_target_name = target_name
387 if (defined(invoker.output_name)) {
388 base_target_name = invoker.output_name
391 input = zip_action_output
396 output = "${root_out_dir}/${base_target_name}/${base_target_name}.mojo"
401 rebase_input = rebase_path(input, root_build_dir)
402 rebase_output = rebase_path(output, root_build_dir)
404 "--input=$rebase_input",
405 "--output=$rebase_output",
406 "--line=#!mojo mojo:android_handler",