Skip to content

Commit 0640b0d

Browse files
authored
cleanup(cmake): REGAPIC helper (#14894)
1 parent 6b60e33 commit 0640b0d

File tree

9 files changed

+21
-395
lines changed

9 files changed

+21
-395
lines changed

cmake/GoogleCloudCppLibrary.cmake

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ function (google_cloud_cpp_add_library_protos library)
108108
# Create and install the CMake configuration files.
109109
include(CMakePackageConfigHelpers)
110110
set(GOOGLE_CLOUD_CPP_CONFIG_LIBRARY "${library_target}")
111+
set(GOOGLE_CLOUD_CPP_TRANSPORT "grpc_utils")
111112
configure_file("${PROJECT_SOURCE_DIR}/cmake/templates/config.cmake.in"
112113
"${library_target}-config.cmake" @ONLY)
113114
write_basic_package_version_file(
@@ -148,7 +149,7 @@ endfunction ()
148149
function (google_cloud_cpp_add_gapic_library library display_name)
149150
cmake_parse_arguments(
150151
_opt
151-
"EXPERIMENTAL;TRANSITION"
152+
"EXPERIMENTAL;TRANSITION;REST_TRANSPORT"
152153
""
153154
"ADDITIONAL_PROTO_LISTS;BACKWARDS_COMPAT_PROTO_TARGETS;CROSS_LIB_DEPS;SERVICE_DIRS;SHARED_PROTO_DEPS"
154155
${ARGN})
@@ -167,6 +168,10 @@ function (google_cloud_cpp_add_gapic_library library display_name)
167168
if (_opt_EXPERIMENTAL)
168169
set(library_alias "${experimental_alias}")
169170
endif ()
171+
set(transport "grpc_utils")
172+
if (_opt_REST_TRANSPORT)
173+
set(transport "rest_protobuf_internal")
174+
endif ()
170175

171176
include(GoogleapisConfig)
172177
set(DOXYGEN_PROJECT_NAME "${display_name} C++ Client")
@@ -241,7 +246,7 @@ function (google_cloud_cpp_add_gapic_library library display_name)
241246
$<INSTALL_INTERFACE:include>)
242247
target_link_libraries(
243248
${library_target}
244-
PUBLIC google-cloud-cpp::grpc_utils google-cloud-cpp::common
249+
PUBLIC google-cloud-cpp::${transport} google-cloud-cpp::common
245250
google-cloud-cpp::${library}_protos ${shared_proto_dep_targets})
246251
google_cloud_cpp_add_common_options(${library_target})
247252
set_target_properties(
@@ -300,13 +305,14 @@ function (google_cloud_cpp_add_gapic_library library display_name)
300305
${library}
301306
"The ${display_name} C++ Client Library"
302307
"Provides C++ APIs to use the ${display_name}"
303-
"google_cloud_cpp_grpc_utils"
308+
"google_cloud_cpp_${transport}"
304309
"${protos_target}"
305310
${shared_proto_dep_targets})
306311

307312
# Create and install the CMake configuration files.
308313
include(CMakePackageConfigHelpers)
309314
set(GOOGLE_CLOUD_CPP_CONFIG_LIBRARY "${library_target}")
315+
set(GOOGLE_CLOUD_CPP_TRANSPORT "${transport}")
310316
foreach (lib IN LISTS _opt_CROSS_LIB_DEPS _opt_SHARED_PROTO_DEPS)
311317
list(APPEND find_dependencies
312318
"find_dependency(google_cloud_cpp_${lib})")

cmake/templates/config.cmake.in

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,7 @@
1313
# limitations under the License.
1414

1515
include(CMakeFindDependencyMacro)
16-
# google_cloud_cpp_googleapis finds both gRPC and Protobuf, no need to load them here.
17-
find_dependency(google_cloud_cpp_googleapis)
18-
find_dependency(google_cloud_cpp_common)
19-
find_dependency(google_cloud_cpp_grpc_utils)
20-
find_dependency(absl)
16+
find_dependency(google_cloud_cpp_@GOOGLE_CLOUD_CPP_TRANSPORT@)
2117
@GOOGLE_CLOUD_CPP_ADDITIONAL_FIND_DEPENDENCIES@
2218

2319
include("${CMAKE_CURRENT_LIST_DIR}/@[email protected]")

google/cloud/bigquerycontrol/CMakeLists.txt

Lines changed: 3 additions & 175 deletions
Original file line numberDiff line numberDiff line change
@@ -16,172 +16,9 @@
1616

1717
include(GoogleCloudCppLibrary)
1818

19-
include(GoogleapisConfig)
20-
set(DOXYGEN_PROJECT_NAME "Cloud BigQuery Control API C++ Client")
21-
set(DOXYGEN_PROJECT_BRIEF
22-
"A C++ Client Library for the Cloud BigQuery Control API")
23-
set(DOXYGEN_PROJECT_NUMBER "${PROJECT_VERSION} (Experimental)")
24-
set(DOXYGEN_EXCLUDE_SYMBOLS "internal")
25-
set(DOXYGEN_EXAMPLE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/quickstart)
26-
27-
unset(mocks_globs)
28-
unset(source_globs)
29-
set(service_dirs "v2/")
30-
foreach (dir IN LISTS service_dirs)
31-
string(REPLACE "/" "_" ns "${dir}")
32-
list(APPEND source_globs "${dir}*.h" "${dir}internal/*.h"
33-
"${dir}internal/*_sources.cc")
34-
list(APPEND mocks_globs "${dir}mocks/*.h")
35-
list(APPEND DOXYGEN_EXAMPLE_PATH
36-
"${CMAKE_CURRENT_SOURCE_DIR}/${dir}samples")
37-
list(APPEND DOXYGEN_EXCLUDE_SYMBOLS "bigquerycontrol_${ns}internal")
38-
endforeach ()
39-
40-
include(GoogleCloudCppDoxygen)
41-
google_cloud_cpp_doxygen_targets("bigquerycontrol" DEPENDS cloud-docs
42-
google-cloud-cpp::bigquery_v2_protos)
43-
44-
include(GoogleCloudCppCommon)
45-
46-
include(CompileProtos)
47-
google_cloud_cpp_find_proto_include_dir(PROTO_INCLUDE_DIR)
48-
google_cloud_cpp_load_protolist(
49-
proto_list
50-
"${PROJECT_SOURCE_DIR}/external/googleapis/protolists/bigquerycontrol.list")
51-
google_cloud_cpp_load_protodeps(
52-
proto_deps
53-
"${PROJECT_SOURCE_DIR}/external/googleapis/protodeps/bigquerycontrol.deps")
54-
google_cloud_cpp_proto_library(
55-
google_cloud_cpp_bigquery_v2_protos # cmake-format: sort
56-
${proto_list} PROTO_PATH_DIRECTORIES "${EXTERNAL_GOOGLEAPIS_SOURCE}"
57-
"${PROTO_INCLUDE_DIR}")
58-
external_googleapis_set_version_and_alias(bigquery_v2_protos)
59-
target_link_libraries(google_cloud_cpp_bigquery_v2_protos PUBLIC ${proto_deps})
60-
61-
file(
62-
GLOB source_files
63-
RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
64-
${source_globs})
65-
list(SORT source_files)
66-
add_library(google_cloud_cpp_bigquerycontrol ${source_files})
67-
target_include_directories(
68-
google_cloud_cpp_bigquerycontrol
69-
PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
70-
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}>
71-
$<INSTALL_INTERFACE:include>)
72-
target_link_libraries(
73-
google_cloud_cpp_bigquerycontrol
74-
PUBLIC google-cloud-cpp::grpc_utils
75-
google-cloud-cpp::common
76-
google-cloud-cpp::rest_internal
77-
google-cloud-cpp::rest_protobuf_internal
78-
google-cloud-cpp::bigquery_v2_protos)
79-
google_cloud_cpp_add_common_options(google_cloud_cpp_bigquerycontrol)
80-
set_target_properties(
81-
google_cloud_cpp_bigquerycontrol
82-
PROPERTIES EXPORT_NAME google-cloud-cpp::experimental-bigquerycontrol
83-
VERSION "${PROJECT_VERSION}"
84-
SOVERSION "${PROJECT_VERSION_MAJOR}")
85-
target_compile_options(google_cloud_cpp_bigquerycontrol
86-
PUBLIC ${GOOGLE_CLOUD_CPP_EXCEPTIONS_FLAG})
87-
88-
add_library(google-cloud-cpp::experimental-bigquerycontrol ALIAS
89-
google_cloud_cpp_bigquerycontrol)
90-
91-
# Get the destination directories based on the GNU recommendations.
92-
include(GNUInstallDirs)
93-
94-
# Export the CMake targets to make it easy to create configuration files.
95-
install(
96-
EXPORT google_cloud_cpp_bigquerycontrol-targets
97-
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/google_cloud_cpp_bigquerycontrol"
98-
COMPONENT google_cloud_cpp_development)
99-
100-
# Install the libraries and headers in the locations determined by
101-
# GNUInstallDirs
102-
install(
103-
TARGETS google_cloud_cpp_bigquerycontrol google_cloud_cpp_bigquery_v2_protos
104-
EXPORT google_cloud_cpp_bigquerycontrol-targets
105-
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
106-
COMPONENT google_cloud_cpp_runtime
107-
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
108-
COMPONENT google_cloud_cpp_runtime
109-
NAMELINK_COMPONENT google_cloud_cpp_development
110-
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
111-
COMPONENT google_cloud_cpp_development)
112-
113-
google_cloud_cpp_install_proto_library_protos(
114-
"google_cloud_cpp_bigquery_v2_protos" "${EXTERNAL_GOOGLEAPIS_SOURCE}")
115-
google_cloud_cpp_install_proto_library_headers(
116-
"google_cloud_cpp_bigquery_v2_protos")
117-
google_cloud_cpp_install_headers("google_cloud_cpp_bigquerycontrol"
118-
"include/google/cloud/bigquerycontrol")
119-
120-
google_cloud_cpp_add_pkgconfig(
121-
bigquerycontrol
122-
"The Cloud BigQuery Control API C++ Client Library"
123-
"Provides C++ APIs to use the Cloud BigQuery Control API."
124-
"google_cloud_cpp_rest_internal"
125-
"google_cloud_cpp_rest_protobuf_internal"
126-
"google_cloud_cpp_grpc_utils"
127-
"google_cloud_cpp_common"
128-
"google_cloud_cpp_bigquery_v2_protos")
129-
130-
# Create and install the CMake configuration files.
131-
include(CMakePackageConfigHelpers)
132-
configure_file("config.cmake.in"
133-
"google_cloud_cpp_bigquerycontrol-config.cmake" @ONLY)
134-
write_basic_package_version_file(
135-
"google_cloud_cpp_bigquerycontrol-config-version.cmake"
136-
VERSION ${PROJECT_VERSION}
137-
COMPATIBILITY ExactVersion)
138-
139-
install(
140-
FILES
141-
"${CMAKE_CURRENT_BINARY_DIR}/google_cloud_cpp_bigquerycontrol-config.cmake"
142-
"${CMAKE_CURRENT_BINARY_DIR}/google_cloud_cpp_bigquerycontrol-config-version.cmake"
143-
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/google_cloud_cpp_bigquerycontrol"
144-
COMPONENT google_cloud_cpp_development)
145-
146-
external_googleapis_install_pc("google_cloud_cpp_bigquery_v2_protos")
147-
148-
if (GOOGLE_CLOUD_CPP_WITH_MOCKS)
149-
# Create a header-only library for the mocks. We use a CMake `INTERFACE`
150-
# library for these, a regular library would not work on macOS (where the
151-
# library needs at least one .o file). Unfortunately INTERFACE libraries are
152-
# a bit weird in that they need absolute paths for their sources.
153-
file(
154-
GLOB relative_mock_files
155-
RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
156-
${mocks_globs})
157-
list(SORT relative_mock_files)
158-
set(mock_files)
159-
foreach (file IN LISTS relative_mock_files)
160-
# We use a generator expression per the recommendation in:
161-
# https://stackoverflow.com/a/62465051
162-
list(APPEND mock_files
163-
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/${file}>")
164-
endforeach ()
165-
add_library(google_cloud_cpp_bigquerycontrol_mocks INTERFACE)
166-
target_sources(google_cloud_cpp_bigquerycontrol_mocks
167-
INTERFACE ${mock_files})
168-
target_link_libraries(
169-
google_cloud_cpp_bigquerycontrol_mocks
170-
INTERFACE google-cloud-cpp::experimental-bigquerycontrol GTest::gmock
171-
GTest::gtest)
172-
set_target_properties(
173-
google_cloud_cpp_bigquerycontrol_mocks
174-
PROPERTIES EXPORT_NAME google-cloud-cpp::bigquerycontrol_mocks)
175-
target_include_directories(
176-
google_cloud_cpp_bigquerycontrol_mocks
177-
INTERFACE $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
178-
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}>
179-
$<INSTALL_INTERFACE:include>)
180-
target_compile_options(google_cloud_cpp_bigquerycontrol_mocks
181-
INTERFACE ${GOOGLE_CLOUD_CPP_EXCEPTIONS_FLAG})
182-
183-
google_cloud_cpp_install_mocks(bigquerycontrol "Cloud BigQuery V2 API")
184-
endif ()
19+
google_cloud_cpp_add_gapic_library(
20+
bigquerycontrol "Cloud BigQuery Control API" EXPERIMENTAL REST_TRANSPORT
21+
SERVICE_DIRS "v2/")
18522

