• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2021 Huawei Device Co., Ltd.
2# Licensed under the Apache License, Version 2.0 (the "License");
3# you may not use this file except in compliance with the License.
4# You may obtain a copy of the License at
5#
6#     http://www.apache.org/licenses/LICENSE-2.0
7#
8# Unless required by applicable law or agreed to in writing, software
9# distributed under the License is distributed on an "AS IS" BASIS,
10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11# See the License for the specific language governing permissions and
12# limitations under the License.
13
14import("//build/ohos.gni")
15
16config("protobuf_config") {
17  include_dirs = [ "src" ]
18}
19protobuf_dir = "src/google/protobuf"
20protobuf_lite_src = [
21  "$protobuf_dir/any_lite.cc",
22  "$protobuf_dir/arena.cc",
23  "$protobuf_dir/extension_set.cc",
24  "$protobuf_dir/generated_enum_util.cc",
25  "$protobuf_dir/generated_message_table_driven_lite.cc",
26  "$protobuf_dir/generated_message_util.cc",
27  "$protobuf_dir/implicit_weak_message.cc",
28  "$protobuf_dir/io/coded_stream.cc",
29  "$protobuf_dir/io/io_win32.cc",
30  "$protobuf_dir/io/strtod.cc",
31  "$protobuf_dir/io/zero_copy_stream.cc",
32  "$protobuf_dir/io/zero_copy_stream_impl.cc",
33  "$protobuf_dir/io/zero_copy_stream_impl_lite.cc",
34  "$protobuf_dir/message_lite.cc",
35  "$protobuf_dir/parse_context.cc",
36  "$protobuf_dir/repeated_field.cc",
37  "$protobuf_dir/stubs/bytestream.cc",
38  "$protobuf_dir/stubs/common.cc",
39  "$protobuf_dir/stubs/int128.cc",
40  "$protobuf_dir/stubs/status.cc",
41  "$protobuf_dir/stubs/statusor.cc",
42  "$protobuf_dir/stubs/stringpiece.cc",
43  "$protobuf_dir/stubs/stringprintf.cc",
44  "$protobuf_dir/stubs/structurally_valid.cc",
45  "$protobuf_dir/stubs/strutil.cc",
46  "$protobuf_dir/stubs/time.cc",
47  "$protobuf_dir/wire_format_lite.cc",
48]
49
50protobuf_src = [
51  "$protobuf_dir/any.cc",
52  "$protobuf_dir/any.pb.cc",
53  "$protobuf_dir/api.pb.cc",
54  "$protobuf_dir/compiler/importer.cc",
55  "$protobuf_dir/compiler/parser.cc",
56  "$protobuf_dir/descriptor.cc",
57  "$protobuf_dir/descriptor.pb.cc",
58  "$protobuf_dir/descriptor_database.cc",
59  "$protobuf_dir/duration.pb.cc",
60  "$protobuf_dir/dynamic_message.cc",
61  "$protobuf_dir/empty.pb.cc",
62  "$protobuf_dir/extension_set_heavy.cc",
63  "$protobuf_dir/field_mask.pb.cc",
64  "$protobuf_dir/generated_message_reflection.cc",
65  "$protobuf_dir/generated_message_table_driven.cc",
66  "$protobuf_dir/io/gzip_stream.cc",
67  "$protobuf_dir/io/printer.cc",
68  "$protobuf_dir/io/tokenizer.cc",
69  "$protobuf_dir/map_field.cc",
70  "$protobuf_dir/message.cc",
71  "$protobuf_dir/reflection_ops.cc",
72  "$protobuf_dir/service.cc",
73  "$protobuf_dir/source_context.pb.cc",
74  "$protobuf_dir/struct.pb.cc",
75  "$protobuf_dir/stubs/substitute.cc",
76  "$protobuf_dir/text_format.cc",
77  "$protobuf_dir/timestamp.pb.cc",
78  "$protobuf_dir/type.pb.cc",
79  "$protobuf_dir/unknown_field_set.cc",
80  "$protobuf_dir/util/delimited_message_util.cc",
81  "$protobuf_dir/util/field_comparator.cc",
82  "$protobuf_dir/util/field_mask_util.cc",
83  "$protobuf_dir/util/internal/datapiece.cc",
84  "$protobuf_dir/util/internal/default_value_objectwriter.cc",
85  "$protobuf_dir/util/internal/error_listener.cc",
86  "$protobuf_dir/util/internal/field_mask_utility.cc",
87  "$protobuf_dir/util/internal/json_escaping.cc",
88  "$protobuf_dir/util/internal/json_objectwriter.cc",
89  "$protobuf_dir/util/internal/json_stream_parser.cc",
90  "$protobuf_dir/util/internal/object_writer.cc",
91  "$protobuf_dir/util/internal/proto_writer.cc",
92  "$protobuf_dir/util/internal/protostream_objectsource.cc",
93  "$protobuf_dir/util/internal/protostream_objectwriter.cc",
94  "$protobuf_dir/util/internal/type_info.cc",
95  "$protobuf_dir/util/internal/type_info_test_helper.cc",
96  "$protobuf_dir/util/internal/utility.cc",
97  "$protobuf_dir/util/json_util.cc",
98  "$protobuf_dir/util/message_differencer.cc",
99  "$protobuf_dir/util/time_util.cc",
100  "$protobuf_dir/util/type_resolver_util.cc",
101  "$protobuf_dir/wire_format.cc",
102  "$protobuf_dir/wrappers.pb.cc",
103]
104if (use_wasm) {
105  source_set("protobuf_lite_static") {
106    sources = protobuf_lite_src
107    include_dirs = [
108      "$protobuf_dir/**/*.h",
109      "$protobuf_dir/**/*.inc",
110      "src",
111    ]
112
113    cflags_cc = [ "-Wno-sign-compare" ]
114    cflags = [
115      "-Wno-sign-compare",
116      "-D HAVE_PTHREAD",
117      "-std=c++17",
118    ]
119    if (wasm_use_thread) {
120      cflags += [
121        "-mbulk-memory",
122        "-matomics",
123      ]
124    }
125    public_configs = [ ":protobuf_config" ]
126  }
127} else {
128  source_set("protobuf_lite_static") {
129    sources = protobuf_lite_src
130    include_dirs = [
131      "$protobuf_dir/**/*.h",
132      "$protobuf_dir/**/*.inc",
133      "src",
134    ]
135
136    cflags_cc = [ "-Wno-sign-compare" ]
137    cflags = [
138      "-Wno-sign-compare",
139      "-D HAVE_PTHREAD",
140      "-std=c++17",
141    ]
142    public_configs = [ ":protobuf_config" ]
143  }
144}
145if (use_wasm) {
146  source_set("protobuf_static") {
147    sources = protobuf_src
148    include_dirs = [
149      "$protobuf_dir/**/*.h",
150      "$protobuf_dir/**/*.inc",
151      "src",
152    ]
153    cflags_cc = [ "-Wno-sign-compare" ]
154    cflags = [
155      "-Wno-sign-compare",
156      "-D HAVE_PTHREAD",
157      "-std=c++17",
158    ]
159    if (wasm_use_thread) {
160      cflags += [
161        "-mbulk-memory",
162        "-matomics",
163      ]
164    }
165
166    deps = [ ":protobuf_lite_static" ]
167    public_configs = [ ":protobuf_config" ]
168  }
169} else {
170  source_set("protobuf_static") {
171    sources = protobuf_src
172    include_dirs = [
173      "$protobuf_dir/**/*.h",
174      "$protobuf_dir/**/*.inc",
175      "src",
176    ]
177
178    cflags = [
179      "-Wno-sign-compare",
180      "-D HAVE_PTHREAD",
181      "-ftrapv",
182      "-fstack-protector-strong",
183      "-fstack-protector-all",
184      "-D_FORTIFY_SOURCE=2 -O2",
185      "-std=c++17",
186    ]
187
188    ldflags = [ "-fstack-protector" ]
189    if (!is_mac) {
190      ldflags += [
191        "-fuse-ld=gold",
192        "-Wl,--gc-sections",
193        "-Wl,-O1",
194        "-fpie",
195        "-pie",
196      ]
197    }
198
199    if (!is_win) {
200      cflags += [
201        "-fPIE",
202        "-fPIC",
203      ]
204    }
205
206    deps = [ ":protobuf_lite_static" ]
207
208    public_configs = [ ":protobuf_config" ]
209  }
210  source_set("protoc_lib") {
211    sources = [
212      "$protobuf_dir/compiler/code_generator.cc",
213      "$protobuf_dir/compiler/command_line_interface.cc",
214      "$protobuf_dir/compiler/cpp/cpp_enum.cc",
215      "$protobuf_dir/compiler/cpp/cpp_enum_field.cc",
216      "$protobuf_dir/compiler/cpp/cpp_extension.cc",
217      "$protobuf_dir/compiler/cpp/cpp_field.cc",
218      "$protobuf_dir/compiler/cpp/cpp_file.cc",
219      "$protobuf_dir/compiler/cpp/cpp_generator.cc",
220      "$protobuf_dir/compiler/cpp/cpp_helpers.cc",
221      "$protobuf_dir/compiler/cpp/cpp_map_field.cc",
222      "$protobuf_dir/compiler/cpp/cpp_message.cc",
223      "$protobuf_dir/compiler/cpp/cpp_message_field.cc",
224      "$protobuf_dir/compiler/cpp/cpp_padding_optimizer.cc",
225      "$protobuf_dir/compiler/cpp/cpp_primitive_field.cc",
226      "$protobuf_dir/compiler/cpp/cpp_service.cc",
227      "$protobuf_dir/compiler/cpp/cpp_string_field.cc",
228      "$protobuf_dir/compiler/csharp/csharp_doc_comment.cc",
229      "$protobuf_dir/compiler/csharp/csharp_enum.cc",
230      "$protobuf_dir/compiler/csharp/csharp_enum_field.cc",
231      "$protobuf_dir/compiler/csharp/csharp_field_base.cc",
232      "$protobuf_dir/compiler/csharp/csharp_generator.cc",
233      "$protobuf_dir/compiler/csharp/csharp_helpers.cc",
234      "$protobuf_dir/compiler/csharp/csharp_map_field.cc",
235      "$protobuf_dir/compiler/csharp/csharp_message.cc",
236      "$protobuf_dir/compiler/csharp/csharp_message_field.cc",
237      "$protobuf_dir/compiler/csharp/csharp_primitive_field.cc",
238      "$protobuf_dir/compiler/csharp/csharp_reflection_class.cc",
239      "$protobuf_dir/compiler/csharp/csharp_repeated_enum_field.cc",
240      "$protobuf_dir/compiler/csharp/csharp_repeated_message_field.cc",
241      "$protobuf_dir/compiler/csharp/csharp_repeated_primitive_field.cc",
242      "$protobuf_dir/compiler/csharp/csharp_source_generator_base.cc",
243      "$protobuf_dir/compiler/csharp/csharp_wrapper_field.cc",
244      "$protobuf_dir/compiler/java/java_context.cc",
245      "$protobuf_dir/compiler/java/java_doc_comment.cc",
246      "$protobuf_dir/compiler/java/java_enum.cc",
247      "$protobuf_dir/compiler/java/java_enum_field.cc",
248      "$protobuf_dir/compiler/java/java_enum_field_lite.cc",
249      "$protobuf_dir/compiler/java/java_enum_lite.cc",
250      "$protobuf_dir/compiler/java/java_extension.cc",
251      "$protobuf_dir/compiler/java/java_extension_lite.cc",
252      "$protobuf_dir/compiler/java/java_field.cc",
253      "$protobuf_dir/compiler/java/java_file.cc",
254      "$protobuf_dir/compiler/java/java_generator.cc",
255      "$protobuf_dir/compiler/java/java_generator_factory.cc",
256      "$protobuf_dir/compiler/java/java_helpers.cc",
257      "$protobuf_dir/compiler/java/java_map_field.cc",
258      "$protobuf_dir/compiler/java/java_map_field_lite.cc",
259      "$protobuf_dir/compiler/java/java_message.cc",
260      "$protobuf_dir/compiler/java/java_message_builder.cc",
261      "$protobuf_dir/compiler/java/java_message_builder_lite.cc",
262      "$protobuf_dir/compiler/java/java_message_field.cc",
263      "$protobuf_dir/compiler/java/java_message_field_lite.cc",
264      "$protobuf_dir/compiler/java/java_message_lite.cc",
265      "$protobuf_dir/compiler/java/java_name_resolver.cc",
266      "$protobuf_dir/compiler/java/java_primitive_field.cc",
267      "$protobuf_dir/compiler/java/java_primitive_field_lite.cc",
268      "$protobuf_dir/compiler/java/java_service.cc",
269      "$protobuf_dir/compiler/java/java_shared_code_generator.cc",
270      "$protobuf_dir/compiler/java/java_string_field.cc",
271      "$protobuf_dir/compiler/java/java_string_field_lite.cc",
272      "$protobuf_dir/compiler/js/js_generator.cc",
273      "$protobuf_dir/compiler/js/well_known_types_embed.cc",
274      "$protobuf_dir/compiler/objectivec/objectivec_enum.cc",
275      "$protobuf_dir/compiler/objectivec/objectivec_enum_field.cc",
276      "$protobuf_dir/compiler/objectivec/objectivec_extension.cc",
277      "$protobuf_dir/compiler/objectivec/objectivec_field.cc",
278      "$protobuf_dir/compiler/objectivec/objectivec_file.cc",
279      "$protobuf_dir/compiler/objectivec/objectivec_generator.cc",
280      "$protobuf_dir/compiler/objectivec/objectivec_helpers.cc",
281      "$protobuf_dir/compiler/objectivec/objectivec_map_field.cc",
282      "$protobuf_dir/compiler/objectivec/objectivec_message.cc",
283      "$protobuf_dir/compiler/objectivec/objectivec_message_field.cc",
284      "$protobuf_dir/compiler/objectivec/objectivec_oneof.cc",
285      "$protobuf_dir/compiler/objectivec/objectivec_primitive_field.cc",
286      "$protobuf_dir/compiler/php/php_generator.cc",
287      "$protobuf_dir/compiler/plugin.cc",
288      "$protobuf_dir/compiler/plugin.pb.cc",
289      "$protobuf_dir/compiler/python/python_generator.cc",
290      "$protobuf_dir/compiler/ruby/ruby_generator.cc",
291      "$protobuf_dir/compiler/subprocess.cc",
292      "$protobuf_dir/compiler/zip_writer.cc",
293    ]
294    include_dirs = [
295      "$protobuf_dir/**/*.h",
296      "$protobuf_dir/**/*.inc",
297      "src",
298    ]
299    if (!use_wasm) {
300      configs = default_configs
301    }
302    cflags_cc = [
303      "-Wno-sign-compare",
304      "-Wno-unused-function",
305      "-Wno-unused-private-field",
306    ]
307    cflags = [
308      "-Wno-sign-compare",
309      "-D HAVE_PTHREAD",
310      "-Wno-unused-function",
311      "-std=c++17",
312    ]
313
314    deps = [
315      ":protobuf_lite_static",
316      ":protobuf_static",
317    ]
318
319    public_configs = [ ":protobuf_config" ]
320  }
321  executable("protoc") {
322    sources = [ "$protobuf_dir/compiler/main.cc" ]
323    include_dirs = [
324      "$protobuf_dir/**/*.h",
325      "$protobuf_dir/**/*.inc",
326      "src",
327      "/usr/include",
328    ]
329    deps = [ ":protoc_lib" ]
330    cflags_cc = [ "-Wno-sign-compare" ]
331    cflags = [
332      "-Wno-sign-compare",
333      "-D HAVE_PTHREAD",
334    ]
335    if (is_mingw) {
336      output_extension = "exe"
337    }
338  }
339}
340