# Copyright (c) 2021 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import("//build/ohos.gni") config("protobuf_config") { include_dirs = [ "src" ] } protobuf_dir = "src/google/protobuf" protobuf_lite_src = [ "$protobuf_dir/any_lite.cc", "$protobuf_dir/arena.cc", "$protobuf_dir/extension_set.cc", "$protobuf_dir/generated_enum_util.cc", "$protobuf_dir/generated_message_table_driven_lite.cc", "$protobuf_dir/generated_message_util.cc", "$protobuf_dir/implicit_weak_message.cc", "$protobuf_dir/io/coded_stream.cc", "$protobuf_dir/io/io_win32.cc", "$protobuf_dir/io/strtod.cc", "$protobuf_dir/io/zero_copy_stream.cc", "$protobuf_dir/io/zero_copy_stream_impl.cc", "$protobuf_dir/io/zero_copy_stream_impl_lite.cc", "$protobuf_dir/message_lite.cc", "$protobuf_dir/parse_context.cc", "$protobuf_dir/repeated_field.cc", "$protobuf_dir/stubs/bytestream.cc", "$protobuf_dir/stubs/common.cc", "$protobuf_dir/stubs/int128.cc", "$protobuf_dir/stubs/status.cc", "$protobuf_dir/stubs/statusor.cc", "$protobuf_dir/stubs/stringpiece.cc", "$protobuf_dir/stubs/stringprintf.cc", "$protobuf_dir/stubs/structurally_valid.cc", "$protobuf_dir/stubs/strutil.cc", "$protobuf_dir/stubs/time.cc", "$protobuf_dir/wire_format_lite.cc", ] protobuf_src = [ "$protobuf_dir/any.cc", "$protobuf_dir/any.pb.cc", "$protobuf_dir/api.pb.cc", "$protobuf_dir/compiler/importer.cc", "$protobuf_dir/compiler/parser.cc", "$protobuf_dir/descriptor.cc", "$protobuf_dir/descriptor.pb.cc", "$protobuf_dir/descriptor_database.cc", "$protobuf_dir/duration.pb.cc", "$protobuf_dir/dynamic_message.cc", "$protobuf_dir/empty.pb.cc", "$protobuf_dir/extension_set_heavy.cc", "$protobuf_dir/field_mask.pb.cc", "$protobuf_dir/generated_message_reflection.cc", "$protobuf_dir/generated_message_table_driven.cc", "$protobuf_dir/io/gzip_stream.cc", "$protobuf_dir/io/printer.cc", "$protobuf_dir/io/tokenizer.cc", "$protobuf_dir/map_field.cc", "$protobuf_dir/message.cc", "$protobuf_dir/reflection_ops.cc", "$protobuf_dir/service.cc", "$protobuf_dir/source_context.pb.cc", "$protobuf_dir/struct.pb.cc", "$protobuf_dir/stubs/substitute.cc", "$protobuf_dir/text_format.cc", "$protobuf_dir/timestamp.pb.cc", "$protobuf_dir/type.pb.cc", "$protobuf_dir/unknown_field_set.cc", "$protobuf_dir/util/delimited_message_util.cc", "$protobuf_dir/util/field_comparator.cc", "$protobuf_dir/util/field_mask_util.cc", "$protobuf_dir/util/internal/datapiece.cc", "$protobuf_dir/util/internal/default_value_objectwriter.cc", "$protobuf_dir/util/internal/error_listener.cc", "$protobuf_dir/util/internal/field_mask_utility.cc", "$protobuf_dir/util/internal/json_escaping.cc", "$protobuf_dir/util/internal/json_objectwriter.cc", "$protobuf_dir/util/internal/json_stream_parser.cc", "$protobuf_dir/util/internal/object_writer.cc", "$protobuf_dir/util/internal/proto_writer.cc", "$protobuf_dir/util/internal/protostream_objectsource.cc", "$protobuf_dir/util/internal/protostream_objectwriter.cc", "$protobuf_dir/util/internal/type_info.cc", "$protobuf_dir/util/internal/type_info_test_helper.cc", "$protobuf_dir/util/internal/utility.cc", "$protobuf_dir/util/json_util.cc", "$protobuf_dir/util/message_differencer.cc", "$protobuf_dir/util/time_util.cc", "$protobuf_dir/util/type_resolver_util.cc", "$protobuf_dir/wire_format.cc", "$protobuf_dir/wrappers.pb.cc", ] if (use_wasm) { source_set("protobuf_lite_static") { sources = protobuf_lite_src include_dirs = [ "$protobuf_dir/**/*.h", "$protobuf_dir/**/*.inc", "src", ] cflags_cc = [ "-Wno-sign-compare" ] cflags = [ "-Wno-sign-compare", "-D HAVE_PTHREAD", "-std=c++17", ] if (wasm_use_thread) { cflags += [ "-mbulk-memory", "-matomics", ] } public_configs = [ ":protobuf_config" ] } } else { source_set("protobuf_lite_static") { sources = protobuf_lite_src include_dirs = [ "$protobuf_dir/**/*.h", "$protobuf_dir/**/*.inc", "src", ] cflags_cc = [ "-Wno-sign-compare" ] cflags = [ "-Wno-sign-compare", "-D HAVE_PTHREAD", "-std=c++17", ] public_configs = [ ":protobuf_config" ] } } if (use_wasm) { source_set("protobuf_static") { sources = protobuf_src include_dirs = [ "$protobuf_dir/**/*.h", "$protobuf_dir/**/*.inc", "src", ] cflags_cc = [ "-Wno-sign-compare" ] cflags = [ "-Wno-sign-compare", "-D HAVE_PTHREAD", "-std=c++17", ] if (wasm_use_thread) { cflags += [ "-mbulk-memory", "-matomics", ] } deps = [ ":protobuf_lite_static" ] public_configs = [ ":protobuf_config" ] } } else { source_set("protobuf_static") { sources = protobuf_src include_dirs = [ "$protobuf_dir/**/*.h", "$protobuf_dir/**/*.inc", "src", ] cflags = [ "-Wno-sign-compare", "-D HAVE_PTHREAD", "-ftrapv", "-fstack-protector-strong", "-fstack-protector-all", "-D_FORTIFY_SOURCE=2 -O2", "-std=c++17", ] ldflags = [ "-fstack-protector" ] if (!is_mac) { ldflags += [ "-fuse-ld=gold", "-Wl,--gc-sections", "-Wl,-O1", "-fpie", "-pie", ] } if (!is_win) { cflags += [ "-fPIE", "-fPIC", ] } deps = [ ":protobuf_lite_static" ] public_configs = [ ":protobuf_config" ] } source_set("protoc_lib") { sources = [ "$protobuf_dir/compiler/code_generator.cc", "$protobuf_dir/compiler/command_line_interface.cc", "$protobuf_dir/compiler/cpp/cpp_enum.cc", "$protobuf_dir/compiler/cpp/cpp_enum_field.cc", "$protobuf_dir/compiler/cpp/cpp_extension.cc", "$protobuf_dir/compiler/cpp/cpp_field.cc", "$protobuf_dir/compiler/cpp/cpp_file.cc", "$protobuf_dir/compiler/cpp/cpp_generator.cc", "$protobuf_dir/compiler/cpp/cpp_helpers.cc", "$protobuf_dir/compiler/cpp/cpp_map_field.cc", "$protobuf_dir/compiler/cpp/cpp_message.cc", "$protobuf_dir/compiler/cpp/cpp_message_field.cc", "$protobuf_dir/compiler/cpp/cpp_padding_optimizer.cc", "$protobuf_dir/compiler/cpp/cpp_primitive_field.cc", "$protobuf_dir/compiler/cpp/cpp_service.cc", "$protobuf_dir/compiler/cpp/cpp_string_field.cc", "$protobuf_dir/compiler/csharp/csharp_doc_comment.cc", "$protobuf_dir/compiler/csharp/csharp_enum.cc", "$protobuf_dir/compiler/csharp/csharp_enum_field.cc", "$protobuf_dir/compiler/csharp/csharp_field_base.cc", "$protobuf_dir/compiler/csharp/csharp_generator.cc", "$protobuf_dir/compiler/csharp/csharp_helpers.cc", "$protobuf_dir/compiler/csharp/csharp_map_field.cc", "$protobuf_dir/compiler/csharp/csharp_message.cc", "$protobuf_dir/compiler/csharp/csharp_message_field.cc", "$protobuf_dir/compiler/csharp/csharp_primitive_field.cc", "$protobuf_dir/compiler/csharp/csharp_reflection_class.cc", "$protobuf_dir/compiler/csharp/csharp_repeated_enum_field.cc", "$protobuf_dir/compiler/csharp/csharp_repeated_message_field.cc", "$protobuf_dir/compiler/csharp/csharp_repeated_primitive_field.cc", "$protobuf_dir/compiler/csharp/csharp_source_generator_base.cc", "$protobuf_dir/compiler/csharp/csharp_wrapper_field.cc", "$protobuf_dir/compiler/java/java_context.cc", "$protobuf_dir/compiler/java/java_doc_comment.cc", "$protobuf_dir/compiler/java/java_enum.cc", "$protobuf_dir/compiler/java/java_enum_field.cc", "$protobuf_dir/compiler/java/java_enum_field_lite.cc", "$protobuf_dir/compiler/java/java_enum_lite.cc", "$protobuf_dir/compiler/java/java_extension.cc", "$protobuf_dir/compiler/java/java_extension_lite.cc", "$protobuf_dir/compiler/java/java_field.cc", "$protobuf_dir/compiler/java/java_file.cc", "$protobuf_dir/compiler/java/java_generator.cc", "$protobuf_dir/compiler/java/java_generator_factory.cc", "$protobuf_dir/compiler/java/java_helpers.cc", "$protobuf_dir/compiler/java/java_map_field.cc", "$protobuf_dir/compiler/java/java_map_field_lite.cc", "$protobuf_dir/compiler/java/java_message.cc", "$protobuf_dir/compiler/java/java_message_builder.cc", "$protobuf_dir/compiler/java/java_message_builder_lite.cc", "$protobuf_dir/compiler/java/java_message_field.cc", "$protobuf_dir/compiler/java/java_message_field_lite.cc", "$protobuf_dir/compiler/java/java_message_lite.cc", "$protobuf_dir/compiler/java/java_name_resolver.cc", "$protobuf_dir/compiler/java/java_primitive_field.cc", "$protobuf_dir/compiler/java/java_primitive_field_lite.cc", "$protobuf_dir/compiler/java/java_service.cc", "$protobuf_dir/compiler/java/java_shared_code_generator.cc", "$protobuf_dir/compiler/java/java_string_field.cc", "$protobuf_dir/compiler/java/java_string_field_lite.cc", "$protobuf_dir/compiler/js/js_generator.cc", "$protobuf_dir/compiler/js/well_known_types_embed.cc", "$protobuf_dir/compiler/objectivec/objectivec_enum.cc", "$protobuf_dir/compiler/objectivec/objectivec_enum_field.cc", "$protobuf_dir/compiler/objectivec/objectivec_extension.cc", "$protobuf_dir/compiler/objectivec/objectivec_field.cc", "$protobuf_dir/compiler/objectivec/objectivec_file.cc", "$protobuf_dir/compiler/objectivec/objectivec_generator.cc", "$protobuf_dir/compiler/objectivec/objectivec_helpers.cc", "$protobuf_dir/compiler/objectivec/objectivec_map_field.cc", "$protobuf_dir/compiler/objectivec/objectivec_message.cc", "$protobuf_dir/compiler/objectivec/objectivec_message_field.cc", "$protobuf_dir/compiler/objectivec/objectivec_oneof.cc", "$protobuf_dir/compiler/objectivec/objectivec_primitive_field.cc", "$protobuf_dir/compiler/php/php_generator.cc", "$protobuf_dir/compiler/plugin.cc", "$protobuf_dir/compiler/plugin.pb.cc", "$protobuf_dir/compiler/python/python_generator.cc", "$protobuf_dir/compiler/ruby/ruby_generator.cc", "$protobuf_dir/compiler/subprocess.cc", "$protobuf_dir/compiler/zip_writer.cc", ] include_dirs = [ "$protobuf_dir/**/*.h", "$protobuf_dir/**/*.inc", "src", ] if (!use_wasm) { configs = default_configs } cflags_cc = [ "-Wno-sign-compare", "-Wno-unused-function", "-Wno-unused-private-field", ] cflags = [ "-Wno-sign-compare", "-D HAVE_PTHREAD", "-Wno-unused-function", "-std=c++17", ] deps = [ ":protobuf_lite_static", ":protobuf_static", ] public_configs = [ ":protobuf_config" ] } executable("protoc") { sources = [ "$protobuf_dir/compiler/main.cc" ] include_dirs = [ "$protobuf_dir/**/*.h", "$protobuf_dir/**/*.inc", "src", "/usr/include", ] deps = [ ":protoc_lib" ] cflags_cc = [ "-Wno-sign-compare" ] cflags = [ "-Wno-sign-compare", "-D HAVE_PTHREAD", ] if (is_mingw) { output_extension = "exe" } } }