Skip to content

Commit 7cdeb9b

Browse files
authored
cleanup(cmake): use keyword, not global variable (googleapis#13247)
1 parent d9694c1 commit 7cdeb9b

File tree

122 files changed

+319
-439
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

122 files changed

+319
-439
lines changed

.cmake-format.py

+10
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,16 @@
4747
"BINARY_DIR": 1,
4848
},
4949
},
50+
"google_cloud_cpp_add_gapic_library": {
51+
"flags": ["EXPERIMENTAL", "TRANSITION"],
52+
"kwargs": {
53+
"SERVICE_DIRS": "+",
54+
"CROSS_LIB_DEPS": "+",
55+
"SHARED_PROTO_DEPS": "+",
56+
"ADDITIONAL_PROTO_LISTS": "+",
57+
"BACKWARDS_COMPAT_PROTO_TARGETS": "+",
58+
},
59+
},
5060
"google_cloud_cpp_doxygen_targets": {
5161
"flags": ["RECURSIVE"],
5262
"kwargs": {

cmake/GoogleCloudCppLibrary.cmake

+8-13
Original file line numberDiff line numberDiff line change
@@ -124,20 +124,13 @@ function (google_cloud_cpp_add_library_protos library)
124124
endfunction ()
125125

126126
#
127-
# A function to add targets for GA libraries that use gRPC for transport.
127+
# A function to add targets for GAPICS - libraries that use gRPC for transport.
128128
#
129129
# * library: the short name of the library, e.g. `kms`.
130130
# * display_name: the display name of the library, e.g. "Cloud Key Management
131131
# Service (KMS) API"
132132
#
133-
# Additionally, we must set the following **variable** in the parent scope. We
134-
# cannot use a `cmake_parse_arguments()` keyword because it will skip the empty
135-
# string when provided in a list. We often need to use the empty string.
136-
#
137-
# * GOOGLE_CLOUD_CPP_SERVICE_DIRS: a list of service directories within the
138-
# library.
139-
#
140-
# The following **keywords** can be optionally supplied to handle edge cases:
133+
# The function respects the following keywords:
141134
#
142135
# * ADDITIONAL_PROTO_LISTS: a list of proto files that may be used indirectly.
143136
# `asset` sets this.
@@ -146,16 +139,18 @@ endfunction ()
146139
# libraries for these, which link to the desired proto library. See #8022 for
147140
# more details.
148141
# * CROSS_LIB_DEPS: a list of client libraries which this library depends on.
142+
# * SERVICE_DIRS: a list of service directories within the library. Use
143+
# "__EMPTY__" to represent the empty string in the list.
149144
# * SHARED_PROTO_DEPS: a list of proto libraries which this library depends on,
150145
# e.g. `grafeas`. This function will define the proto library targets if they
151146
# do not already exist.
152147
#
153-
function (google_cloud_cpp_add_ga_grpc_library library display_name)
148+
function (google_cloud_cpp_add_gapic_library library display_name)
154149
cmake_parse_arguments(
155150
_opt
156151
"EXPERIMENTAL;TRANSITION"
157152
""
158-
"ADDITIONAL_PROTO_LISTS;BACKWARDS_COMPAT_PROTO_TARGETS;CROSS_LIB_DEPS;SHARED_PROTO_DEPS"
153+
"ADDITIONAL_PROTO_LISTS;BACKWARDS_COMPAT_PROTO_TARGETS;CROSS_LIB_DEPS;SERVICE_DIRS;SHARED_PROTO_DEPS"
159154
${ARGN})
160155
if (_opt_EXPERIMENTAL AND _opt_TRANSITION)
161156
message(
@@ -188,7 +183,7 @@ function (google_cloud_cpp_add_ga_grpc_library library display_name)
188183

189184
unset(mocks_globs)
190185
unset(source_globs)
191-
foreach (dir IN LISTS GOOGLE_CLOUD_CPP_SERVICE_DIRS)
186+
foreach (dir IN LISTS _opt_SERVICE_DIRS)
192187
if ("${dir}" STREQUAL "__EMPTY__")
193188
set(dir "")
194189
endif ()
@@ -355,7 +350,7 @@ function (google_cloud_cpp_add_ga_grpc_library library display_name)
355350

356351
# ${library_alias} must be defined before we can add the samples.
357352
if (BUILD_TESTING AND GOOGLE_CLOUD_CPP_ENABLE_CXX_EXCEPTIONS)
358-
foreach (dir IN LISTS GOOGLE_CLOUD_CPP_SERVICE_DIRS)
353+
foreach (dir IN LISTS _opt_SERVICE_DIRS)
359354
if ("${dir}" STREQUAL "__EMPTY__")
360355
set(dir "")
361356
endif ()

generator/internal/scaffold_generator.cc

+2-3
Original file line numberDiff line numberDiff line change
@@ -473,9 +473,8 @@ void GenerateCMakeLists(std::ostream& os,
473473
474474
include(GoogleCloudCppLibrary)
475475
476-
set(GOOGLE_CLOUD_CPP_SERVICE_DIRS "$service_subdirectory$")
477-
478-
google_cloud_cpp_add_ga_grpc_library($library$ "$title$"$experimental$)
476+
google_cloud_cpp_add_gapic_library($library$ "$title$"$experimental$
477+
SERVICE_DIRS "$service_subdirectory$")
479478
480479
if (BUILD_TESTING AND GOOGLE_CLOUD_CPP_ENABLE_CXX_EXCEPTIONS)
481480
add_executable($library$_quickstart "quickstart/quickstart.cc")

generator/internal/scaffold_generator_test.cc

+2-3
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,8 @@ TEST_F(ScaffoldGenerator, CMakeLists) {
229229
EXPECT_THAT(actual, Not(HasSubstr("$experimental$")));
230230
EXPECT_THAT(actual, HasSubstr(R"""(include(GoogleCloudCppLibrary)
231231
232-
set(GOOGLE_CLOUD_CPP_SERVICE_DIRS "v1/")
233-
234-
google_cloud_cpp_add_ga_grpc_library(test "Test Only API")
232+
google_cloud_cpp_add_gapic_library(test "Test Only API"
233+
SERVICE_DIRS "v1/")
235234
)"""));
236235

237236
EXPECT_THAT(actual, HasSubstr(R"""(add_executable(test_quickstart)"""));

google/cloud/accessapproval/CMakeLists.txt

+2-3
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@
1616

1717
include(GoogleCloudCppLibrary)
1818

19-
set(GOOGLE_CLOUD_CPP_SERVICE_DIRS "" "v1/")
20-
21-
google_cloud_cpp_add_ga_grpc_library(accessapproval "Access Approval API")
19+
google_cloud_cpp_add_gapic_library(accessapproval "Access Approval API"
20+
SERVICE_DIRS "__EMPTY__" "v1/")
2221

2322
if (BUILD_TESTING AND GOOGLE_CLOUD_CPP_ENABLE_CXX_EXCEPTIONS)
2423
add_executable(accessapproval_quickstart "quickstart/quickstart.cc")

google/cloud/accesscontextmanager/CMakeLists.txt

+3-4
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@
1616

1717
include(GoogleCloudCppLibrary)
1818

19-
set(GOOGLE_CLOUD_CPP_SERVICE_DIRS "" "v1/")
20-
21-
google_cloud_cpp_add_ga_grpc_library(accesscontextmanager
22-
"Access Context Manager API")
19+
google_cloud_cpp_add_gapic_library(
20+
accesscontextmanager "Access Context Manager API" SERVICE_DIRS "__EMPTY__"
21+
"v1/")
2322

2423
if (BUILD_TESTING AND GOOGLE_CLOUD_CPP_ENABLE_CXX_EXCEPTIONS)
2524
add_executable(accesscontextmanager_quickstart "quickstart/quickstart.cc")

google/cloud/advisorynotifications/CMakeLists.txt

+2-4
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,8 @@
1616

1717
include(GoogleCloudCppLibrary)
1818

19-
set(GOOGLE_CLOUD_CPP_SERVICE_DIRS "v1/")
20-
21-
google_cloud_cpp_add_ga_grpc_library(advisorynotifications
22-
"Advisory Notifications API")
19+
google_cloud_cpp_add_gapic_library(
20+
advisorynotifications "Advisory Notifications API" SERVICE_DIRS "v1/")
2321

2422
if (BUILD_TESTING AND GOOGLE_CLOUD_CPP_ENABLE_CXX_EXCEPTIONS)
2523
add_executable(advisorynotifications_quickstart "quickstart/quickstart.cc")

google/cloud/aiplatform/CMakeLists.txt

+2-3
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@
1616

1717
include(GoogleCloudCppLibrary)
1818

19-
set(GOOGLE_CLOUD_CPP_SERVICE_DIRS "v1/")
20-
21-
google_cloud_cpp_add_ga_grpc_library(aiplatform "Vertex AI API")
19+
google_cloud_cpp_add_gapic_library(aiplatform "Vertex AI API"
20+
SERVICE_DIRS "v1/")
2221

2322
if (BUILD_TESTING AND GOOGLE_CLOUD_CPP_ENABLE_CXX_EXCEPTIONS)
2423
add_executable(aiplatform_quickstart "quickstart/quickstart.cc")

google/cloud/alloydb/CMakeLists.txt

+1-3
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@
1616

1717
include(GoogleCloudCppLibrary)
1818

19-
set(GOOGLE_CLOUD_CPP_SERVICE_DIRS "v1/")
20-
21-
google_cloud_cpp_add_ga_grpc_library(alloydb "AlloyDB API")
19+
google_cloud_cpp_add_gapic_library(alloydb "AlloyDB API" SERVICE_DIRS "v1/")
2220

2321
if (BUILD_TESTING AND GOOGLE_CLOUD_CPP_ENABLE_CXX_EXCEPTIONS)
2422
add_executable(alloydb_quickstart "quickstart/quickstart.cc")

google/cloud/apigateway/CMakeLists.txt

+2-3
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@
1616

1717
include(GoogleCloudCppLibrary)
1818

19-
set(GOOGLE_CLOUD_CPP_SERVICE_DIRS "" "v1/")
20-
21-
google_cloud_cpp_add_ga_grpc_library(apigateway "API Gateway API")
19+
google_cloud_cpp_add_gapic_library(apigateway "API Gateway API"
20+
SERVICE_DIRS "__EMPTY__" "v1/")
2221

2322
if (BUILD_TESTING AND GOOGLE_CLOUD_CPP_ENABLE_CXX_EXCEPTIONS)
2423
add_executable(apigateway_quickstart "quickstart/quickstart.cc")

google/cloud/apigeeconnect/CMakeLists.txt

+2-3
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@
1616

1717
include(GoogleCloudCppLibrary)
1818

19-
set(GOOGLE_CLOUD_CPP_SERVICE_DIRS "" "v1/")
20-
21-
google_cloud_cpp_add_ga_grpc_library(apigeeconnect "Apigee Connect API")
19+
google_cloud_cpp_add_gapic_library(apigeeconnect "Apigee Connect API"
20+
SERVICE_DIRS "__EMPTY__" "v1/")
2221

2322
if (BUILD_TESTING AND GOOGLE_CLOUD_CPP_ENABLE_CXX_EXCEPTIONS)
2423
add_executable(apigeeconnect_quickstart "quickstart/quickstart.cc")

google/cloud/apikeys/CMakeLists.txt

+2-3
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@
1616

1717
include(GoogleCloudCppLibrary)
1818

19-
set(GOOGLE_CLOUD_CPP_SERVICE_DIRS "" "v2/")
20-
21-
google_cloud_cpp_add_ga_grpc_library(apikeys "API Keys API")
19+
google_cloud_cpp_add_gapic_library(apikeys "API Keys API"
20+
SERVICE_DIRS "__EMPTY__" "v2/")
2221

2322
if (BUILD_TESTING AND GOOGLE_CLOUD_CPP_ENABLE_CXX_EXCEPTIONS)
2423
add_executable(apikeys_quickstart "quickstart/quickstart.cc")

google/cloud/appengine/CMakeLists.txt

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616

1717
include(GoogleCloudCppLibrary)
1818

19-
set(GOOGLE_CLOUD_CPP_SERVICE_DIRS "" "v1/")
20-
21-
google_cloud_cpp_add_ga_grpc_library(appengine "App Engine Admin API"
22-
SHARED_PROTO_DEPS "logging_type")
19+
google_cloud_cpp_add_gapic_library(
20+
appengine "App Engine Admin API"
21+
SERVICE_DIRS "__EMPTY__" "v1/"
22+
SHARED_PROTO_DEPS "logging_type")
2323

2424
if (BUILD_TESTING AND GOOGLE_CLOUD_CPP_ENABLE_CXX_EXCEPTIONS)
2525
add_executable(appengine_quickstart "quickstart/quickstart.cc")

google/cloud/artifactregistry/CMakeLists.txt

+2-3
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@
1616

1717
include(GoogleCloudCppLibrary)
1818

19-
set(GOOGLE_CLOUD_CPP_SERVICE_DIRS "" "v1/")
20-
21-
google_cloud_cpp_add_ga_grpc_library(artifactregistry "Artifact Registry API")
19+
google_cloud_cpp_add_gapic_library(artifactregistry "Artifact Registry API"
20+
SERVICE_DIRS "__EMPTY__" "v1/")
2221

2322
if (BUILD_TESTING AND GOOGLE_CLOUD_CPP_ENABLE_CXX_EXCEPTIONS)
2423
add_executable(artifactregistry_quickstart "quickstart/quickstart.cc")

google/cloud/asset/CMakeLists.txt

+10-12
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,17 @@
1616

1717
include(GoogleCloudCppLibrary)
1818

19-
set(GOOGLE_CLOUD_CPP_SERVICE_DIRS "" "v1/")
20-
21-
google_cloud_cpp_add_ga_grpc_library(
22-
asset
23-
"Cloud Asset API"
24-
# orgpolicy/v**1** is used *indirectly* by google/cloud/asset, therefore it
25-
# does not appear in protolists/asset.list. In addition, it is not compiled
26-
# by any other library. So, added manually.
19+
google_cloud_cpp_add_gapic_library(
20+
asset "Cloud Asset API"
21+
SERVICE_DIRS
22+
"__EMPTY__"
23+
"v1/"
24+
# orgpolicy/v**1** is used *indirectly* by google/cloud/asset, therefore
25+
# it does not appear in protolists/asset.list. In addition, it is not
26+
# compiled by any other library. So, added manually.
2727
ADDITIONAL_PROTO_LISTS
28-
"${EXTERNAL_GOOGLEAPIS_SOURCE}/google/cloud/orgpolicy/v1/orgpolicy.proto"
29-
CROSS_LIB_DEPS
30-
"accesscontextmanager"
31-
"osconfig")
28+
"${EXTERNAL_GOOGLEAPIS_SOURCE}/google/cloud/orgpolicy/v1/orgpolicy.proto"
29+
CROSS_LIB_DEPS "accesscontextmanager" "osconfig")
3230

3331
if (BUILD_TESTING AND GOOGLE_CLOUD_CPP_ENABLE_CXX_EXCEPTIONS)
3432
add_executable(asset_quickstart "quickstart/quickstart.cc")

google/cloud/assuredworkloads/CMakeLists.txt

+2-3
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@
1616

1717
include(GoogleCloudCppLibrary)
1818

19-
set(GOOGLE_CLOUD_CPP_SERVICE_DIRS "" "v1/")
20-
21-
google_cloud_cpp_add_ga_grpc_library(assuredworkloads "Assured Workloads API")
19+
google_cloud_cpp_add_gapic_library(assuredworkloads "Assured Workloads API"
20+
SERVICE_DIRS "__EMPTY__" "v1/")
2221

2322
if (BUILD_TESTING AND GOOGLE_CLOUD_CPP_ENABLE_CXX_EXCEPTIONS)
2423
add_executable(assuredworkloads_quickstart "quickstart/quickstart.cc")

google/cloud/automl/CMakeLists.txt

+2-3
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@
1616

1717
include(GoogleCloudCppLibrary)
1818

19-
set(GOOGLE_CLOUD_CPP_SERVICE_DIRS "" "v1/")
20-
21-
google_cloud_cpp_add_ga_grpc_library(automl "Cloud AutoML API")
19+
google_cloud_cpp_add_gapic_library(automl "Cloud AutoML API"
20+
SERVICE_DIRS "__EMPTY__" "v1/")
2221

2322
if (BUILD_TESTING AND GOOGLE_CLOUD_CPP_ENABLE_CXX_EXCEPTIONS)
2423
add_executable(automl_quickstart "quickstart/quickstart.cc")

google/cloud/baremetalsolution/CMakeLists.txt

+2-4
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,8 @@
1616

1717
include(GoogleCloudCppLibrary)
1818

19-
set(GOOGLE_CLOUD_CPP_SERVICE_DIRS "" "v2/")
20-
21-
google_cloud_cpp_add_ga_grpc_library(baremetalsolution
22-
"Bare Metal Solution API")
19+
google_cloud_cpp_add_gapic_library(baremetalsolution "Bare Metal Solution API"
20+
SERVICE_DIRS "__EMPTY__" "v2/")
2321

2422
if (BUILD_TESTING AND GOOGLE_CLOUD_CPP_ENABLE_CXX_EXCEPTIONS)
2523
add_executable(baremetalsolution_quickstart "quickstart/quickstart.cc")

google/cloud/batch/CMakeLists.txt

+2-3
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@
1616

1717
include(GoogleCloudCppLibrary)
1818

19-
set(GOOGLE_CLOUD_CPP_SERVICE_DIRS "" "v1/")
20-
21-
google_cloud_cpp_add_ga_grpc_library(batch "Batch API")
19+
google_cloud_cpp_add_gapic_library(batch "Batch API" SERVICE_DIRS "__EMPTY__"
20+
"v1/")
2221

2322
if (BUILD_TESTING AND GOOGLE_CLOUD_CPP_ENABLE_CXX_EXCEPTIONS)
2423
add_executable(batch_quickstart "quickstart/quickstart.cc")

google/cloud/beyondcorp/CMakeLists.txt

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616

1717
include(GoogleCloudCppLibrary)
1818

19-
set(GOOGLE_CLOUD_CPP_SERVICE_DIRS "" "appconnections/v1/" "appconnectors/v1/"
20-
"appgateways/v1/")
21-
22-
google_cloud_cpp_add_ga_grpc_library(beyondcorp "BeyondCorp API")
19+
google_cloud_cpp_add_gapic_library(
20+
beyondcorp "BeyondCorp API"
21+
SERVICE_DIRS "__EMPTY__" "appconnections/v1/" "appconnectors/v1/"
22+
"appgateways/v1/")
2323

2424
if (BUILD_TESTING AND GOOGLE_CLOUD_CPP_ENABLE_CXX_EXCEPTIONS)
2525
add_executable(beyondcorp_quickstart "quickstart/quickstart.cc")

google/cloud/bigquery/bigquery_grpc.cmake

+14-15
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,19 @@
1616

1717
include(GoogleCloudCppLibrary)
1818

19-
set(GOOGLE_CLOUD_CPP_SERVICE_DIRS
20-
""
21-
"analyticshub/v1/"
22-
"biglake/v1/"
23-
"connection/v1/"
24-
"datapolicies/v1/"
25-
"datatransfer/v1/"
26-
"migration/v2/"
27-
"reservation/v1/"
28-
"storage/v1/")
29-
30-
google_cloud_cpp_add_ga_grpc_library(
31-
bigquery "Google Cloud BigQuery API" BACKWARDS_COMPAT_PROTO_TARGETS
32-
"cloud_bigquery_protos")
19+
google_cloud_cpp_add_gapic_library(
20+
bigquery "Google Cloud BigQuery API"
21+
SERVICE_DIRS
22+
"__EMPTY__"
23+
"analyticshub/v1/"
24+
"biglake/v1/"
25+
"connection/v1/"
26+
"datapolicies/v1/"
27+
"datatransfer/v1/"
28+
"migration/v2/"
29+
"reservation/v1/"
30+
"storage/v1/"
31+
BACKWARDS_COMPAT_PROTO_TARGETS "cloud_bigquery_protos")
3332

3433
# Examples are enabled if possible, but package maintainers may want to disable
3534
# compilation to speed up their builds.
@@ -49,7 +48,7 @@ if (GOOGLE_CLOUD_CPP_ENABLE_EXAMPLES)
4948
endif ()
5049

5150
# BigQuery has a handwritten sample that demonstrates mocking. The executable is
52-
# added by `google_cloud_cpp_add_ga_grpc_library()`. We need to manually link it
51+
# added by `google_cloud_cpp_add_gapic_library()`. We need to manually link it
5352
# against Google Mock.
5453
if (BUILD_TESTING AND GOOGLE_CLOUD_CPP_ENABLE_CXX_EXCEPTIONS)
5554
target_link_libraries(bigquery_samples_mock_bigquery_read

google/cloud/billing/CMakeLists.txt

+2-3
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@
1616

1717
include(GoogleCloudCppLibrary)
1818

19-
set(GOOGLE_CLOUD_CPP_SERVICE_DIRS "" "budgets/v1/" "v1/")
20-
21-
google_cloud_cpp_add_ga_grpc_library(billing "Cloud Billing Budget API")
19+
google_cloud_cpp_add_gapic_library(billing "Cloud Billing Budget API"
20+
SERVICE_DIRS "__EMPTY__" "budgets/v1/" "v1/")
2221

2322
if (BUILD_TESTING AND GOOGLE_CLOUD_CPP_ENABLE_CXX_EXCEPTIONS)
2423
add_executable(billing_quickstart "quickstart/quickstart.cc")

google/cloud/binaryauthorization/CMakeLists.txt

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616

1717
include(GoogleCloudCppLibrary)
1818

19-
set(GOOGLE_CLOUD_CPP_SERVICE_DIRS "" "v1/")
20-
21-
google_cloud_cpp_add_ga_grpc_library(
22-
binaryauthorization "Binary Authorization API" SHARED_PROTO_DEPS "grafeas")
19+
google_cloud_cpp_add_gapic_library(
20+
binaryauthorization "Binary Authorization API"
21+
SERVICE_DIRS "__EMPTY__" "v1/"
22+
SHARED_PROTO_DEPS "grafeas")
2323

2424
if (BUILD_TESTING AND GOOGLE_CLOUD_CPP_ENABLE_CXX_EXCEPTIONS)
2525
add_executable(binaryauthorization_quickstart "quickstart/quickstart.cc")

0 commit comments

Comments
 (0)