18623
if (BUILD_TESTING AND GOOGLE_CLOUD_CPP_ENABLE_CXX_EXCEPTIONS)
18724
add_executable(bigquerycontrol_quickstart "quickstart/quickstart.cc")
@@ -198,12 +35,3 @@ if (BUILD_TESTING AND GOOGLE_CLOUD_CPP_ENABLE_CXX_EXCEPTIONS)
19835
endif ()
19936

20037
add_subdirectory(integration_tests)
201-
202-
# google-cloud-cpp::experimental-bigquerycontrol must be defined before we can
203-
# add the samples.
204-
foreach (dir IN LISTS service_dirs)
205-
if (BUILD_TESTING AND GOOGLE_CLOUD_CPP_ENABLE_CXX_EXCEPTIONS)
206-
google_cloud_cpp_add_samples_relative("experimental-bigquerycontrol"
207-
"${dir}samples/")
208-
endif ()
209-
endforeach ()

google/cloud/bigquerycontrol/config.cmake.in

Lines changed: 0 additions & 24 deletions
This file was deleted.

google/cloud/google_cloud_cpp_rest_protobuf_internal.cmake

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ google_cloud_cpp_add_pkgconfig(
7878
rest_protobuf_internal
7979
"REST/Protobuf Utilities for the Google Cloud C++ Client Library"
8080
"Provides REST and Protobuf Utilities for the Google Cloud C++ Client Library."
81-
"google_cloud_cpp_common")
81+
"google_cloud_cpp_common"
82+
"google_cloud_cpp_grpc_utils"
83+
"google_cloud_cpp_rest_internal")
8284

