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/module_args/mojo.gni")
9 # Generate a binary mojo application.The parameters of this template are those
10 # of a shared library.
11 template("mojo_native_application") {
12 if (defined(invoker.output_name)) {
13 base_target_name = invoker.output_name
15 base_target_name = target_name
18 final_target_name = target_name
21 output = base_target_name + ".mojo"
22 library_target_name = base_target_name + "_library"
24 if (is_linux || is_android) {
25 library_name = "lib${library_target_name}.so"
27 library_name = "${library_target_name}.dll"
29 library_name = "lib${library_target_name}.dylib"
31 assert(false, "Platform not supported.")
35 # On android, use the stripped version of the library, because applications
36 # are always fetched over the network.
37 library_dir = "${root_out_dir}/lib.stripped"
39 library_dir = root_out_dir
42 shared_library(library_target_name) {
43 if (defined(invoker.cflags)) {
44 cflags = invoker.cflags
46 if (defined(invoker.cflags_c)) {
47 cflags_c = invoker.cflags_c
49 if (defined(invoker.cflags_cc)) {
50 cflags_cc = invoker.cflags_cc
52 if (defined(invoker.cflags_objc)) {
53 cflags_objc = invoker.cflags_objc
55 if (defined(invoker.cflags_objcc)) {
56 cflags_objcc = invoker.cflags_objcc
58 if (defined(invoker.defines)) {
59 defines = invoker.defines
61 if (defined(invoker.include_dirs)) {
62 include_dirs = invoker.include_dirs
64 if (defined(invoker.ldflags)) {
65 ldflags = invoker.ldflags
67 if (defined(invoker.lib_dirs)) {
68 lib_dirs = invoker.lib_dirs
70 if (defined(invoker.libs)) {
75 if (defined(invoker.data_deps)) {
76 data_deps = invoker.data_deps
79 # Copy any necessary prebuilt artifacts.
80 if (mojo_use_prebuilt_mojo_shell) {
82 [ rebase_path("mojo/public/tools:copy_mojo_shell", ".", mojo_root) ]
84 if (mojo_use_prebuilt_network_service) {
85 data_deps += [ rebase_path("mojo/public/tools:copy_network_service",
91 "mojo/public/c/system",
92 "mojo/public/platform/native:system",
96 if (defined(invoker.deps)) {
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 "${library_dir}/${library_name}",
151 "${root_out_dir}/${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",
216 if (defined(invoker.deps)) {
219 if (defined(invoker.forward_dependent_configs_from)) {
220 forward_dependent_configs_from = invoker.forward_dependent_configs_from
222 if (defined(invoker.public_deps)) {
223 public_deps = invoker.public_deps
225 if (defined(invoker.all_dependent_configs)) {
226 all_dependent_configs = invoker.all_dependent_configs
228 if (defined(invoker.public_configs)) {
229 public_configs = invoker.public_configs
231 if (defined(invoker.check_includes)) {
232 check_includes = invoker.check_includes
234 if (defined(invoker.configs)) {
235 configs += invoker.configs
237 if (defined(invoker.data)) {
240 if (defined(invoker.inputs)) {
241 inputs = invoker.inputs
243 if (defined(invoker.public)) {
244 public = invoker.public
246 if (defined(invoker.sources)) {
247 sources = invoker.sources
249 if (defined(invoker.testonly)) {
250 testonly = invoker.testonly
253 visibility = [ ":${final_target_name}" ]
256 action(target_name) {
257 if (defined(invoker.testonly)) {
258 testonly = invoker.testonly
260 if (defined(invoker.visibility)) {
261 visibility = invoker.visibility
264 script = rebase_path("mojo/public/tools/prepend.py", ".", mojo_root)
266 input_path = "${root_out_dir}/${nexe_name}"
271 output_path = "${root_build_dir}/${output}"
277 ":${nexe_target_name}",
280 rebase_input = rebase_path(input_path, root_build_dir)
281 rebase_output = rebase_path(output_path, root_build_dir)
283 "--input=$rebase_input",
284 "--output=$rebase_output",
285 "--line=#!mojo mojo:nacl_content_handler",
292 # Declares an Android Mojo application consisting of an .so file and a
293 # corresponding .dex.jar file.
296 # input_so: the .so file to bundle
297 # input_dex_jar: the .dex.jar file to bundle
298 # output_name (optional): override for the output file name
299 template("mojo_android_application") {
300 assert(defined(invoker.input_so))
301 assert(defined(invoker.input_dex_jar))
303 zip_action_name = "${target_name}_zip"
304 zip_action_output = "$target_gen_dir/${target_name}.zip"
305 action(zip_action_name) {
306 script = "//build/android/gn/zip.py"
310 invoker.input_dex_jar,
313 output = zip_action_output
318 rebase_inputs = rebase_path(inputs, root_build_dir)
319 rebase_output = rebase_path(output, root_build_dir)
321 "--inputs=$rebase_inputs",
322 "--output=$rebase_output",
326 if (defined(invoker.output_name)) {
327 mojo_output = "$root_out_dir/" + invoker.output_name + ".mojo"
329 mojo_output = "$root_out_dir/" + target_name + ".mojo"
332 action(target_name) {
333 script = rebase_path("mojo/public/tools/prepend.py", ".", mojo_root)
335 input = zip_action_output
345 rebase_input = rebase_path(input, root_build_dir)
346 rebase_output = rebase_path(output, root_build_dir)
348 "--input=$rebase_input",
349 "--output=$rebase_output",
350 "--line=#!mojo mojo:android_handler",