Skip to content
This repository was archived by the owner on Dec 22, 2021. It is now read-only.

Commit 051e01e

Browse files
authored
Merge pull request #21 from coryan/refactor-single-proto-libraries
cleanup: refactor single-source library definitions.
2 parents 03c3da1 + 984abcc commit 051e01e

File tree

1 file changed

+122
-190
lines changed

1 file changed

+122
-190
lines changed

CMakeLists.txt

Lines changed: 122 additions & 190 deletions
Original file line numberDiff line numberDiff line change
@@ -47,48 +47,58 @@ set(GOOGLE_CLOUD_CPP_GOOGLEAPIS_SHA256
4747
set(GOOGLEAPIS_CPP_SOURCE
4848
"${CMAKE_BINARY_DIR}/external/googleapis/src/googleapis_download")
4949

50+
set(GOOGLEAPIS_CPP_PROTO_FILES
51+
"google/api/http.proto"
52+
"google/api/annotations.proto"
53+
"google/api/auth.proto"
54+
"google/api/client.proto"
55+
"google/api/label.proto"
56+
"google/api/launch_stage.proto"
57+
"google/api/metric.proto"
58+
"google/api/monitored_resource.proto"
59+
"google/api/resource.proto"
60+
"google/devtools/cloudtrace/v2/trace.proto"
61+
"google/devtools/cloudtrace/v2/tracing.proto"
62+
"google/type/expr.proto"
63+
"google/rpc/error_details.proto"
64+
"google/rpc/status.proto"
65+
"google/iam/v1/options.proto"
66+
"google/iam/v1/policy.proto"
67+
"google/iam/v1/iam_policy.proto"
68+
"google/longrunning/operations.proto"
69+
"google/bigtable/admin/v2/bigtable_instance_admin.proto"
70+
"google/bigtable/admin/v2/bigtable_table_admin.proto"
71+
"google/bigtable/admin/v2/common.proto"
72+
"google/bigtable/admin/v2/instance.proto"
73+
"google/bigtable/admin/v2/table.proto"
74+
"google/bigtable/v2/bigtable.proto"
75+
"google/bigtable/v2/data.proto"
76+
"google/spanner/admin/database/v1/spanner_database_admin.proto"
77+
"google/spanner/admin/instance/v1/spanner_instance_admin.proto"
78+
"google/spanner/v1/keys.proto"
79+
"google/spanner/v1/mutation.proto"
80+
"google/spanner/v1/query_plan.proto"
81+
"google/spanner/v1/result_set.proto"
82+
"google/spanner/v1/spanner.proto"
83+
"google/spanner/v1/transaction.proto"
84+
"google/spanner/v1/type.proto")
85+
86+
set(GOOGLEAPIS_CPP_BYPRODUCTS)
87+
foreach (proto ${GOOGLEAPIS_PROTO_FILES})
88+
list(APPEND GOOGLEAPIS_CPP_BYPRODUCTS "${GOOGLEAPIS_CPP_SOURCE}/${proto}")
89+
endforeach ()
90+
5091
include(ExternalProject)
51-
ExternalProject_Add(
52-
googleapis_download
53-
EXCLUDE_FROM_ALL ON
54-
PREFIX "${CMAKE_BINARY_DIR}/external/googleapis"
55-
URL ${GOOGLE_CLOUD_CPP_GOOGLEAPIS_URL}
56-
URL_HASH SHA256=${GOOGLE_CLOUD_CPP_GOOGLEAPIS_SHA256}
57-
CONFIGURE_COMMAND ""
58-
BUILD_COMMAND ""
59-
INSTALL_COMMAND ""
60-
BUILD_BYPRODUCTS
61-
"${GOOGLEAPIS_CPP_SOURCE}/google/api/http.proto"
62-
"${GOOGLEAPIS_CPP_SOURCE}/google/api/annotations.proto"
63-
"${GOOGLEAPIS_CPP_SOURCE}/google/api/auth.proto"
64-
"${GOOGLEAPIS_CPP_SOURCE}/google/api/client.proto"
65-
"${GOOGLEAPIS_CPP_SOURCE}/google/api/resource.proto"
66-
"${GOOGLEAPIS_CPP_SOURCE}/google/devtools/cloudtrace/v2/trace.proto"
67-
"${GOOGLEAPIS_CPP_SOURCE}/google/devtools/cloudtrace/v2/tracing.proto"
68-
"${GOOGLEAPIS_CPP_SOURCE}/google/type/expr.proto"
69-
"${GOOGLEAPIS_CPP_SOURCE}/google/rpc/error_details.proto"
70-
"${GOOGLEAPIS_CPP_SOURCE}/google/rpc/status.proto"
71-
"${GOOGLEAPIS_CPP_SOURCE}/google/iam/v1/options.proto"
72-
"${GOOGLEAPIS_CPP_SOURCE}/google/iam/v1/policy.proto"
73-
"${GOOGLEAPIS_CPP_SOURCE}/google/iam/v1/iam_policy.proto"
74-
"${GOOGLEAPIS_CPP_SOURCE}/google/longrunning/operations.proto"
75-
"${GOOGLEAPIS_CPP_SOURCE}/google/bigtable/admin/v2/bigtable_instance_admin.proto"
76-
"${GOOGLEAPIS_CPP_SOURCE}/google/bigtable/admin/v2/bigtable_table_admin.proto"
77-
"${GOOGLEAPIS_CPP_SOURCE}/google/bigtable/admin/v2/common.proto"
78-
"${GOOGLEAPIS_CPP_SOURCE}/google/bigtable/admin/v2/instance.proto"
79-
"${GOOGLEAPIS_CPP_SOURCE}/google/bigtable/admin/v2/table.proto"
80-
"${GOOGLEAPIS_CPP_SOURCE}/google/bigtable/v2/bigtable.proto"
81-
"${GOOGLEAPIS_CPP_SOURCE}/google/bigtable/v2/data.proto"
82-
"${GOOGLEAPIS_CPP_SOURCE}/google/spanner/admin/database/v1/spanner_database_admin.proto"
83-
"${GOOGLEAPIS_CPP_SOURCE}/google/spanner/admin/instance/v1/spanner_instance_admin.proto"
84-
"${GOOGLEAPIS_CPP_SOURCE}/google/spanner/v1/keys.proto"
85-
"${GOOGLEAPIS_CPP_SOURCE}/google/spanner/v1/mutation.proto"
86-
"${GOOGLEAPIS_CPP_SOURCE}/google/spanner/v1/query_plan.proto"
87-
"${GOOGLEAPIS_CPP_SOURCE}/google/spanner/v1/result_set.proto"
88-
"${GOOGLEAPIS_CPP_SOURCE}/google/spanner/v1/spanner.proto"
89-
"${GOOGLEAPIS_CPP_SOURCE}/google/spanner/v1/transaction.proto"
90-
"${GOOGLEAPIS_CPP_SOURCE}/google/spanner/v1/type.proto"
91-
LOG_DOWNLOAD OFF)
92+
ExternalProject_Add(googleapis_download
93+
EXCLUDE_FROM_ALL ON
94+
PREFIX "${CMAKE_BINARY_DIR}/external/googleapis"
95+
URL ${GOOGLE_CLOUD_CPP_GOOGLEAPIS_URL}
96+
URL_HASH SHA256=${GOOGLE_CLOUD_CPP_GOOGLEAPIS_SHA256}
97+
CONFIGURE_COMMAND ""
98+
BUILD_COMMAND ""
99+
INSTALL_COMMAND ""
100+
BUILD_BYPRODUCTS ${GOOGLEAPIS_CPP_BYPRODUCTS}
101+
LOG_DOWNLOAD OFF)
92102

93103
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
94104
find_package(ProtobufTargets REQUIRED)
@@ -111,6 +121,51 @@ include(CompileProtos)
111121

112122
google_cloud_cpp_add_protos_property()
113123

124+
function (googleapis_cpp_short_name var proto)
125+
string(REPLACE "google/"
126+
""
127+
short_name
128+
"${proto}")
129+
string(REPLACE "/"
130+
"_"
131+
short_name
132+
"${short_name}")
133+
string(REPLACE ".proto"
134+
"_protos"
135+
short_name
136+
"${short_name}")
137+
set("${var}" "${short_name}" PARENT_SCOPE)
138+
endfunction ()
139+
140+
# Create a single source proto library.
141+
#
142+
# * proto: the filename for the proto source.
143+
# * (optional) ARGN: proto libraries the new library depends on.
144+
function (googleapis_cpp_add_library proto)
145+
googleapis_cpp_short_name(short_name "${proto}")
146+
google_cloud_cpp_grpcpp_library(googleapis_cpp_${short_name}
147+
"${GOOGLEAPIS_CPP_SOURCE}/${proto}"
148+
PROTO_PATH_DIRECTORIES
149+
"${GOOGLEAPIS_CPP_SOURCE}"
150+
"${PROTO_INCLUDE_DIR}")
151+
152+
googleapis_cpp_set_version_and_alias("${short_name}")
153+
154+
set(public_deps)
155+
foreach (dep_short_name ${ARGN})
156+
list(APPEND public_deps "googleapis-c++::${dep_short_name}")
157+
endforeach ()
158+
list(LENGTH public_deps public_deps_length)
159+
if (public_deps_length EQUAL 0)
160+
target_link_libraries("googleapis_cpp_${short_name}"
161+
PRIVATE googleapis_cpp_common_flags)
162+
else ()
163+
target_link_libraries("googleapis_cpp_${short_name}"
164+
PUBLIC ${public_deps}
165+
PRIVATE googleapis_cpp_common_flags)
166+
endif ()
167+
endfunction ()
168+
114169
function (googleapis_cpp_set_version_and_alias short_name)
115170
add_dependencies("googleapis_cpp_${short_name}" googleapis_download)
116171
set_target_properties("googleapis_cpp_${short_name}"
@@ -122,136 +177,38 @@ function (googleapis_cpp_set_version_and_alias short_name)
122177
"googleapis_cpp_${short_name}")
123178
endfunction ()
124179

125-
google_cloud_cpp_grpcpp_library(googleapis_cpp_api_http_protos
126-
"${GOOGLEAPIS_CPP_SOURCE}/google/api/http.proto"
127-
PROTO_PATH_DIRECTORIES
128-
"${GOOGLEAPIS_CPP_SOURCE}"
129-
"${PROTO_INCLUDE_DIR}")
130-
googleapis_cpp_set_version_and_alias(api_http_protos)
131-
target_link_libraries(googleapis_cpp_api_http_protos
132-
PRIVATE googleapis_cpp_common_flags)
180+
googleapis_cpp_add_library("google/api/http.proto")
181+
googleapis_cpp_add_library("google/api/annotations.proto" api_http_protos)
182+
googleapis_cpp_add_library("google/api/auth.proto" api_annotations_protos)
183+
googleapis_cpp_add_library("google/api/client.proto")
184+
googleapis_cpp_add_library("google/api/resource.proto")
133185

134-
google_cloud_cpp_grpcpp_library(
135-
googleapis_cpp_api_annotations_protos
136-
"${GOOGLEAPIS_CPP_SOURCE}/google/api/annotations.proto"
137-
PROTO_PATH_DIRECTORIES
138-
"${GOOGLEAPIS_CPP_SOURCE}"
139-
"${PROTO_INCLUDE_DIR}")
140-
googleapis_cpp_set_version_and_alias(api_annotations_protos)
141-
target_link_libraries(googleapis_cpp_api_annotations_protos
142-
PUBLIC googleapis-c++::api_http_protos
143-
PRIVATE googleapis_cpp_common_flags)
144-
145-
google_cloud_cpp_grpcpp_library(googleapis_cpp_api_auth_protos
146-
"${GOOGLEAPIS_CPP_SOURCE}/google/api/auth.proto"
147-
PROTO_PATH_DIRECTORIES
148-
"${GOOGLEAPIS_CPP_SOURCE}"
149-
"${PROTO_INCLUDE_DIR}")
150-
googleapis_cpp_set_version_and_alias(api_auth_protos)
151-
target_link_libraries(googleapis_cpp_api_auth_protos
152-
PUBLIC googleapis-c++::api_annotations_protos
153-
PRIVATE googleapis_cpp_common_flags)
186+
googleapis_cpp_add_library("google/type/expr.proto")
154187

155-
google_cloud_cpp_grpcpp_library(
156-
googleapis_cpp_api_client_protos
157-
"${GOOGLEAPIS_CPP_SOURCE}/google/api/client.proto"
158-
PROTO_PATH_DIRECTORIES
159-
"${GOOGLEAPIS_CPP_SOURCE}"
160-
"${PROTO_INCLUDE_DIR}")
161-
googleapis_cpp_set_version_and_alias(api_client_protos)
162-
target_link_libraries(googleapis_cpp_api_client_protos
163-
PRIVATE googleapis_cpp_common_flags)
164-
165-
google_cloud_cpp_grpcpp_library(
166-
googleapis_cpp_api_resource_protos
167-
"${GOOGLEAPIS_CPP_SOURCE}/google/api/resource.proto"
168-
PROTO_PATH_DIRECTORIES
169-
"${GOOGLEAPIS_CPP_SOURCE}"
170-
"${PROTO_INCLUDE_DIR}")
171-
googleapis_cpp_set_version_and_alias(api_resource_protos)
172-
target_link_libraries(googleapis_cpp_api_resource_protos
173-
PRIVATE googleapis_cpp_common_flags)
174-
175-
google_cloud_cpp_grpcpp_library(
176-
googleapis_cpp_type_expr_protos
177-
"${GOOGLEAPIS_CPP_SOURCE}/google/type/expr.proto"
178-
PROTO_PATH_DIRECTORIES
179-
"${GOOGLEAPIS_CPP_SOURCE}"
180-
"${PROTO_INCLUDE_DIR}")
181-
googleapis_cpp_set_version_and_alias(type_expr_protos)
182-
target_link_libraries(googleapis_cpp_type_expr_protos
183-
PRIVATE googleapis_cpp_common_flags)
184-
185-
google_cloud_cpp_grpcpp_library(
186-
googleapis_cpp_rpc_error_details_protos
187-
"${GOOGLEAPIS_CPP_SOURCE}/google/rpc/error_details.proto"
188-
PROTO_PATH_DIRECTORIES
189-
"${GOOGLEAPIS_CPP_SOURCE}"
190-
"${PROTO_INCLUDE_DIR}")
191-
googleapis_cpp_set_version_and_alias(rpc_error_details_protos)
192-
target_link_libraries(googleapis_cpp_rpc_error_details_protos
193-
PRIVATE googleapis_cpp_common_flags)
194-
195-
google_cloud_cpp_grpcpp_library(
196-
googleapis_cpp_rpc_status_protos
197-
"${GOOGLEAPIS_CPP_SOURCE}/google/rpc/status.proto"
198-
PROTO_PATH_DIRECTORIES
199-
"${GOOGLEAPIS_CPP_SOURCE}"
200-
"${PROTO_INCLUDE_DIR}")
201-
googleapis_cpp_set_version_and_alias(rpc_status_protos)
202-
target_link_libraries(googleapis_cpp_rpc_status_protos
203-
PUBLIC googleapis-c++::rpc_error_details_protos
204-
PRIVATE googleapis_cpp_common_flags)
188+
googleapis_cpp_add_library("google/rpc/error_details.proto")
189+
googleapis_cpp_add_library("google/rpc/status.proto" rpc_error_details_protos)
205190

206-
google_cloud_cpp_grpcpp_library(
207-
googleapis_cpp_iam_v1_options_protos
208-
"${GOOGLEAPIS_CPP_SOURCE}/google/iam/v1/options.proto"
209-
PROTO_PATH_DIRECTORIES
210-
"${GOOGLEAPIS_CPP_SOURCE}"
211-
"${PROTO_INCLUDE_DIR}")
212-
googleapis_cpp_set_version_and_alias(iam_v1_options_protos)
213-
target_link_libraries(googleapis_cpp_iam_v1_options_protos
214-
PUBLIC googleapis-c++::api_annotations_protos
215-
PRIVATE googleapis_cpp_common_flags)
191+
googleapis_cpp_add_library("google/iam/v1/options.proto" api_annotations_protos)
192+
googleapis_cpp_add_library("google/iam/v1/policy.proto"
193+
api_annotations_protos
194+
api_resource_protos
195+
type_expr_protos)
216196

217-
google_cloud_cpp_grpcpp_library(
218-
googleapis_cpp_iam_v1_policy_protos
219-
"${GOOGLEAPIS_CPP_SOURCE}/google/iam/v1/policy.proto"
220-
PROTO_PATH_DIRECTORIES
221-
"${GOOGLEAPIS_CPP_SOURCE}"
222-
"${PROTO_INCLUDE_DIR}")
223-
googleapis_cpp_set_version_and_alias(iam_v1_policy_protos)
224-
target_link_libraries(googleapis_cpp_iam_v1_policy_protos
225-
PUBLIC googleapis-c++::api_annotations_protos
226-
googleapis-c++::api_resource_protos
227-
googleapis-c++::type_expr_protos
228-
PRIVATE googleapis_cpp_common_flags)
197+
googleapis_cpp_add_library("google/iam/v1/iam_policy.proto"
198+
api_annotations_protos
199+
api_client_protos
200+
iam_v1_options_protos
201+
iam_v1_policy_protos)
229202

230-
google_cloud_cpp_grpcpp_library(
231-
googleapis_cpp_iam_v1_iam_policy_protos
232-
"${GOOGLEAPIS_CPP_SOURCE}/google/iam/v1/iam_policy.proto"
233-
PROTO_PATH_DIRECTORIES
234-
"${GOOGLEAPIS_CPP_SOURCE}"
235-
"${PROTO_INCLUDE_DIR}")
236-
googleapis_cpp_set_version_and_alias(iam_v1_iam_policy_protos)
237-
target_link_libraries(googleapis_cpp_iam_v1_iam_policy_protos
238-
PUBLIC googleapis-c++::api_annotations_protos
239-
googleapis-c++::api_client_protos
240-
googleapis-c++::iam_v1_options_protos
241-
googleapis-c++::iam_v1_policy_protos
242-
PRIVATE googleapis_cpp_common_flags)
203+
googleapis_cpp_add_library("google/longrunning/operations.proto"
204+
api_annotations_protos rpc_status_protos)
243205

244-
google_cloud_cpp_grpcpp_library(
245-
googleapis_cpp_longrunning_operations_protos
246-
"${GOOGLEAPIS_CPP_SOURCE}/google/longrunning/operations.proto"
247-
PROTO_PATH_DIRECTORIES
248-
"${GOOGLEAPIS_CPP_SOURCE}"
249-
"${PROTO_INCLUDE_DIR}")
250-
googleapis_cpp_set_version_and_alias(longrunning_operations_protos)
251-
target_link_libraries(googleapis_cpp_longrunning_operations_protos
252-
PUBLIC googleapis-c++::api_annotations_protos
253-
googleapis-c++::rpc_status_protos
254-
PRIVATE googleapis_cpp_common_flags)
206+
googleapis_cpp_add_library("google/devtools/cloudtrace/v2/trace.proto"
207+
api_annotations_protos rpc_status_protos)
208+
googleapis_cpp_add_library("google/devtools/cloudtrace/v2/tracing.proto"
209+
devtools_cloudtrace_v2_trace_protos
210+
api_annotations_protos
211+
rpc_status_protos)
255212

256213
google_cloud_cpp_grpcpp_library(
257214
googleapis_cpp_bigtable_protos
@@ -296,31 +253,6 @@ target_link_libraries(googleapis_cpp_spanner_protos
296253
googleapis-c++::iam_v1_iam_policy_protos
297254
PRIVATE googleapis_cpp_common_flags)
298255

299-
google_cloud_cpp_grpcpp_library(
300-
googleapis_cpp_devtools_cloudtrace_v2_trace_protos
301-
"${GOOGLEAPIS_CPP_SOURCE}/google/devtools/cloudtrace/v2/trace.proto"
302-
PROTO_PATH_DIRECTORIES
303-
"${GOOGLEAPIS_CPP_SOURCE}"
304-
"${PROTO_INCLUDE_DIR}")
305-
googleapis_cpp_set_version_and_alias(devtools_cloudtrace_v2_trace_protos)
306-
target_link_libraries(googleapis_cpp_devtools_cloudtrace_v2_trace_protos
307-
PUBLIC googleapis-c++::api_annotations_protos
308-
googleapis-c++::rpc_status_protos
309-
PRIVATE googleapis_cpp_common_flags)
310-
311-
google_cloud_cpp_grpcpp_library(
312-
googleapis_cpp_devtools_cloudtrace_v2_tracing_protos
313-
"${GOOGLEAPIS_CPP_SOURCE}/google/devtools/cloudtrace/v2/tracing.proto"
314-
PROTO_PATH_DIRECTORIES
315-
"${GOOGLEAPIS_CPP_SOURCE}"
316-
"${PROTO_INCLUDE_DIR}")
317-
googleapis_cpp_set_version_and_alias(devtools_cloudtrace_v2_tracing_protos)
318-
target_link_libraries(googleapis_cpp_devtools_cloudtrace_v2_tracing_protos
319-
PUBLIC googleapis-c++::devtools_cloudtrace_v2_trace_protos
320-
googleapis-c++::api_annotations_protos
321-
googleapis-c++::rpc_status_protos
322-
PRIVATE googleapis_cpp_common_flags)
323-
324256
# Install the libraries and headers in the locations determined by
325257
# GNUInstallDirs
326258
include(GNUInstallDirs)

0 commit comments

Comments
 (0)