8385
# Create and install the CMake configuration files.
8486
configure_file("config-rest-protobuf.cmake.in"

google/cloud/pubsub/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,7 @@ google_cloud_cpp_add_pkgconfig(
348348
# Create and install the CMake configuration files.
349349
include(CMakePackageConfigHelpers)
350350
set(GOOGLE_CLOUD_CPP_CONFIG_LIBRARY "pubsub")
351+
set(GOOGLE_CLOUD_CPP_TRANSPORT "grpc_utils")
351352
configure_file("${PROJECT_SOURCE_DIR}/cmake/templates/config.cmake.in"
352353
"google_cloud_cpp_pubsub-config.cmake" @ONLY)
353354
write_basic_package_version_file(

google/cloud/spanner/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@ google_cloud_cpp_add_pkgconfig(
334334
# Create and install the CMake configuration files.
335335
include(CMakePackageConfigHelpers)
336336
set(GOOGLE_CLOUD_CPP_CONFIG_LIBRARY "spanner")
337+
set(GOOGLE_CLOUD_CPP_TRANSPORT "grpc_utils")
337338
configure_file("${PROJECT_SOURCE_DIR}/cmake/templates/config.cmake.in"
338339
"google_cloud_cpp_spanner-config.cmake" @ONLY)
339340
write_basic_package_version_file(

0 commit comments

Comments
 (0)