43cb6db66c665d6a73138943e0cd7e0afc8d4145
[platform/upstream/grpc.git] / templates / gRPC-C++.podspec.template
1 %YAML 1.2
2 --- |
3   # This file has been automatically generated from a template file.
4   # Please make modifications to `templates/gRPC-C++.podspec.template`
5   # instead. This file can be regenerated from the template by running
6   # `tools/buildgen/generate_projects.sh`.
7
8   # gRPC C++ CocoaPods podspec
9   #
10   # Copyright 2017 gRPC authors.
11   #
12   # Licensed under the Apache License, Version 2.0 (the "License");
13   # you may not use this file except in compliance with the License.
14   # You may obtain a copy of the License at
15   #
16   #     http://www.apache.org/licenses/LICENSE-2.0
17   #
18   # Unless required by applicable law or agreed to in writing, software
19   # distributed under the License is distributed on an "AS IS" BASIS,
20   # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21   # See the License for the specific language governing permissions and
22   # limitations under the License.
23
24   <%!
25   def grpc_lib_files(libs, expect_libs, groups):
26     out = []
27     for lib in libs:
28       if lib.name in expect_libs:
29         for group in groups:
30           out += lib.get(group, [])
31     return out
32
33   def filter_grpcpp(files):
34     return [file for file in files if not file.startswith("include/grpc++")]
35
36   def grpc_private_files(libs):
37     out = grpc_lib_files(libs, ("grpc", "gpr"), ("headers", "src"))
38     return out
39
40   def grpc_private_headers(libs):
41     out = grpc_lib_files(libs, ("grpc", "gpr"), ("headers",))
42     return out
43
44   def grpc_public_headers(libs):
45     out = grpc_lib_files(libs, ("grpc", "gpr"), ("public_headers",))
46     return out
47
48   def grpcpp_proto_files(filegroups):
49     out = grpc_lib_files(filegroups, ("grpc++_codegen_proto", "grpc++_config_proto"), ("headers", "src", "public_headers"))
50     excl_files = grpc_lib_files(filegroups, ("grpc++_codegen_base",), ("headers", "src", "public_headers"))
51     out = [file for file in out if file not in excl_files]
52     out = filter_grpcpp(out)
53     return out
54
55   def grpcpp_private_files(libs, filegroups):
56     out = grpc_lib_files(libs, ("grpc++",), ("headers", "src"))
57     excl_files = grpc_private_files(libs)
58
59     # We exclude proto related files in this particular podspec so that we can provide a protobuf-independent lib
60     excl_files += grpcpp_proto_files(filegroups)
61     out = [file for file in out if file not in excl_files]
62
63     # Since some C++ source files directly included private headers in C core, we include all the
64     # C core headers in C++ Implementation subspec as well.
65     out += [file for file in grpc_private_headers(libs) if not file.startswith("third_party/nanopb/")]
66
67     out = filter_grpcpp(out)
68
69     return out
70
71   def grpcpp_private_headers(libs, filegroups):
72     out = grpc_lib_files(libs, ("grpc++",), ("headers",))
73
74     # We exclude proto related files in this particular podspec so that we can provide a protobuf-independent lib
75     excl_files = grpcpp_proto_files(filegroups)
76     out = [file for file in out if file not in excl_files]
77
78     # Since some C++ source files directly included private headers in C core, we intentionally
79     # keep the C core headers in \a out. But we should exclude nanopb headers.
80     out = [file for file in out if not file.startswith("third_party/nanopb/")]
81
82     out = filter_grpcpp(out)
83     return out
84
85   def grpcpp_public_headers(libs, filegroups):
86     out = grpc_lib_files(libs, ("grpc++",), ("public_headers",))
87     excl_files = grpc_public_headers(libs)
88
89     # We exclude proto related files in this particular podspec so that we can provide a protobuf-independent lib
90     excl_files += grpcpp_proto_files(filegroups)
91
92     out = [file for file in out if file not in excl_files]
93
94     out = filter_grpcpp(out)
95
96     return out
97
98   def grpc_test_util_files(libs):
99     out = grpc_lib_files(libs, ("grpc_test_util",), ("src", "headers"))
100     return out
101
102   def grpc_test_util_headers(libs):
103     out = grpc_lib_files(libs, ("grpc_test_util",), ("headers",))
104     return out
105
106   # Tests subspec is currently disabled since the tests currently use `grpc++` include style instead of `grpcpp`.
107   # TODO (mxyan): enable Tests subspec after the inclusion style is updated in `test/` directory.
108   def grpcpp_test_util_files(libs, filegroups):
109     out = grpc_lib_files(libs, ("grpc++_test_util",), ("src", "headers"))
110     excl_files = grpc_test_util_files(libs) + grpcpp_private_files(libs, filegroups)
111
112     # We exclude proto related files in this particular podspec so that we can provide a protobuf-independent lib
113     excl_files += grpc_lib_files(filegroups, ("grpc++_codegen_proto", "grpc++_config_proto"), ("headers", "src"))
114     excl_files += ["test/cpp/util/byte_buffer_proto_helper.cc",
115                    "test/cpp/util/byte_buffer_proto_helper.h",
116                    "test/cpp/end2end/test_service_impl.cc",
117                    "test/cpp/end2end/test_service_impl.h"]
118     excl_files += [file for file in out if file.endswith(".proto")]
119
120     out = [file for file in out if not file in excl_files]
121
122     # Since some C++ test files directly included private headers in C core, we intentionally add these header
123     # files to this subspec
124     out += grpc_test_util_headers(libs)
125
126     return out
127
128   def ruby_multiline_list(files, indent):
129     return (',\n' + indent*' ').join('\'%s\'' % f for f in files)
130
131   def modify_podspec_version_string(pod_version, grpc_version):
132     # Append -preX when it is a pre-release
133     if len(str(grpc_version).split('-')) > 1:
134       return pod_version + '-' + str(grpc_version).split('-')[-1]
135     else:
136       return pod_version
137
138   %>
139   Pod::Spec.new do |s|
140     s.name     = 'gRPC-C++'
141     # TODO (mxyan): use version that match gRPC version when pod is stabilized
142     # version = '${settings.version}'
143     version = '${modify_podspec_version_string('0.0.8', settings.version)}'
144     s.version  = version
145     s.summary  = 'gRPC C++ library'
146     s.homepage = 'https://grpc.io'
147     s.license  = 'Apache License, Version 2.0'
148     s.authors  = { 'The gRPC contributors' => 'grpc-packages@google.com' }
149
150     grpc_version = '${settings.version}'
151
152     s.source = {
153       :git => 'https://github.com/grpc/grpc.git',
154       :tag => "v#{grpc_version}",
155     }
156
157     s.ios.deployment_target = '7.0'
158     s.osx.deployment_target = '10.9'
159     s.tvos.deployment_target = '10.0'
160
161     s.requires_arc = false
162
163     name = 'grpcpp'
164     # Use `grpcpp` as framework name so that `#include <grpcpp/xxx.h>` works when built as
165     # framework.
166     s.module_name = name
167
168     # Add include prefix `grpcpp` so that `#include <grpcpp/xxx.h>` works when built as static
169     # library.
170     s.header_dir = name
171
172     s.pod_target_xcconfig = {
173       'HEADER_SEARCH_PATHS' => '"$(inherited)" "$(PODS_TARGET_SRCROOT)/include"',
174       'USER_HEADER_SEARCH_PATHS' => '"$(PODS_TARGET_SRCROOT)"',
175       'GCC_PREPROCESSOR_DEFINITIONS' => '"$(inherited)" "COCOAPODS=1" "PB_NO_PACKED_STRUCTS=1"',
176       'CLANG_WARN_STRICT_PROTOTYPES' => 'NO',
177       'CLANG_WARN_DOCUMENTATION_COMMENTS' => 'NO',
178
179       # If we don't set these two settings, `include/grpc/support/time.h` and
180       # `src/core/lib/support/string.h` shadow the system `<time.h>` and `<string.h>`, breaking the
181       # build.
182       'USE_HEADERMAP' => 'NO',
183       'ALWAYS_SEARCH_USER_PATHS' => 'NO',
184     }
185
186     s.libraries = 'c++'
187
188     s.default_subspecs = 'Interface', 'Implementation'
189
190     # Certificates, to be able to establish TLS connections:
191     s.resource_bundles = { 'gRPCCertificates' => ['etc/roots.pem'] }
192
193     s.header_mappings_dir = 'include/grpcpp'
194
195     s.subspec 'Interface' do |ss|
196       ss.header_mappings_dir = 'include/grpcpp'
197
198       ss.source_files = ${ruby_multiline_list(grpcpp_public_headers(libs, filegroups), 22)}
199     end
200
201     s.subspec 'Implementation' do |ss|
202       ss.header_mappings_dir = '.'
203       ss.dependency "#{s.name}/Interface", version
204       ss.dependency 'gRPC-Core', grpc_version
205       ss.dependency 'nanopb', '~> 0.3'
206
207       ss.source_files = ${ruby_multiline_list(grpcpp_private_files(libs, filegroups), 22)}
208
209       ss.private_header_files = ${ruby_multiline_list(grpcpp_private_headers(libs, filegroups), 30)}
210     end
211
212     s.subspec 'Protobuf' do |ss|
213       ss.header_mappings_dir = 'include/grpcpp'
214       ss.dependency "#{s.name}/Interface", version
215
216       ss.source_files = ${ruby_multiline_list(grpcpp_proto_files(filegroups), 22)}
217     end
218
219     s.prepare_command = <<-END_OF_COMMAND
220       find src/cpp/ -type f ! -path '*.grpc_back' -print0 | xargs -0 -L1 sed -E -i'.grpc_back' 's;#include "(pb(_.*)?\\.h)";#include <nanopb/\\1>;g'
221       find src/cpp/ -type f -path '*.grpc_back' -print0 | xargs -0 rm
222       find src/core/ -type f ! -path '*.grpc_back' -print0 | xargs -0 -L1 sed -E -i'.grpc_back' 's;#include "(pb(_.*)?\\.h)";#include <nanopb/\\1>;g'
223       find src/core/ -type f -path '*.grpc_back' -print0 | xargs -0 rm
224     END_OF_COMMAND
225   end