5360711eecec1559ddca9136518ccbd5beed649b
[platform/framework/web/crosswalk.git] / src / extensions / generated_extensions_api.gni
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.
4
5 # Defines a static library corresponding to the output of schema compiler tools
6 # over a set of extensions API schemas (IDL or JSON format.) The library target
7 # has implicit hard dependencies on all schema files listed by the invoker and
8 # is itself a hard dependency.
9 #
10 # Invocations of this template may use the following variables:
11 #
12 # sources [required] A list of schema files to be compiled.
13 #
14 # root_namespace [required]
15 #     A Python string substituion pattern used to generate the C++
16 #     namespace for each API. Use %(namespace)s to replace with the API
17 #     namespace, like "toplevel::%(namespace)s_api".
18 #
19 # bundle [optional, default = false]
20 #   Boolean indicating if the schema files should be bundled or not.
21 #
22 # impl_dir [required if bundle = true, otherwise unused]
23 #   The path containing C++ implementations of API functions. This path is
24 #   used as the root path when looking for {schema}/{schema}_api.h headers
25 #   during the API bundle generation phase. Such headers, if found, are
26 #   automatically included by the generated code.
27 #
28 # uncompiled_sources [optional, only used when bundle = true]
29 #   A list of schema files which should not be compiled, but which should still
30 #   be processed for API bundle generation.
31 #
32 # deps [optional]
33 #   If any deps are specified they will be inherited by the static library
34 #   target.
35 #
36 # The static libarary target also inherits the visibility and output_name
37 # of its invoker.
38
39 template("generated_extensions_api") {
40   assert(defined(invoker.sources),
41          "\"sources\" must be defined for the $target_name template.")
42   assert(defined(invoker.root_namespace),
43          "\"root_namespace\" must be defined for the $target_name template.")
44
45   bundle = defined(invoker.bundle) && invoker.bundle
46
47   # Keep a copy of the target_name here since it will be trampled
48   # in nested targets.
49   target_visibility = ":$target_name"
50
51   generated_config_name = target_name + "_generated_config"
52   config(generated_config_name) {
53     include_dirs = [ target_gen_dir ]
54     visibility = target_visibility
55   }
56
57   schemas = invoker.sources
58   root_namespace = invoker.root_namespace
59
60   compiler_root = "//tools/json_schema_compiler"
61   compiler_script = "$compiler_root/compiler.py"
62   compiler_sources = [
63     "$compiler_root/cc_generator.py",
64     "$compiler_root/code.py",
65     "$compiler_root/compiler.py",
66     "$compiler_root/cpp_generator.py",
67     "$compiler_root/cpp_type_generator.py",
68     "$compiler_root/cpp_util.py",
69     "$compiler_root/h_generator.py",
70     "$compiler_root/idl_schema.py",
71     "$compiler_root/model.py",
72     "$compiler_root/util_cc_helper.py",
73   ]
74
75   schema_generator_name = target_name + "_schema_generator"
76   action_foreach(schema_generator_name) {
77     script = compiler_script
78     inputs = compiler_sources
79     sources = schemas
80     outputs = [
81       "$target_gen_dir/{{source_name_part}}.cc",
82       "$target_gen_dir/{{source_name_part}}.h",
83     ]
84     args = [
85       "{{source}}",
86       "--root=" + rebase_path("//", root_build_dir),
87       "--destdir=" + rebase_path(root_gen_dir, root_build_dir),
88       "--namespace=$root_namespace",
89       "--generator=cpp" ]
90     visibility = target_visibility
91   }
92
93   if (bundle) {
94     assert(defined(invoker.impl_dir),
95            "\"impl_dir\" must be defined for the $target_name template.")
96     impl_dir = invoker.impl_dir
97
98     uncompiled_schemas = []
99     if (defined(invoker.uncompiled_sources)) {
100       uncompiled_schemas = invoker.uncompiled_sources
101     }
102
103     bundle_generator_name = target_name + "_bundle_generator"
104     action(bundle_generator_name) {
105       script = compiler_script
106       inputs = compiler_sources + schemas + uncompiled_schemas
107       outputs = [
108         "$target_gen_dir/generated_api.cc",
109         "$target_gen_dir/generated_api.h",
110         "$target_gen_dir/generated_schemas.cc",
111         "$target_gen_dir/generated_schemas.h",
112       ]
113       args = [
114         "--root=" + rebase_path("//", root_build_dir),
115         "--destdir=" + rebase_path(root_gen_dir, root_build_dir),
116         "--namespace=$root_namespace",
117         "--generator=cpp-bundle",
118         "--impl-dir=" + rebase_path(impl_dir, "//"),
119       ] +
120         rebase_path(schemas, root_build_dir) +
121         rebase_path(uncompiled_schemas, root_build_dir)
122     }
123   }
124
125   source_set(target_name) {
126     sources = get_target_outputs(":$schema_generator_name")
127
128     deps = [
129       ":$schema_generator_name",
130       "//tools/json_schema_compiler:generated_api_util",
131     ]
132
133     if (bundle) {
134       sources += get_target_outputs(":$bundle_generator_name")
135       deps += [ ":$bundle_generator_name" ]
136     }
137
138     if (defined(invoker.deps)) {
139       deps += invoker.deps
140     }
141     direct_dependent_configs = [ ":$generated_config_name" ]
142
143     if (defined(invoker.visibility)) {
144       visibility = invoker.visibility
145     }
146     if (defined(invoker.output_name)) {
147       output_name = invoker.output_name
148     }
149   }
150 }