Skip to content

Commit e3c2d59

Browse files
authored
cleanup(cmake): re-support transition libraries (#12753)
1 parent e68c72e commit e3c2d59

3 files changed

Lines changed: 23 additions & 16 deletions

File tree

cmake/GoogleCloudCppLibrary.cmake

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,16 +153,24 @@ endfunction ()
153153
function (google_cloud_cpp_add_ga_grpc_library library display_name)
154154
cmake_parse_arguments(
155155
_opt
156-
"EXPERIMENTAL"
156+
"EXPERIMENTAL;TRANSITION"
157157
""
158158
"ADDITIONAL_PROTO_LISTS;BACKWARDS_COMPAT_PROTO_TARGETS;CROSS_LIB_DEPS;SHARED_PROTO_DEPS"
159159
${ARGN})
160+
if (_opt_EXPERIMENTAL AND _opt_TRANSITION)
161+
message(
162+
FATAL_ERROR
163+
"EXPERIMENTAL and TRANSITION keywords are mutually exclusive. Only supply one."
164+
)
165+
endif ()
166+
160167
set(library_target "google_cloud_cpp_${library}")
161168
set(mocks_target "google_cloud_cpp_${library}_mocks")
162169
set(protos_target "google_cloud_cpp_${library}_protos")
163170
set(library_alias "google-cloud-cpp::${library}")
171+
set(experimental_alias "google-cloud-cpp::experimental-${library}")
164172
if (_opt_EXPERIMENTAL)
165-
set(library_alias "google-cloud-cpp::experimental-${library}")
173+
set(library_alias "${experimental_alias}")
166174
endif ()
167175

168176
include(GoogleapisConfig)
@@ -323,6 +331,14 @@ function (google_cloud_cpp_add_ga_grpc_library library display_name)
323331
endforeach ()
324332
string(JOIN "\n" GOOGLE_CLOUD_CPP_ADDITIONAL_FIND_DEPENDENCIES
325333
${find_dependencies})
334+
if (_opt_TRANSITION)
335+
set(cmake_config_transition_lines
336+
"if (NOT TARGET ${experimental_alias})"
337+
" add_library(${experimental_alias} ALIAS ${library_alias})"
338+
"endif ()")
339+
string(JOIN "\n" GOOGLE_CLOUD_CPP_CONFIG_TRANSITION_TARGETS
340+
${cmake_config_transition_lines})
341+
endif ()
326342
configure_file("${PROJECT_SOURCE_DIR}/cmake/templates/config.cmake.in"
327343
"${library_target}-config.cmake" @ONLY)
328344
write_basic_package_version_file(

cmake/templates/config.cmake.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,5 @@ find_dependency(absl)
2121
@GOOGLE_CLOUD_CPP_ADDITIONAL_FIND_DEPENDENCIES@
2222

2323
include("${CMAKE_CURRENT_LIST_DIR}/@GOOGLE_CLOUD_CPP_CONFIG_LIBRARY@-targets.cmake")
24+
25+
@GOOGLE_CLOUD_CPP_CONFIG_TRANSITION_TARGETS@

doc/contributor/howto-guide-declare-a-library-ga.md

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -86,21 +86,10 @@ for lib in "${ga[@]}"; do sed -i 's/^Please note that the Google Cloud C/While t
8686

8787
### `google/cloud/${library}/CMakeLists.txt`:
8888

89-
Remove the EXPERIMENTAL keyword from the library definition.
89+
Update the CMake library targets.
9090

9191
```shell
92-
for lib in "${ga[@]}"; do sed -i 's/EXPERIMENTAL//' google/cloud/${lib}/CMakeLists.txt; done
93-
```
94-
95-
### `google/cloud/${library}/config.cmake.in`:
96-
97-
Add an alias to help transition from `google-cloud-cpp::experimental-${library}`
98-
to `google-cloud-cpp::${library}`:
99-
100-
```shell
101-
for lib in "${ga[@]}"; do
102-
printf "\nif (NOT TARGET google-cloud-cpp::experimental-%s)\n add_library(google-cloud-cpp::experimental-%s ALIAS google-cloud-cpp::%s)\nendif ()\n" "${lib}" "${lib}" "${lib}" >>google/cloud/${lib}/config.cmake.in
103-
done
92+
for lib in "${ga[@]}"; do sed -i 's/EXPERIMENTAL/TRANSITION/' google/cloud/${lib}/CMakeLists.txt; done
10493
```
10594

10695
## Reference the GA targets in the quickstarts
@@ -128,5 +117,5 @@ In the following release, move the libraries from
128117
Then remove the CMake aliases.
129118

130119
```shell
131-
for lib in "${ga[@]}"; do sed -i '1,/-targets.cmake")/!d' google/cloud/${lib}/config.cmake.in; done
120+
for lib in "${ga[@]}"; do sed -i 's/TRANSITION//' google/cloud/${lib}/CMakeLists.txt; done
132121
```

0 commit comments

Comments
 (0)