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

Lines changed: 10 additions & 0 deletions
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

Lines changed: 8 additions & 13 deletions
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

Lines changed: 2 additions & 3 deletions
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

Lines changed: 2 additions & 3 deletions
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

Lines changed: 2 additions & 3 deletions
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

Lines changed: 3 additions & 4 deletions
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

Lines changed: 2 additions & 4 deletions
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

Lines changed: 2 additions & 3 deletions
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

Lines changed: 1 addition & 3 deletions
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

Lines changed: 2 additions & 3 deletions
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")

0 commit comments

Comments
 (0)