Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DO NOT REVIEW #12482

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ci/cloudbuild/builds/lib/features.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function features::libraries() {
function features::list_full() {
local feature_list
mapfile -t feature_list < <(features::libraries)
feature_list+=(experimental-opentelemetry experimental-storage-grpc grafeas)
feature_list+=(experimental-opentelemetry experimental-storage-grpc)
printf "%s\n" "${feature_list[@]}" | sort -u
}

Expand Down
2 changes: 1 addition & 1 deletion ci/cloudbuild/builds/publish-docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ io::log "bucket: gs://${docfx_bucket}"

# Upload the documents for all features, including common. We need to
# rename `experimental-opentelemetry`. Some features do not have documentation,
# such as `grafeas` and `experimental-storage-grpc`. These are harmless, as the
# such as `experimental-storage-grpc`. These are harmless, as the
# `stage_docfx()`` function skips missing directories without an error.
uploaded=(common)
uploaded+=("${FEATURE_LIST[@]/experimental-opentelemetry/opentelemetry}")
Expand Down
6 changes: 0 additions & 6 deletions cmake/GoogleCloudCppFeatures.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,6 @@ function (google_cloud_cpp_enable_deps)
if (asset IN_LIST enabled_features)
list(INSERT enabled_features 0 accesscontextmanager osconfig)
endif ()
if (binaryauthorization IN_LIST enabled_features)
list(INSERT enabled_features 0 grafeas)
endif ()
if (containeranalysis IN_LIST enabled_features)
list(INSERT enabled_features 0 grafeas)
endif ()
if (contentwarehouse IN_LIST enabled_features)
list(INSERT enabled_features 0 documentai)
endif ()
Expand Down
118 changes: 97 additions & 21 deletions cmake/GoogleCloudCppLibrary.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,101 @@
# limitations under the License.
# ~~~

# A function to add proto libraries, as defined by their protolists and
# protodeps.
#
# * library: the short name of the associated client library, e.g. `kms`.
#
# The function also respects the following boolean keyword:
#
# * EXPORT_TARGET: Export the targets. This function will install a config file
# named `google_cloud_cpp_${library}-targets.cmake`.
#
# Note that if this keyword is supplied, we will only create new targets for
# this proto **if they do not already exist**. This logic allows us to add
# common proto dependencies across multiple client libraries.
#
# For example, both `binaryauthorization` and `contentanalysis` depend on
# `grafeas`. So they use EXPORT_TARGET, to only add `grafeas_protos` if
# necessary.
function (google_cloud_cpp_add_library_protos library)
cmake_parse_arguments(_opt "EXPORT_TARGET" "" "ADDITIONAL_PROTO_LISTS"
${ARGN})

set(protos_target "google_cloud_cpp_${library}_protos")
# If this function is responsible for exporting the target, make sure the
# target has not been defined before. This simplifies the logic to compile
# protos shared across multiple client libraries.
if (_opt_EXPORT_TARGET AND TARGET ${protos_target})
message(STATUS "${protos_target} has already been defined. Skipping.")
return()
endif ()

include(CompileProtos)
google_cloud_cpp_find_proto_include_dir(PROTO_INCLUDE_DIR)
google_cloud_cpp_load_protolist(
proto_list
"${PROJECT_SOURCE_DIR}/external/googleapis/protolists/${library}.list")
if (_opt_ADDITIONAL_PROTO_LISTS)
list(APPEND proto_list "${_opt_ADDITIONAL_PROTO_LISTS}")
endif ()
google_cloud_cpp_load_protodeps(
proto_deps
"${PROJECT_SOURCE_DIR}/external/googleapis/protodeps/${library}.deps")
google_cloud_cpp_grpcpp_library(
${protos_target} # cmake-format: sort
${proto_list} PROTO_PATH_DIRECTORIES "${EXTERNAL_GOOGLEAPIS_SOURCE}"
"${PROTO_INCLUDE_DIR}")
external_googleapis_set_version_and_alias(${library}_protos)
target_link_libraries(${protos_target} PUBLIC ${proto_deps})

google_cloud_cpp_install_proto_library_protos(
"${protos_target}" "${EXTERNAL_GOOGLEAPIS_SOURCE}")
google_cloud_cpp_install_proto_library_headers("${protos_target}")

external_googleapis_install_pc("${protos_target}")

if (NOT _opt_EXPORT_TARGET)
return()
endif ()

# Export the CMake targets to make it easy to create configuration files.
install(
EXPORT google_cloud_cpp_${library}-targets
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/google_cloud_cpp_${library}"
COMPONENT google_cloud_cpp_development)

# Install the libraries and headers in the locations determined by
# GNUInstallDirs
install(
TARGETS google_cloud_cpp_${library}_protos
EXPORT google_cloud_cpp_${library}-targets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
COMPONENT google_cloud_cpp_runtime
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT google_cloud_cpp_runtime
NAMELINK_COMPONENT google_cloud_cpp_development
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT google_cloud_cpp_development)

# Create and install the CMake configuration files.
include(CMakePackageConfigHelpers)
set(GOOGLE_CLOUD_CPP_CONFIG_LIBRARY "${library}")
configure_file("${PROJECT_SOURCE_DIR}/cmake/templates/config.cmake.in"
"google_cloud_cpp_${library}-config.cmake" @ONLY)
write_basic_package_version_file(
"google_cloud_cpp_${library}-config-version.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY ExactVersion)

install(
FILES
"${CMAKE_CURRENT_BINARY_DIR}/google_cloud_cpp_${library}-config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/google_cloud_cpp_${library}-config-version.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/google_cloud_cpp_${library}"
COMPONENT google_cloud_cpp_development)
endfunction ()

# A function to add targets for GA libraries that use gRPC for transport.
#
# * library: the short name of the library, e.g. `kms`.
Expand Down Expand Up @@ -81,22 +176,8 @@ function (google_cloud_cpp_add_ga_grpc_library library display_name)
include(GoogleCloudCppCommon)

include(CompileProtos)
google_cloud_cpp_find_proto_include_dir(PROTO_INCLUDE_DIR)
google_cloud_cpp_load_protolist(
proto_list
"${PROJECT_SOURCE_DIR}/external/googleapis/protolists/${library}.list")
if (_opt_ADDITIONAL_PROTO_LISTS)
list(APPEND proto_list "${_opt_ADDITIONAL_PROTO_LISTS}")
endif ()
google_cloud_cpp_load_protodeps(
proto_deps
"${PROJECT_SOURCE_DIR}/external/googleapis/protodeps/${library}.deps")
google_cloud_cpp_grpcpp_library(
${protos_target} # cmake-format: sort
${proto_list} PROTO_PATH_DIRECTORIES "${EXTERNAL_GOOGLEAPIS_SOURCE}"
"${PROTO_INCLUDE_DIR}")
external_googleapis_set_version_and_alias(${library}_protos)
target_link_libraries(${protos_target} PUBLIC ${proto_deps})
google_cloud_cpp_add_library_protos(${library} ADDITIONAL_PROTO_LISTS
${_opt_ADDITIONAL_PROTO_LISTS})

# We used to offer the proto library by another name. Maintain backwards
# compatibility by providing an interface library with that name. Also make
Expand Down Expand Up @@ -186,9 +267,6 @@ function (google_cloud_cpp_add_ga_grpc_library library display_name)
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT google_cloud_cpp_development)

google_cloud_cpp_install_proto_library_protos(
"${protos_target}" "${EXTERNAL_GOOGLEAPIS_SOURCE}")
google_cloud_cpp_install_proto_library_headers("${protos_target}")
google_cloud_cpp_install_headers("${library_target}"
"include/google/cloud/${library}")
google_cloud_cpp_install_headers("${mocks_target}"
Expand All @@ -214,8 +292,6 @@ function (google_cloud_cpp_add_ga_grpc_library library display_name)
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${library_target}"
COMPONENT google_cloud_cpp_development)

external_googleapis_install_pc("${protos_target}")

# ${library_alias} must be defined before we can add the samples.
if (BUILD_TESTING AND GOOGLE_CLOUD_CPP_ENABLE_CXX_EXCEPTIONS)
foreach (dir IN LISTS GOOGLE_CLOUD_CPP_SERVICE_DIRS)
Expand Down
22 changes: 22 additions & 0 deletions cmake/templates/config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright 2023 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

include(CMakeFindDependencyMacro)
# google_cloud_cpp_googleapis finds both gRPC and Protobuf, no need to load them here.
find_dependency(google_cloud_cpp_googleapis)
find_dependency(google_cloud_cpp_common)
find_dependency(google_cloud_cpp_grpc_utils)
find_dependency(absl)

include("${CMAKE_CURRENT_LIST_DIR}/google_cloud_cpp_@GOOGLE_CLOUD_CPP_CONFIG_LIBRARY@-targets.cmake")
3 changes: 3 additions & 0 deletions google/cloud/binaryauthorization/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ set(GOOGLE_CLOUD_CPP_SERVICE_DIRS "" "v1/")
set(GOOGLE_CLOUD_CPP_DOXYGEN_EXTRA_INCLUDES
"${PROJECT_BINARY_DIR}/google/cloud/grafeas")

# There is a cross dependency on grafeas.
google_cloud_cpp_add_library_protos(grafeas EXPORT_TARGET)

google_cloud_cpp_add_ga_grpc_library(binaryauthorization
"Binary Authorization API")

Expand Down
3 changes: 3 additions & 0 deletions google/cloud/containeranalysis/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ set(GOOGLE_CLOUD_CPP_SERVICE_DIRS "" "v1/")
set(GOOGLE_CLOUD_CPP_DOXYGEN_EXTRA_INCLUDES
"${PROJECT_BINARY_DIR}/google/cloud/grafeas")

# There is a cross dependency on grafeas.
google_cloud_cpp_add_library_protos(grafeas EXPORT_TARGET)

google_cloud_cpp_add_ga_grpc_library(containeranalysis "Container Analysis API")

if (BUILD_TESTING AND GOOGLE_CLOUD_CPP_ENABLE_CXX_EXCEPTIONS)
Expand Down
71 changes: 2 additions & 69 deletions google/cloud/grafeas/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,73 +14,6 @@
# limitations under the License.
# ~~~

include(GoogleapisConfig)
include(GoogleCloudCppLibrary)

include(GoogleCloudCppCommon)

include(CompileProtos)
google_cloud_cpp_find_proto_include_dir(PROTO_INCLUDE_DIR)
google_cloud_cpp_load_protolist(
grafeas_list
"${PROJECT_SOURCE_DIR}/external/googleapis/protolists/grafeas.list")
google_cloud_cpp_load_protodeps(
grafeas_deps
"${PROJECT_SOURCE_DIR}/external/googleapis/protodeps/grafeas.deps")
google_cloud_cpp_grpcpp_library(
google_cloud_cpp_grafeas_protos ${grafeas_list} PROTO_PATH_DIRECTORIES
"${EXTERNAL_GOOGLEAPIS_SOURCE}" "${PROTO_INCLUDE_DIR}")
external_googleapis_set_version_and_alias(grafeas_protos)
target_link_libraries(google_cloud_cpp_grafeas_protos PUBLIC ${grafeas_deps})

# Get the destination directories based on the GNU recommendations.
include(GNUInstallDirs)

# Export the CMake targets to make it easy to create configuration files.
install(
EXPORT google_cloud_cpp_grafeas-targets
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/google_cloud_cpp_grafeas"
COMPONENT google_cloud_cpp_development)

# Install the libraries and headers in the locations determined by
# GNUInstallDirs
install(
TARGETS google_cloud_cpp_grafeas_protos
EXPORT google_cloud_cpp_grafeas-targets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
COMPONENT google_cloud_cpp_runtime
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT google_cloud_cpp_runtime
NAMELINK_SKIP
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT google_cloud_cpp_development)
# With CMake-3.12 and higher we could avoid this separate command (and the
# duplication).
install(
TARGETS google_cloud_cpp_grafeas_protos
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT google_cloud_cpp_development
NAMELINK_ONLY
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT google_cloud_cpp_development)

google_cloud_cpp_install_proto_library_protos("google_cloud_cpp_grafeas_protos"
"${EXTERNAL_GOOGLEAPIS_SOURCE}")
google_cloud_cpp_install_proto_library_headers(
"google_cloud_cpp_grafeas_protos")

# Create and install the CMake configuration files.
include(CMakePackageConfigHelpers)
configure_file("config.cmake.in" "google_cloud_cpp_grafeas-config.cmake" @ONLY)
write_basic_package_version_file(
"google_cloud_cpp_grafeas-config-version.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY ExactVersion)

install(
FILES
"${CMAKE_CURRENT_BINARY_DIR}/google_cloud_cpp_grafeas-config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/google_cloud_cpp_grafeas-config-version.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/google_cloud_cpp_grafeas"
COMPONENT google_cloud_cpp_development)

external_googleapis_install_pc("google_cloud_cpp_grafeas_protos")
google_cloud_cpp_add_library_protos(grafeas EXPORT_TARGET)