From eab5cb57dd38531023b1e7e7a529882c268d1333 Mon Sep 17 00:00:00 2001 From: Carlos O'Ryan Date: Fri, 28 Jun 2019 15:01:33 -0400 Subject: [PATCH 01/34] Initial set of files. The make install target is not working for .proto files, but otherwise it seems to work. --- .cmake-format.py | 42 ++++ .editorconfig | 22 ++ .gitignore | 25 +++ CMakeLists.txt | 371 ++++++++++++++++++++++++++++++++ CONTRIBUTING.md | 55 +++++ LICENSE | 201 +++++++++++++++++ README.md | 68 ++++++ cmake/CompileProtos.cmake | 286 ++++++++++++++++++++++++ cmake/FindProtobufTargets.cmake | 207 ++++++++++++++++++ cmake/FindgRPC.cmake | 343 +++++++++++++++++++++++++++++ cmake/SelectMSVCRuntime.cmake | 46 ++++ cmake/config-version.cmake.in | 35 +++ cmake/config.cmake.in | 36 ++++ cmake/config.pc.in | 26 +++ 14 files changed, 1763 insertions(+) create mode 100644 .cmake-format.py create mode 100644 .editorconfig create mode 100644 .gitignore create mode 100644 CMakeLists.txt create mode 100644 CONTRIBUTING.md create mode 100644 LICENSE create mode 100644 README.md create mode 100644 cmake/CompileProtos.cmake create mode 100644 cmake/FindProtobufTargets.cmake create mode 100644 cmake/FindgRPC.cmake create mode 100644 cmake/SelectMSVCRuntime.cmake create mode 100644 cmake/config-version.cmake.in create mode 100644 cmake/config.cmake.in create mode 100644 cmake/config.pc.in diff --git a/.cmake-format.py b/.cmake-format.py new file mode 100644 index 000000000..f6ceafc1a --- /dev/null +++ b/.cmake-format.py @@ -0,0 +1,42 @@ +# Copyright 2019 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 +# +# http://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. + +tab_size = 4 +separate_ctrl_name_with_space = True + +additional_commands = { + "externalproject_add": { + "flags": [ + ], + "kwargs": { + "BUILD_COMMAND": "+", + "BUILD_BYPRODUCTS": "+", + "CMAKE_ARGS": "+", + "COMMAND": "+", + "CONFIGURE_COMMAND": "+", + "DEPENDS": "+", + "DOWNLOAD_COMMAND": "+", + "EXCLUDE_FROM_ALL": 1, + "INSTALL_COMMAND": "+", + "INSTALL_DIR": 1, + "LOG_BUILD": 1, + "LOG_CONFIGURE": 1, + "LOG_DOWNLOAD": 1, + "LOG_INSTALL": 1, + "PREFIX": 1, + "URL": 1, + "URL_HASH": 1, + } + } +} diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 000000000..0983572c6 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,22 @@ +# http://editorconfig.org + +root = true + +[*] +charset = utf-8 +indent_style = space + +[BUILD] +indent_size = 4 + +[CMakeLists.*] +indent_size = 4 + +[*.h,*.cc] +indent_size = 2 + +[*.md] +indent_size = 2 + +[*.sh] +indent_size = 2 diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..765f3e124 --- /dev/null +++ b/.gitignore @@ -0,0 +1,25 @@ +# Common build output directory names +.build/ +_build/ +build-output/ +cmake-out/ + +# Common bazel output directories +bazel-* + +# Backup files for Emacs +*~ + +# Ignore IDEA / IntelliJ files +.idea/ +cmake-build-*/ + +# This is a staging directory used to upload the documents to gihub.io +github-io-staging/ + +# Ignore Visual Studio Code files +.vsbuild/ +.vscode/ + +google/cloud/storage/testbench/__pycache__/ +google/cloud/storage/testbench/*.pyc diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 000000000..edc8f2320 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,371 @@ +# ~~~ +# Copyright 2019 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 +# +# http://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. +# ~~~ + +cmake_minimum_required(VERSION 3.5) + +# Define the project name and where to report bugs. +set(PACKAGE_BUGREPORT "https://github.com/googleapis/google-cloud-cpp/issues") +project(googleapis-cpp-protos CXX C) + +set(GOOGLEAPIS_CPP_PROTOS_VERSION_MAJOR 0) +set(GOOGLEAPIS_CPP_PROTOS_VERSION_MINOR 2) +set(GOOGLEAPIS_CPP_PROTOS_VERSION_PATCH 0) + +string(CONCAT GOOGLE_APIS_CPP_PROTOS_VERSION + "${GOOGLEAPIS_CPP_PROTOS_VERSION_MAJOR}" + "." + "${GOOGLEAPIS_CPP_PROTOS_VERSION_MINOR}" + "." + "${GOOGLEAPIS_CPP_PROTOS_VERSION_PATCH}") + +# Configure the compiler options, we will be using C++11 features. +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +# Give application developers a hook to configure the version and hash +# downloaded from GitHub. +set( + GOOGLE_CLOUD_CPP_GOOGLEAPIS_URL + "https://github.com/googleapis/googleapis/archive/a8ee1416f4c588f2ab92da72e7c1f588c784d3e6.tar.gz" + ) +set(GOOGLE_CLOUD_CPP_GOOGLEAPIS_SHA256 + "6b8a9b2bcb4476e9a5a9872869996f0d639c8d5df76dd8a893e79201f211b1cf") + +include(ExternalProject) +externalproject_add(googleapis_download + EXCLUDE_FROM_ALL ON + PREFIX "${CMAKE_BINARY_DIR}/external/googleapis" + URL ${GOOGLE_CLOUD_CPP_GOOGLEAPIS_URL} + URL_HASH SHA256=${GOOGLE_CLOUD_CPP_GOOGLEAPIS_SHA256} + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + INSTALL_COMMAND "" + LOG_DOWNLOAD OFF) +externalproject_get_property(googleapis_download SOURCE_DIR) +set(GOOGLEAPIS_CPP_SOURCE "${SOURCE_DIR}") + +list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake") +find_package(ProtobufTargets REQUIRED) +find_package(gRPC REQUIRED) + +# Sometimes (this happens often with vcpkg) protobuf is installed in a non- +# standard directory. We need to find out where, and then add that directory to +# the search path for protos. +find_path(PROTO_INCLUDE_DIR google/protobuf/descriptor.proto) +if (PROTO_INCLUDE_DIR) + list(INSERT PROTOBUF_IMPORT_DIRS 0 "${PROTO_INCLUDE_DIR}") +endif () + +add_library(googleapis_cpp_common_flags INTERFACE) + +include(SelectMSVCRuntime) + +# Include the functions to compile proto files. +include(CompileProtos) + +google_cloud_cpp_add_protos_property() + +function (googleapis_cpp_set_version_and_alias short_name) + add_dependencies("googleapis_cpp_${short_name}" googleapis_download) + set_target_properties("googleapis_cpp_${short_name}" + PROPERTIES VERSION + "${GOOGLE_APIS_CPP_PROTOS_VERSION}" + SOVERSION + ${GOOGLEAPIS_CPP_PROTOS_VERSION_MAJOR}) + add_library("googleapis-c++::${short_name}" ALIAS + "googleapis_cpp_${short_name}") +endfunction () + +google_cloud_cpp_grpcpp_library(googleapis_cpp_api_http_protos + "${GOOGLEAPIS_CPP_SOURCE}/google/api/http.proto" + PROTO_PATH_DIRECTORIES + "${GOOGLEAPIS_CPP_SOURCE}" + "${PROTO_INCLUDE_DIR}") +googleapis_cpp_set_version_and_alias(api_http_protos) +target_link_libraries(googleapis_cpp_api_http_protos + PRIVATE googleapis_cpp_common_flags) + +google_cloud_cpp_grpcpp_library( + googleapis_cpp_api_annotations_protos + "${GOOGLEAPIS_CPP_SOURCE}/google/api/annotations.proto" + PROTO_PATH_DIRECTORIES + "${GOOGLEAPIS_CPP_SOURCE}" + "${PROTO_INCLUDE_DIR}") +googleapis_cpp_set_version_and_alias(api_annotations_protos) +target_link_libraries(googleapis_cpp_api_annotations_protos + PUBLIC googleapis-c++::api_http_protos + PRIVATE googleapis_cpp_common_flags) + +google_cloud_cpp_grpcpp_library(googleapis_cpp_api_auth_protos + "${GOOGLEAPIS_CPP_SOURCE}/google/api/auth.proto" + PROTO_PATH_DIRECTORIES + "${GOOGLEAPIS_CPP_SOURCE}" + "${PROTO_INCLUDE_DIR}") +googleapis_cpp_set_version_and_alias(api_auth_protos) +target_link_libraries(googleapis_cpp_api_auth_protos + PUBLIC googleapis-c++::api_annotations_protos + PRIVATE googleapis_cpp_common_flags) + +google_cloud_cpp_grpcpp_library( + googleapis_cpp_api_resource_protos + "${GOOGLEAPIS_CPP_SOURCE}/google/api/resource.proto" + PROTO_PATH_DIRECTORIES + "${GOOGLEAPIS_CPP_SOURCE}" + "${PROTO_INCLUDE_DIR}") +googleapis_cpp_set_version_and_alias(api_resource_protos) +target_link_libraries(googleapis_cpp_api_resource_protos + PRIVATE googleapis_cpp_common_flags) + +google_cloud_cpp_grpcpp_library( + googleapis_cpp_type_expr_protos + "${GOOGLEAPIS_CPP_SOURCE}/google/type/expr.proto" + PROTO_PATH_DIRECTORIES + "${GOOGLEAPIS_CPP_SOURCE}" + "${PROTO_INCLUDE_DIR}") +googleapis_cpp_set_version_and_alias(type_expr_protos) +target_link_libraries(googleapis_cpp_type_expr_protos + PRIVATE googleapis_cpp_common_flags) + +google_cloud_cpp_grpcpp_library( + googleapis_cpp_rpc_error_details_protos + "${GOOGLEAPIS_CPP_SOURCE}/google/rpc/error_details.proto" + PROTO_PATH_DIRECTORIES + "${GOOGLEAPIS_CPP_SOURCE}" + "${PROTO_INCLUDE_DIR}") +googleapis_cpp_set_version_and_alias(rpc_error_details_protos) +target_link_libraries(googleapis_cpp_rpc_error_details_protos + PRIVATE googleapis_cpp_common_flags) + +google_cloud_cpp_grpcpp_library( + googleapis_cpp_rpc_status_protos + "${GOOGLEAPIS_CPP_SOURCE}/google/rpc/status.proto" + PROTO_PATH_DIRECTORIES + "${GOOGLEAPIS_CPP_SOURCE}" + "${PROTO_INCLUDE_DIR}") +googleapis_cpp_set_version_and_alias(rpc_status_protos) +target_link_libraries(googleapis_cpp_rpc_status_protos + PUBLIC googleapis-c++::rpc_error_details_protos + PRIVATE googleapis_cpp_common_flags) + +google_cloud_cpp_grpcpp_library( + googleapis_cpp_iam_v1_policy_protos + "${GOOGLEAPIS_CPP_SOURCE}/google/iam/v1/policy.proto" + PROTO_PATH_DIRECTORIES + "${GOOGLEAPIS_CPP_SOURCE}" + "${PROTO_INCLUDE_DIR}") +googleapis_cpp_set_version_and_alias(iam_v1_policy_protos) +target_link_libraries(googleapis_cpp_iam_v1_policy_protos + PUBLIC googleapis-c++::api_annotations_protos + googleapis-c++::api_resource_protos + googleapis-c++::type_expr_protos + PRIVATE googleapis_cpp_common_flags) + +google_cloud_cpp_grpcpp_library( + googleapis_cpp_iam_v1_iam_policy_protos + "${GOOGLEAPIS_CPP_SOURCE}/google/iam/v1/iam_policy.proto" + PROTO_PATH_DIRECTORIES + "${GOOGLEAPIS_CPP_SOURCE}" + "${PROTO_INCLUDE_DIR}") +googleapis_cpp_set_version_and_alias(iam_v1_iam_policy_protos) +target_link_libraries(googleapis_cpp_iam_v1_iam_policy_protos + PUBLIC googleapis-c++::api_annotations_protos + googleapis-c++::iam_v1_policy_protos + PRIVATE googleapis_cpp_common_flags) + +google_cloud_cpp_grpcpp_library( + googleapis_cpp_longrunning_operations_protos + "${GOOGLEAPIS_CPP_SOURCE}/google/longrunning/operations.proto" + PROTO_PATH_DIRECTORIES + "${GOOGLEAPIS_CPP_SOURCE}" + "${PROTO_INCLUDE_DIR}") +googleapis_cpp_set_version_and_alias(longrunning_operations_protos) +target_link_libraries(googleapis_cpp_longrunning_operations_protos + PUBLIC googleapis-c++::api_annotations_protos + googleapis-c++::rpc_status_protos + PRIVATE googleapis_cpp_common_flags) + +google_cloud_cpp_grpcpp_library( + googleapis_cpp_bigtable_protos + "${GOOGLEAPIS_CPP_SOURCE}/google/bigtable/admin/v2/bigtable_instance_admin.proto" + "${GOOGLEAPIS_CPP_SOURCE}/google/bigtable/admin/v2/bigtable_table_admin.proto" + "${GOOGLEAPIS_CPP_SOURCE}/google/bigtable/admin/v2/common.proto" + "${GOOGLEAPIS_CPP_SOURCE}/google/bigtable/admin/v2/instance.proto" + "${GOOGLEAPIS_CPP_SOURCE}/google/bigtable/admin/v2/table.proto" + "${GOOGLEAPIS_CPP_SOURCE}/google/bigtable/v2/bigtable.proto" + "${GOOGLEAPIS_CPP_SOURCE}/google/bigtable/v2/data.proto" + PROTO_PATH_DIRECTORIES + "${GOOGLEAPIS_CPP_SOURCE}" + "${PROTO_INCLUDE_DIR}") +googleapis_cpp_set_version_and_alias(bigtable_protos) +target_link_libraries(googleapis_cpp_bigtable_protos + PUBLIC googleapis-c++::api_annotations_protos + googleapis-c++::api_auth_protos + googleapis-c++::longrunning_operations_protos + googleapis-c++::rpc_status_protos + googleapis-c++::iam_v1_iam_policy_protos + PRIVATE googleapis_cpp_common_flags) + +google_cloud_cpp_grpcpp_library( + googleapis_cpp_spanner_protos + "${GOOGLEAPIS_CPP_SOURCE}/google/spanner/admin/database/v1/spanner_database_admin.proto" + "${GOOGLEAPIS_CPP_SOURCE}/google/spanner/admin/instance/v1/spanner_instance_admin.proto" + "${GOOGLEAPIS_CPP_SOURCE}/google/spanner/v1/keys.proto" + "${GOOGLEAPIS_CPP_SOURCE}/google/spanner/v1/mutation.proto" + "${GOOGLEAPIS_CPP_SOURCE}/google/spanner/v1/query_plan.proto" + "${GOOGLEAPIS_CPP_SOURCE}/google/spanner/v1/result_set.proto" + "${GOOGLEAPIS_CPP_SOURCE}/google/spanner/v1/spanner.proto" + "${GOOGLEAPIS_CPP_SOURCE}/google/spanner/v1/transaction.proto" + "${GOOGLEAPIS_CPP_SOURCE}/google/spanner/v1/type.proto" + PROTO_PATH_DIRECTORIES + "${GOOGLEAPIS_CPP_SOURCE}" + "${PROTO_INCLUDE_DIR}") +googleapis_cpp_set_version_and_alias(spanner_protos) +target_link_libraries(googleapis_cpp_spanner_protos + PUBLIC googleapis-c++::api_annotations_protos + googleapis-c++::longrunning_operations_protos + googleapis-c++::rpc_status_protos + googleapis-c++::iam_v1_iam_policy_protos + PRIVATE googleapis_cpp_common_flags) + +# Install the libraries and headers in the locations determined by +# GNUInstallDirs +include(GNUInstallDirs) + +set(googleapis_cpp_installed_libraries_list + googleapis_cpp_bigtable_protos + googleapis_cpp_spanner_protos + googleapis_cpp_longrunning_operations_protos + googleapis_cpp_api_http_protos + googleapis_cpp_api_annotations_protos + googleapis_cpp_api_auth_protos + googleapis_cpp_api_resource_protos + googleapis_cpp_iam_v1_policy_protos + googleapis_cpp_iam_v1_iam_policy_protos + googleapis_cpp_rpc_error_details_protos + googleapis_cpp_rpc_status_protos + googleapis_cpp_type_expr_protos) + +install(TARGETS ${googleapis_cpp_installed_libraries_list} + googleapis_cpp_common_flags + EXPORT googleapis-targets + RUNTIME DESTINATION bin + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) + +foreach (target ${googleapis_cpp_installed_libraries_list}) + google_cloud_cpp_install_proto_library_headers("${target}") + google_cloud_cpp_install_proto_library_protos("${target}") +endforeach () + +# Export the CMake targets to make it easy to create configuration files. +install(EXPORT googleapis-targets + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/googleapis") + +# Setup global variables used in the following *.in files. +set( + GOOGLE_CLOUD_CPP_CONFIG_VERSION_MAJOR ${GOOGLEAPIS_CPP_PROTOS_VERSION_MAJOR} + ) +set( + GOOGLE_CLOUD_CPP_CONFIG_VERSION_MINOR ${GOOGLEAPIS_CPP_PROTOS_VERSION_MINOR} + ) +set( + GOOGLE_CLOUD_CPP_CONFIG_VERSION_PATCH ${GOOGLEAPIS_CPP_PROTOS_VERSION_PATCH} + ) + +# Use a function to create a scope for the variables. +function (googleapis_cpp_install_pc target) + string(REPLACE "googleapis_cpp_" + "" + _short_name + ${target}) + string(REPLACE "_protos" + "" + _short_name + ${_short_name}) + set(GOOGLE_CLOUD_CPP_PC_NAME + "The Google APIS C++ ${_short_name} Proto Library") + set(GOOGLE_CLOUD_CPP_PC_DESCRIPTION "Compiled proto for C++.") + # Examine the target LINK_LIBRARIES property, use that to pull the + # dependencies between the googleapis-c++::* libraries. + set(_target_pc_requires) + get_target_property(_target_deps ${target} LINK_LIBRARIES) + foreach (dep ${_target_deps}) + if ("${dep}" MATCHES "^googleapis-c\\+\\+::") + string(REPLACE "googleapis-c++::" + "googleapis_cpp_" + dep + "${dep}") + list(APPEND _target_pc_requires " " "${dep}") + endif () + endforeach () + # These dependencies are required for all the googleapis-c++::* libraries. + list(APPEND _target_pc_requires + " grpc++" + " grpc" + " openssl" + " protobuf" + " zlib" + " libcares") + string(CONCAT GOOGLE_CLOUD_CPP_PC_REQUIRES ${_target_pc_requires}) + set(GOOGLE_CLOUD_CPP_PC_LIBS "-l${target}") + configure_file("cmake/config.pc.in" "${target}.pc" @ONLY) + install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${target}.pc" DESTINATION + "${CMAKE_INSTALL_LIBDIR}/pkgconfig") +endfunction () + +# Create and install the pkg-config files. +foreach (target ${googleapis_cpp_installed_libraries_list}) + googleapis_cpp_install_pc("${target}") +endforeach () + +# Create and install the googleapis pkg-config file for backwards compatibility. +set(GOOGLE_CLOUD_CPP_PC_NAME "The Google APIS C++ Proto Library") +set(GOOGLE_CLOUD_CPP_PC_DESCRIPTION + "Provides C++ APIs to access Google Cloud Platforms.") +# Note the use of spaces, `string(JOIN)` is not available in cmake-3.5, so we +# need to add the separator ourselves. +string(CONCAT GOOGLE_CLOUD_CPP_PC_REQUIRES + "googleapis_cpp_bigtable_protos" + " googleapis_cpp_iam_v1_iam_policy_protos" + " googleapis_cpp_iam_v1_policy_protos" + " googleapis_cpp_longrunning_operations_protos" + " googleapis_cpp_api_auth_protos" + " googleapis_cpp_api_annotations_protos" + " googleapis_cpp_api_http_protos" + " googleapis_cpp_rpc_status_protos" + " googleapis_cpp_rpc_error_details_protos" + " grpc++" + " grpc" + " openssl" + " protobuf" + " zlib" + " libcares") +set(GOOGLE_CLOUD_CPP_PC_LIBS "") +configure_file("cmake/config.pc.in" "googleapis.pc" @ONLY) +install(FILES "${CMAKE_CURRENT_BINARY_DIR}/googleapis.pc" DESTINATION + "${CMAKE_INSTALL_LIBDIR}/pkgconfig") + +# Create and install the CMake configuration files. +configure_file("cmake/config.cmake.in" "googleapis-config.cmake" @ONLY) +configure_file("cmake/config-version.cmake.in" "googleapis-config-version.cmake" + @ONLY) +install(FILES "${CMAKE_CURRENT_BINARY_DIR}/googleapis-config.cmake" + "${CMAKE_CURRENT_BINARY_DIR}/googleapis-config-version.cmake" + "${PROJECT_SOURCE_DIR}/cmake/FindgRPC.cmake" + "${PROJECT_SOURCE_DIR}/cmake/FindProtobufTargets.cmake" + "${PROJECT_SOURCE_DIR}/cmake/CompileProtos.cmake" + DESTINATION + "${CMAKE_INSTALL_LIBDIR}/cmake/googleapis") diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 000000000..33497a379 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,55 @@ +# How to become a contributor and submit your own code + +## Contributor License Agreements + +We'd love to accept your patches! Before we can take them, we +have to jump a couple of legal hurdles. + +Please fill out either the individual or corporate Contributor License Agreement +(CLA). + + * If you are an individual writing original source code and you're sure you + own the intellectual property, then you'll need to sign an + [individual CLA](https://developers.google.com/open-source/cla/individual). + * If you work for a company that wants to allow you to contribute your work, + then you'll need to sign a + [corporate CLA](https://developers.google.com/open-source/cla/corporate). + +Follow either of the two links above to access the appropriate CLA and +instructions for how to sign and return it. Once we receive it, we'll be able to +accept your pull requests. + +## Contributing A Patch + +1. Submit an issue describing your proposed change to the repo in question. +1. The repo owner will respond to your issue promptly. +1. If your proposed change is accepted, and you haven't already done so, sign a + Contributor License Agreement (see details above). +1. Fork the desired repo, develop and test your code changes. +1. Ensure that your code adheres to the existing style in the sample to which + you are contributing. +1. Ensure that your code has an appropriate set of unit tests which all pass. +1. Submit a pull request. + +## Style + +This repository follow the [Google C++ Style Guide]( +https://google.github.io/styleguide/cppguide.html). +Please make sure your contributions adhere to the style guide. + +### Formatting + +The code in this project is formatted with `clang-format(1)`, and our CI builds +will check that the code matches the format generated by this tool before +accepting a pull request. Please configure your editor or IDE to use the Google +style for indentation and other whitespace. If you need to reformat one or more +files, you can simply run `clang-format` manually: + +```console +$ clang-format -i .... +``` + +If you need to reformat one of the files to match the Google style. Please be +advised that `clang-format` has been known to generate slightly different +formatting in different versions. We use version 7; use the same version if you +run into problems. diff --git a/LICENSE b/LICENSE new file mode 100644 index 000000000..261eeb9e9 --- /dev/null +++ b/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + 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 + + http://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. diff --git a/README.md b/README.md new file mode 100644 index 000000000..5c2a71193 --- /dev/null +++ b/README.md @@ -0,0 +1,68 @@ +# Google Cloud Platform C++ Proto Libraries + +Compile the protocol buffer definitions into C++ libraries. + +## Requirements + +#### Compiler + +The Google Cloud C++ libraries are tested with the following compilers: + +| Compiler | Minimum Version | +| ----------- | --------------- | +| GCC | 4.8 | +| Clang | 3.8 | +| MSVC++ | 14.1 | +| Apple Clang | 8.1 | + +#### Build Tools + +The Google Cloud C++ Client Libraries can be built with +[CMake](https://cmake.org) or [Bazel](https://bazel.io). The minimal versions +of these tools we test with are: + +| Tool | Minimum Version | +| ---------- | --------------- | +| CMake | 3.5 | +| Bazel | 0.24.0 | + +#### Libraries + +The libraries also depend on gRPC, libcurl, and the dependencies of those +libraries. The Google Cloud C++ Client libraries are tested with the following +versions of these dependencies: + +| Library | Minimum version | +| ------- | --------------- | +| gRPC | v1.16.x | +| libcurl | 7.47.0 | + + +## Versioning + +Please note that the Google Cloud C++ client libraries do **not** follow +[Semantic Versioning](http://semver.org/). + +**GA**: Libraries defined at a GA quality level are expected to be stable and +any backwards-incompatible changes will be noted in the documentation. Major +changes to the API will signaled by changing major version number +(e.g. 1.x.y -> 2.0.0). + +**Beta**: Libraries defined at a Beta quality level are expected to be mostly +stable and we're working towards their release candidate. We will address issues +and requests with a higher priority. + +**Alpha**: Libraries defined at an Alpha quality level are still a +work-in-progress and are more likely to get backwards-incompatible updates. +Additionally, it's possible for Alpha libraries to get deprecated and deleted +before ever being promoted to Beta or GA. + +## Contributing changes + +See [`CONTRIBUTING.md`](CONTRIBUTING.md) for details on how to contribute to +this project, including how to build and test your changes as well as how to +properly format your code. + +## Licensing + +Apache 2.0; see [`LICENSE`](LICENSE) for details. diff --git a/cmake/CompileProtos.cmake b/cmake/CompileProtos.cmake new file mode 100644 index 000000000..a01a90b82 --- /dev/null +++ b/cmake/CompileProtos.cmake @@ -0,0 +1,286 @@ +# ~~~ +# Copyright 2019 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 +# +# http://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. +# ~~~ + +# Introduce a new TARGET property to associate proto files with a target. +# +# We use a function to define the property so it can be called multiple times +# without introducing the property over and over. +function (google_cloud_cpp_add_protos_property) + set_property(TARGET + PROPERTY PROTO_SOURCES + BRIEF_DOCS + "The list of .proto files for a target." + FULL_DOCS + "List of .proto files specified for a target.") +endfunction () + +# Generate C++ for .proto files preserving the directory hierarchy +# +# Receives a list of `.proto` file names and (a) creates the runs to convert +# these files to `.pb.h` and `.pb.cc` output files, (b) returns the list of +# `.pb.cc` files and `.pb.h` files in @p HDRS, and (c) creates the list of files +# preserving the directory hierarchy, such that if a `.proto` file says: +# +# import "foo/bar/baz.proto" +# +# the resulting C++ code says: +# +# #include +# +# Use the `PROTO_PATH` option to provide one or more directories to search for +# proto files in the import. +# +# @par Example +# +# google_cloud_cpp_generate_proto( MY_PB_FILES "foo/bar/baz.proto" +# "foo/bar/qux.proto" PROTO_PATH_DIRECTORIES "another/dir/with/protos") +# +# Note that `protoc` the protocol buffer compiler requires your protos to be +# somewhere in the search path defined by the `--proto_path` (aka -I) options. +# For example, if you want to generate the `.pb.{h,cc}` files for +# `foo/bar/baz.proto` then the directory containing `foo` must be in the search +# path. +function (google_cloud_cpp_generate_proto SRCS) + cmake_parse_arguments(_opt "" "" "PROTO_PATH_DIRECTORIES" ${ARGN}) + if (NOT _opt_UNPARSED_ARGUMENTS) + message(SEND_ERROR "Error: google_cloud_cpp_generate_proto() called" + " without any proto files") + return() + endif () + + # Build the list of `--proto_path` options. Use the absolute path for each + # option given, and do not include any path more than once. + set(protobuf_include_path) + foreach (dir ${_opt_PROTO_PATH_DIRECTORIES}) + get_filename_component(absolute_path ${dir} ABSOLUTE) + list(FIND protobuf_include_path "${absolute_path}" + already_in_search_path) + if (${already_in_search_path} EQUAL -1) + list(APPEND protobuf_include_path "--proto_path" "${absolute_path}") + endif () + endforeach () + + set(${SRCS}) + foreach (filename ${_opt_UNPARSED_ARGUMENTS}) + get_filename_component(file_directory "${filename}" DIRECTORY) + # This gets the filename without the extension, analogous to $(basename + # "${filename}" .proto) + get_filename_component(file_stem "${filename}" NAME_WE) + + # Strip all the prefixes in ${_opt_PROTO_PATH_DIRECTORIES} from the + # source proto directory + set(D "${file_directory}") + if (DEFINED _opt_PROTO_PATH_DIRECTORIES) + foreach (P ${_opt_PROTO_PATH_DIRECTORIES}) + string(REGEX + REPLACE "^${P}" + "" + T + "${D}") + set(D ${T}) + endforeach () + endif () + set(pb_cc "${CMAKE_CURRENT_BINARY_DIR}/${D}/${file_stem}.pb.cc") + set(pb_h "${CMAKE_CURRENT_BINARY_DIR}/${D}/${file_stem}.pb.h") + list(APPEND ${SRCS} "${pb_cc}" "${pb_h}") + add_custom_command( + OUTPUT "${pb_cc}" "${pb_h}" + COMMAND $ + ARGS + --cpp_out "${CMAKE_CURRENT_BINARY_DIR}" + ${protobuf_include_path} "${filename}" + DEPENDS "${filename}" protobuf::protoc + COMMENT "Running C++ protocol buffer compiler on ${filename}" + VERBATIM) + endforeach () + + set_source_files_properties(${${SRCS}} PROPERTIES GENERATED TRUE) + set(${SRCS} ${${SRCS}} PARENT_SCOPE) +endfunction () + +# Generate gRPC C++ files from .proto files preserving the directory hierarchy. +# +# Receives a list of `.proto` file names and (a) creates the runs to convert +# these files to `.grpc.pb.h` and `.grpc.pb.cc` output files, (b) returns the +# list of `.grpc.pb.cc` and `.pb.h` files in @p SRCS, and (c) creates the list +# of files preserving the directory hierarchy, such that if a `.proto` file says +# +# import "foo/bar/baz.proto" +# +# the resulting C++ code says: +# +# #include +# +# Use the `PROTO_PATH` option to provide one or more directories to search for +# proto files in the import. +# +# @par Example +# +# google_cloud_cpp_generate_grpc( MY_GRPC_PB_FILES "foo/bar/baz.proto" +# "foo/bar/qux.proto" PROTO_PATH_DIRECTORIES "another/dir/with/protos") +# +# Note that `protoc` the protocol buffer compiler requires your protos to be +# somewhere in the search path defined by the `--proto_path` (aka -I) options. +# For example, if you want to generate the `.pb.{h,cc}` files for +# `foo/bar/baz.proto` then the directory containing `foo` must be in the search +# path. +function (google_cloud_cpp_generate_grpcpp SRCS) + cmake_parse_arguments(_opt "" "" "PROTO_PATH_DIRECTORIES" ${ARGN}) + if (NOT _opt_UNPARSED_ARGUMENTS) + message( + SEND_ERROR "Error: google_cloud_cpp_generate_grpc() called without" + " any proto files") + return() + endif () + + # Build the list of `--proto_path` options. Use the absolute path for each + # option given, and do not include any path more than once. + set(protobuf_include_path) + foreach (dir ${_opt_PROTO_PATH_DIRECTORIES}) + get_filename_component(absolute_path ${dir} ABSOLUTE) + list(FIND protobuf_include_path "${absolute_path}" + already_in_search_path) + if (${already_in_search_path} EQUAL -1) + list(APPEND protobuf_include_path "--proto_path" "${absolute_path}") + endif () + endforeach () + + set(${SRCS}) + foreach (filename ${_opt_UNPARSED_ARGUMENTS}) + get_filename_component(file_directory "${filename}" DIRECTORY) + # This gets the filename without the extension, analogous to $(basename + # "${filename}" .proto) + get_filename_component(file_stem "${filename}" NAME_WE) + + # Strip all the prefixes in ${_opt_PROTO_PATH_DIRECTORIES} from the + # source proto directory + set(D "${file_directory}") + if (DEFINED _opt_PROTO_PATH_DIRECTORIES) + foreach (P ${_opt_PROTO_PATH_DIRECTORIES}) + string(REGEX + REPLACE "^${P}" + "" + T + "${D}") + set(D ${T}) + endforeach () + endif () + set(grpc_pb_cc + "${CMAKE_CURRENT_BINARY_DIR}/${D}/${file_stem}.grpc.pb.cc") + set(grpc_pb_h "${CMAKE_CURRENT_BINARY_DIR}/${D}/${file_stem}.grpc.pb.h") + list(APPEND ${SRCS} "${grpc_pb_cc}" "${grpc_pb_h}") + add_custom_command( + OUTPUT "${grpc_pb_cc}" "${grpc_pb_h}" + COMMAND + $ + ARGS + --plugin=protoc-gen-grpc=$ + "--grpc_out=${CMAKE_CURRENT_BINARY_DIR}" + "--cpp_out=${CMAKE_CURRENT_BINARY_DIR}" + ${protobuf_include_path} "${filename}" + DEPENDS "${filename}" protobuf::protoc gRPC::grpc_cpp_plugin + COMMENT "Running gRPC C++ protocol buffer compiler on ${filename}" + VERBATIM) + endforeach () + + set_source_files_properties(${${SRCS}} PROPERTIES GENERATED TRUE) + set(${SRCS} ${${SRCS}} PARENT_SCOPE) +endfunction () + +include(GNUInstallDirs) + +# Install headers for a C++ proto library. +function (google_cloud_cpp_install_proto_library_headers target) + get_target_property(target_sources ${target} SOURCES) + foreach (header ${target_sources}) + # Skip anything that is not a header file. + if (NOT "${header}" MATCHES "\\.h$") + continue() + endif () + string(REPLACE "${CMAKE_CURRENT_BINARY_DIR}/" + "" + relative + "${header}") + get_filename_component(dir "${relative}" DIRECTORY) + install(FILES "${header}" DESTINATION + "${CMAKE_INSTALL_INCLUDEDIR}/${dir}") + endforeach () +endfunction () + +# Install protos for a C++ proto library. +function (google_cloud_cpp_install_proto_library_protos target) + get_target_property(target_protos ${target} PROTO_SOURCES) + foreach (header ${target_protos}) + # Skip anything that is not a header file. + if (NOT "${header}" MATCHES "\\.proto$") + continue() + endif () + string(REPLACE "${CMAKE_CURRENT_BINARY_DIR}/" + "" + relative + "${header}") + get_filename_component(dir "${relative}" DIRECTORY) + # This is modeled after the Protobuf library, it installs the basic + # protos (think google/protobuf/any.proto) in the include directory for + # C/C++ code. :shrug: + install(FILES "${header}" DESTINATION + "${CMAKE_INSTALL_INCLUDEDIR}/${dir}") + endforeach () +endfunction () + +function (google_cloud_cpp_proto_library libname) + cmake_parse_arguments(_opt "" "" "PROTO_PATH_DIRECTORIES" ${ARGN}) + if (NOT _opt_UNPARSED_ARGUMENTS) + message(SEND_ERROR "Error: google_cloud_cpp_proto_library() called" + " without any proto files") + return() + endif () + + google_cloud_cpp_generate_proto(proto_sources + ${_opt_UNPARSED_ARGUMENTS} + PROTO_PATH_DIRECTORIES + ${_opt_PROTO_PATH_DIRECTORIES}) + + add_library(${libname} ${proto_sources}) + set_property(TARGET ${libname} + PROPERTY PROTO_SOURCES ${_opt_UNPARSED_ARGUMENTS}) + target_link_libraries(${libname} + PUBLIC gRPC::grpc++ gRPC::grpc protobuf::libprotobuf) + target_include_directories( + ${libname} + PUBLIC $ + $ + $) +endfunction () + +function (google_cloud_cpp_grpcpp_library libname) + cmake_parse_arguments(_opt "" "" "PROTO_PATH_DIRECTORIES" ${ARGN}) + if (NOT _opt_UNPARSED_ARGUMENTS) + message(SEND_ERROR "Error: google_cloud_cpp_proto_library() called" + " without any proto files") + return() + endif () + + google_cloud_cpp_generate_grpcpp(grpcpp_sources + ${_opt_UNPARSED_ARGUMENTS} + PROTO_PATH_DIRECTORIES + ${_opt_PROTO_PATH_DIRECTORIES}) + google_cloud_cpp_proto_library(${libname} + ${_opt_UNPARSED_ARGUMENTS} + PROTO_PATH_DIRECTORIES + ${_opt_PROTO_PATH_DIRECTORIES}) + target_sources(${libname} PRIVATE ${grpcpp_sources}) +endfunction () diff --git a/cmake/FindProtobufTargets.cmake b/cmake/FindProtobufTargets.cmake new file mode 100644 index 000000000..db260280d --- /dev/null +++ b/cmake/FindProtobufTargets.cmake @@ -0,0 +1,207 @@ +# ~~~ +# Copyright 2019 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 +# +# http://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. +# ~~~ + +#[=======================================================================[.rst: +FindProtobufTargets +------------------- + +A module to use `Protobuf` with less complications. + +Using ``find_package(Protobuf)`` should be simple, but it is not. + +CMake provides a ``FindProtobuf`` module. Unfortunately it does not generate +`protobuf::*` targets until CMake-3.9, and `protobuf::protoc` does not +appear until CMake-3.10. + +The CMake-config files generated by `protobuf` always create these targets, +but on some Linux distributions (e.g. Fedora>=29, and openSUSE-Tumbleweed) there +are system packages for protobuf, but these packages are installed without the +CMake-config files. One must either use the ``FindProtobuf`` module, find the +libraries via `pkg-config`, or find the libraries manually. + +When the CMake-config files are installed they produce the same targets as +recent versions of ``FindProtobuf``. However, they do not produce the +`Protobuf_LIBRARY`, `Protobuf_INCLUDE_DIR`, etc. that are generated by the +module. Furthermore, the `protobuf::protoc` library is not usable when loaded +from the CMake-config files: its ``IMPORTED_LOCATION`` variable is not defined. + +This module is designed to provide a single, uniform, ``find_package()`` +module that always produces the same outputs: + +- It always generates the ``protobuf::*`` targets. +- It always defines ``ProtobufTargets_FOUND`` and ``ProtobufTargets_VERSION``. +- It *prefers* using the CMake config files if they are available. +- It fallsback on the ``FindProtobuf`` module if the config files are not found. +- It populates any missing targets and their properties. + +The following :prop_tgt:`IMPORTED` targets are defined: + +``protobuf::libprotobuf`` + The protobuf library. +``protobuf::libprotobuf-lite`` + The protobuf lite library. +``protobuf::libprotoc`` + The protoc library. +``protobuf::protoc`` + The protoc compiler. + +Example: + +.. code-block:: cmake + + find_package(ProtobufTargets REQUIRED) + add_executable(bar bar.cc) + target_link_libraries(bar PRIVATE protobuf::libprotobuf) + +#]=======================================================================] + +if (protobuf_DEBUG) + message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " + "protobuf_USE_STATIC_LIBS = ${protobuf_USE_STATIC_LIBS}" + " ProtobufTargets = ${ProtobufTargets_FOUND}") +endif () + +# Always load thread support, even on Windows. +find_package(Threads REQUIRED) + +# First try to use the ``protobufConfig.cmake`` or ``protobuf-config.cmake`` +# file if it was installed. This is common on systems (or package managers) +# where protobuf was compiled and installed with `CMake`. Note that on Linux +# this *must* be all lowercase ``protobuf``, while on Windows it does not +# matter. +find_package(protobuf CONFIG) + +if (protobuf_DEBUG) + message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " + "protobuf_FOUND = ${protobuf_FOUND}" + " protobuf_VERSION = ${protobuf_VERSION}") +endif () + +if (protobuf_FOUND) + set(ProtobufTargets_FOUND 1) + set(ProtobufTargets_VERSION ${protobuf_VERSION}) + if (protobuf_DEBUG) + message( + STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " + "ProtobufTargets_FOUND = ${ProtobufTargets_FOUND}" + " ProtobufTargets_VERSION = ${ProtobufTargets_VERSION}") + endif () +else() + find_package(Protobuf QUIET) + if (Protobuf_FOUND) + set(ProtobufTargets_FOUND 1) + set(ProtobufTargets_VERSION ${Protobuf_VERSION}) + + if (NOT TARGET protobuf::libprotobuf) + add_library(protobuf::libprotobuf INTERFACE IMPORTED) + set_property(TARGET protobuf::libprotobuf + PROPERTY INTERFACE_INCLUDE_DIRECTORIES + ${Protobuf_INCLUDE_DIR}) + set_property(TARGET protobuf::libprotobuf + APPEND + PROPERTY INTERFACE_LINK_LIBRARIES ${Protobuf_LIBRARY} + Threads::Threads) + endif () + + if (NOT TARGET protobuf::libprotobuf-lite) + add_library(protobuf::libprotobuf-lite INTERFACE IMPORTED) + set_property(TARGET protobuf::libprotobuf-lite + PROPERTY INTERFACE_INCLUDE_DIRECTORIES + ${Protobuf_INCLUDE_DIR}) + set_property(TARGET protobuf::libprotobuf-lite + APPEND + PROPERTY INTERFACE_LINK_LIBRARIES + ${Protobuf_LITE_LIBRARY} Threads::Threads) + endif () + + if (NOT TARGET protobuf::libprotoc) + add_library(protobuf::libprotoc INTERFACE IMPORTED) + set_property(TARGET protobuf::libprotoc + PROPERTY INTERFACE_INCLUDE_DIRECTORIES + ${Protobuf_INCLUDE_DIR}) + set_property(TARGET protobuf::libprotoc + APPEND + PROPERTY INTERFACE_LINK_LIBRARIES + ${Protobuf_PROTOC_LIBRARY} Threads::Threads) + endif () + endif () +endif () + +if (protobuf_DEBUG) + message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " + "ProtobufTargets_FOUND = ${ProtobufTargets_FOUND}" + " ProtobufTargets_VERSION = ${ProtobufTargets_VERSION}") +endif () + +# We also should try to find the protobuf C++ plugin for the protocol buffers +# compiler. +if (ProtobufTargets_FOUND AND NOT TARGET protobuf::protoc) + add_executable(protobuf::protoc IMPORTED) + + # Discover the protoc compiler location. + find_program(_protobuf_PROTOC_EXECUTABLE + NAMES protoc + DOC "The Google Protocol Buffers Compiler") + if (protobuf_DEBUG) + message( + STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " + "ProtobufTargets_FOUND = ${ProtobufTargets_FOUND}" + " ProtobufTargets_VERSION = ${ProtobufTargets_VERSION}" + " EXE = ${_protobuf_PROTOC_EXECUTABLE}") + endif () + set_property(TARGET protobuf::protoc + PROPERTY IMPORTED_LOCATION ${_protobuf_PROTOC_EXECUTABLE}) + set_property( + TARGET protobuf::protoc + PROPERTY IMPORTED_LOCATION_DEBUG ${_protobuf_PROTOC_EXECUTABLE}) + set_property(TARGET protobuf::protoc + PROPERTY IMPORTED_LOCATION_RELEASE + ${_protobuf_PROTOC_EXECUTABLE}) + unset(_protobuf_PROTOC_EXECUTABLE) + + if (protobuf_DEBUG) + get_target_property(_protobuf_PROTOC_EXECUTABLE protobuf::protoc + IMPORTED_LOCATION) + message( + STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " + "LOCATION=${_protobuf_PROTOC_EXECUTABLE}") + endif () +endif () + +if (protobuf_DEBUG) + message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " + "ProtobufTargets_FOUND = ${ProtobufTargets_FOUND}" + " ProtobufTargets_VERSION = ${ProtobufTargets_VERSION}") + if (ProtobufTargets_FOUND) + foreach (_target + protobuf::libprotobuf + protobuf::libprotobuf-lite + protobuf::libprotoc) + if (NOT TARGET ${_target}) + message( + STATUS + "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " + "target=${_target} is NOT a target") + endif () + endforeach () + unset(_target) + endif () +endif () + +find_package_handle_standard_args(ProtobufTargets + REQUIRED_VARS + ProtobufTargets_FOUND + ProtobufTargets_VERSION) diff --git a/cmake/FindgRPC.cmake b/cmake/FindgRPC.cmake new file mode 100644 index 000000000..5895cf067 --- /dev/null +++ b/cmake/FindgRPC.cmake @@ -0,0 +1,343 @@ +# ~~~ +# Copyright 2019 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 +# +# http://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. +# ~~~ + +#[=======================================================================[.rst: +FindgRPC +-------- + +Locate and configure the gRPC library. + +The following variables can be set and are optional: + +``gRPC_DEBUG`` + Show debug messages. +``gRPC_USE_STATIC_LIBS`` + Set to ON to force the use of the static libraries. + Default is OFF. + +Defines the following variables: + +``gRPC_FOUND`` + Found the gRPC library +``gRPC_VERSION`` + Version of package found. + +The following :prop_tgt:`IMPORTED` targets are also defined: + +``gRPC::grpc++`` + The gRPC C++ library. +``gRPC::grpc`` + The gRPC C core library. +``gRPC::cpp_plugin`` + The C++ plugin for the Protobuf protoc compiler. + +The following cache variables are also available to set or use: + +Example: + +.. code-block:: cmake + + find_package(gRPC REQUIRED) + add_executable(bar bar.cc) + target_link_libraries(bar PRIVATE gRPC::grpc++) + +#]=======================================================================] + +if (gRPC_DEBUG) + message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " + "gRPC_USE_STATIC_LIBS = ${gRPC_USE_STATIC_LIBS}" + " gRPC_FOUND = ${gRPC_FOUND}") +endif () + +# gRPC always requires Thread support. +find_package(Threads REQUIRED) + +# Load the module to find protobuf with proper targets. Do not use +# `find_package()` because we (have to) install this module in non-standard +# locations. +include(${CMAKE_CURRENT_LIST_DIR}/FindProtobufTargets.cmake) + +# The gRPC::grpc_cpp_plugin target is sometimes defined, but without a +# IMPORTED_LOCATION +function (_grpc_fix_grpc_cpp_plugin_target) + # The target may already exist, do not create it again if it does. + if (NOT TARGET gRPC::grpc_cpp_plugin) + add_executable(gRPC::grpc_cpp_plugin IMPORTED) + endif () + get_target_property(_gRPC_CPP_PLUGIN_EXECUTABLE gRPC::grpc_cpp_plugin + IMPORTED_LOCATION) + if (gRPC_DEBUG) + message( + STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " + "LOCATION=${_gRPC_CPP_PLUGIN_EXECUTABLE}") + endif () + # Even if the target exists, gRPC CMake support files do not define the + # executable for the imported target (at least they do not in v1.19.1), so + # we need to define it ourselves. + if (NOT _gRPC_CPP_PLUGIN_EXECUTABLE) + find_program(_gRPC_CPP_PLUGIN_EXECUTABLE grpc_cpp_plugin + DOC "The gRPC C++ plugin for protoc") + mark_as_advanced(_gRPC_CPP_PLUGIN_EXECUTABLE) + if (_gRPC_CPP_PLUGIN_EXECUTABLE) + set_property(TARGET gRPC::grpc_cpp_plugin + PROPERTY IMPORTED_LOCATION + ${_gRPC_CPP_PLUGIN_EXECUTABLE}) + else() + set(gRPC_FOUND "grpc_cpp_plugin-NOTFOUND") + endif () + endif () +endfunction () + +# The gRPC::* targets sometimes lack the right definitions to compile cleanly on +# WIN32 +function (_grpc_fix_grpc_target_definitions) + # Including gRPC headers without this definition results in a build error. + if (WIN32) + set_property(TARGET gRPC::grpc + APPEND + PROPERTY INTERFACE_COMPILE_DEFINITIONS _WIN32_WINNT=0x600) + set_property(TARGET gRPC::grpc++ + APPEND + PROPERTY INTERFACE_COMPILE_DEFINITIONS _WIN32_WINNT=0x600) + endif () +endfunction () + +# First try to use the `gRPCConfig.cmake` or `grpc-config.cmake` file if it was +# installed. This is common on systems (or package managers) where gRPC was +# compiled and installed with `CMake`. +find_package(gRPC NO_MODULE QUIET) + +if (gRPC_DEBUG) + message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " + "NO_MODULE result gRPC_FOUND = ${gRPC_FOUND}") +endif () + +if (gRPC_FOUND) + _grpc_fix_grpc_cpp_plugin_target() + _grpc_fix_grpc_target_definitions() + return() +endif () + +include(SelectLibraryConfigurations) + +# Internal function: search for normal library as well as a debug one if the +# debug one is specified also include debug/optimized keywords in *_LIBRARIES +# variable +function (_gRPC_find_library name filename) + if (${name}_LIBRARY) + # Use result recorded by a previous call. + return() + else() + find_library(${name}_LIBRARY_RELEASE NAMES ${filename}) + mark_as_advanced(${name}_LIBRARY_RELEASE) + + find_library(${name}_LIBRARY_DEBUG NAMES ${filename}d ${filename}) + mark_as_advanced(${name}_LIBRARY_DEBUG) + + select_library_configurations(${name}) + + if (gRPC_DEBUG) + message( + STATUS + "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " + "${name} ${filename} RELEASE=${${name}_LIBRARY}" + " DEBUG=${${name}_LIBRARY_DEBUG} DEFAULT=${${name}_LIBRARY}" + ) + endif () + + set(${name}_LIBRARY "${${name}_LIBRARY}" PARENT_SCOPE) + endif () +endfunction () + +# +# Main +# + +# Support preference of static libs by adjusting CMAKE_FIND_LIBRARY_SUFFIXES +if (_gRPC_USE_STATIC_LIBS) + set(_gRPC_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES}) + if (WIN32) + set(CMAKE_FIND_LIBRARY_SUFFIXES .lib .a ${CMAKE_FIND_LIBRARY_SUFFIXES}) + else() + set(CMAKE_FIND_LIBRARY_SUFFIXES .a) + endif () +endif () + +_grpc_find_library(_gRPC_grpc grpc) +_grpc_find_library(_gRPC_grpc++ grpc++) + +if (NOT _gRPC_INCLUDE_DIR) + find_path(_gRPC_INCLUDE_DIR grpcpp/grpcpp.h) + mark_as_advanced(_gRPC_INCLUDE_DIR) +endif () + +if (gRPC_DEBUG) + message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " + " _gRPC_grpc_LIBRARY = ${_gRPC_grpc_LIBRARY}") + message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " + " _gRPC_grpc++_LIBRARY = ${_gRPC_grpc++_LIBRARY}") + message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " + " _gRPC_INCLUDE_DIR = ${_gRPC_INCLUDE_DIR}") +endif () + +if (_gRPC_grpc_LIBRARY) + if (NOT TARGET gRPC::grpc) + add_library(gRPC::grpc UNKNOWN IMPORTED) + set_target_properties(gRPC::grpc + PROPERTIES INTERFACE_INCLUDE_DIRECTORIES + "${_gRPC_INCLUDE_DIR}") + if (EXISTS "${_gRPC_grpc_LIBRARY}") + set_target_properties(gRPC::grpc + PROPERTIES IMPORTED_LOCATION + "${_gRPC_grpc_LIBRARY}") + endif () + if (EXISTS "${_gRPC_grpc_LIBRARY_RELEASE}") + set_property(TARGET gRPC::grpc + APPEND + PROPERTY IMPORTED_CONFIGURATIONS RELEASE) + set_target_properties(gRPC::grpc + PROPERTIES IMPORTED_LOCATION_RELEASE + "${_gRPC_grpc_LIBRARY_RELEASE}") + endif () + if (EXISTS "${_gRPC_grpc_LIBRARY_DEBUG}") + set_property(TARGET gRPC::grpc + APPEND + PROPERTY IMPORTED_CONFIGURATIONS DEBUG) + set_target_properties(gRPC::grpc + PROPERTIES IMPORTED_LOCATION_DEBUG + "${_gRPC_grpc_LIBRARY_DEBUG}") + endif () + set_property(TARGET gRPC::grpc + APPEND + PROPERTY INTERFACE_LINK_LIBRARIES protobuf::libprotobuf + Threads::Threads) + endif () +endif () + +if (_gRPC_grpc++_LIBRARY) + if (NOT TARGET gRPC::grpc++) + add_library(gRPC::grpc++ UNKNOWN IMPORTED) + set_target_properties(gRPC::grpc++ + PROPERTIES INTERFACE_INCLUDE_DIRECTORIES + "${_gRPC++_INCLUDE_DIR}") + if (EXISTS "${_gRPC_grpc++_LIBRARY}") + set_target_properties(gRPC::grpc++ + PROPERTIES IMPORTED_LOCATION + "${_gRPC_grpc++_LIBRARY}") + endif () + if (EXISTS "${_gRPC_grpc++_LIBRARY_RELEASE}") + set_property(TARGET gRPC::grpc++ + APPEND + PROPERTY IMPORTED_CONFIGURATIONS RELEASE) + set_target_properties(gRPC::grpc++ + PROPERTIES IMPORTED_LOCATION_RELEASE + "${_gRPC_grpc++_LIBRARY_RELEASE}") + endif () + if (EXISTS "${_gRPC_grpc++_LIBRARY_DEBUG}") + set_property(TARGET gRPC::grpc++ + APPEND + PROPERTY IMPORTED_CONFIGURATIONS DEBUG) + set_target_properties(gRPC::grpc++ + PROPERTIES IMPORTED_LOCATION_DEBUG + "${_gRPC_grpc++_LIBRARY_DEBUG}") + endif () + set_property(TARGET gRPC::grpc++ + APPEND + PROPERTY INTERFACE_LINK_LIBRARIES + gRPC::grpc + protobuf::libprotobuf + Threads::Threads) + if (CMAKE_VERSION VERSION_GREATER 3.8) + # gRPC++ requires C++11, but only CMake-3.8 introduced a target + # compiler feature to meet that requirement. + set_property(TARGET gRPC::grpc++ + APPEND + PROPERTY INTERFACE_COMPILE_FEATURES cxx_std_11) + elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") + # CMake 3.5 is still alive and kicking in some older distros, use + # the compiler-specific versions in these cases. + set_property(TARGET gRPC::grpc++ + APPEND + PROPERTY INTERFACE_COMPILE_OPTIONS "-std=c++11") + elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + set_property(TARGET gRPC::grpc++ + APPEND + PROPERTY INTERFACE_COMPILE_OPTIONS "-std=c++11") + else() + message( + WARNING + "gRPC::grpc++ requires C++11, but this module" + " (${CMAKE_CURRENT_LIST_FILE})" + " cannot enable it for the library target in your CMake and" + " compiler versions. You need to enable C++11 in the" + " CMakeLists.txt for your project. Consider filing a bug" + " so we can fix this problem.") + endif () + endif () +endif () + +# Restore original find library prefixes +if (_gRPC_USE_STATIC_LIBS) + set(CMAKE_FIND_LIBRARY_PREFIXES "${_gRPC_ORIG_FIND_LIBRARY_PREFIXES}") +endif () + +file(WRITE "${CMAKE_BINARY_DIR}/get_gRPC_version.cc" [====[ +#include +#include +int main() { + std::cout << grpc::Version(); // no newline to simplify CMake module + return 0; +} + ]====]) + +try_run(_gRPC_GET_VERSION_STATUS + _gRPC_GET_VERSION_COMPILE_STATUS + "${CMAKE_BINARY_DIR}" + "${CMAKE_BINARY_DIR}/get_gRPC_version.cc" + LINK_LIBRARIES + gRPC::grpc++ + gRPC::grpc + COMPILE_OUTPUT_VARIABLE _gRPC_GET_VERSION_COMPILE_OUTPUT + RUN_OUTPUT_VARIABLE gRPC_VERSION) + +file(REMOVE "${CMAKE_BINARY_DIR}/get_gRPC_version.cc") + +_grpc_fix_grpc_cpp_plugin_target() + +if (gRPC_DEBUG) + foreach (_var + _gRPC_CPP_PLUGIN_EXECUTABLE + _gRPC_VERSION_RAW + _gRPC_GET_VERSION_STATUS + _gRPC_GET_VERSION_COMPILE_STATUS + _gRPC_GET_VERSION_COMPILE_OUTPUT + _gRPC_grpc_LIBRARY + _gRPC_grpc++_LIBRARY + _gRPC_INCLUDE_DIR) + message( + STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " + "${_var} = ${${_var}}") + endforeach () + unset(_var) +endif () + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(gRPC + REQUIRED_VARS + _gRPC_grpc_LIBRARY + _gRPC_INCLUDE_DIR + VERSION_VAR + gRPC_VERSION) diff --git a/cmake/SelectMSVCRuntime.cmake b/cmake/SelectMSVCRuntime.cmake new file mode 100644 index 000000000..eb7f8f9e9 --- /dev/null +++ b/cmake/SelectMSVCRuntime.cmake @@ -0,0 +1,46 @@ +# ~~~ +# Copyright 2019 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 +# +# http://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. +# ~~~ + +# When compiling against *-static vcpkg packages we need to use the static C++ +# runtime with MSVC. The default is to use the dynamic runtime, which does not +# work in this case. This seems to be the recommended way to change the +# runtime: +# +# ~~~ +# https://gitlab.kitware.com/cmake/community/wikis/FAQ#how-can-i-build-my-msvc-application-with-a-static-runtime +# ~~~ +# +# Note that currently we use VCPKG_TARGET_TRIPLET to determine if the static +# runtime is needed. In the future we may need to use a more complex expression +# to determine this, but this is a good start. +# +if (MSVC AND VCPKG_TARGET_TRIPLET MATCHES "-static$") + foreach (flag_var + CMAKE_CXX_FLAGS + CMAKE_CXX_FLAGS_DEBUG + CMAKE_CXX_FLAGS_RELEASE + CMAKE_CXX_FLAGS_MINSIZEREL + CMAKE_CXX_FLAGS_RELWITHDEBINFO) + if (${flag_var} MATCHES "/MD") + string(REGEX + REPLACE "/MD" + "/MT" + ${flag_var} + "${${flag_var}}") + endif () + endforeach (flag_var) + unset(flag_var) +endif () diff --git a/cmake/config-version.cmake.in b/cmake/config-version.cmake.in new file mode 100644 index 000000000..29891a6bd --- /dev/null +++ b/cmake/config-version.cmake.in @@ -0,0 +1,35 @@ +# Copyright 2019 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 +# +# http://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. + +set(PACKAGE_VERSION @DOXYGEN_PROJECT_NUMBER@) + +# This package has not reached 1.0, there are no compatibility guarantees +# before then. +if (@GOOGLE_CLOUD_CPP_CONFIG_VERSION_MAJOR@ EQUAL 0) + if ("${PACKAGE_FIND_VERSION}" STREQUAL "") + set(PACKAGE_VERSION_COMPATIBLE TRUE) + elseif ("${PACKAGE_VERSION}" VERSION_EQUAL "${PACKAGE_FIND_VERSION}") + set(PACKAGE_VERSION_COMPATIBLE TRUE) + set(PACKAGE_VERSION_EXACT TRUE) + else () + set(PACKAGE_VERSION_UNSUITABLE TRUE) + endif () +elseif("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}") + set(PACKAGE_VERSION_COMPATIBLE FALSE) +else() + set(PACKAGE_VERSION_COMPATIBLE TRUE) + if ("${PACKAGE_VERSION}" VERSION_EQUAL "${PACKAGE_FIND_VERSION}") + set(PACKAGE_VERSION_EXACT TRUE) + endif() +endif() diff --git a/cmake/config.cmake.in b/cmake/config.cmake.in new file mode 100644 index 000000000..50ddd6bbd --- /dev/null +++ b/cmake/config.cmake.in @@ -0,0 +1,36 @@ +# Copyright 2019 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 +# +# http://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("${CMAKE_CURRENT_LIST_DIR}/FindProtobufTargets.cmake") +include("${CMAKE_CURRENT_LIST_DIR}/FindgRPC.cmake") + +include("${CMAKE_CURRENT_LIST_DIR}/googleapis-targets.cmake") + +foreach (_target + api_http + api_annotations + api_auth + rpc_status + rpc_error_details + longrunning_operations + iam_v1_policy + iam_v1_iam_policy + bigtable + spanner) + set(scoped_name "googleapis-c++::${_target}_protos") + set(imported_name "googleapis_cpp_${_target}_protos") + add_library(${scoped_name} IMPORTED INTERFACE) + set_target_properties(${scoped_name} PROPERTIES + INTERFACE_LINK_LIBRARIES ${imported_name}) +endforeach () diff --git a/cmake/config.pc.in b/cmake/config.pc.in new file mode 100644 index 000000000..af068beb7 --- /dev/null +++ b/cmake/config.pc.in @@ -0,0 +1,26 @@ +# Copyright 2019 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 +# +# http://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. + +prefix=@CMAKE_INSTALL_PREFIX@ +exec_prefix=${prefix}/@CMAKE_INSTALL_BINDIR@ +libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@ +includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@ + +Name: @GOOGLE_CLOUD_CPP_PC_NAME@ +Description: @GOOGLE_CLOUD_CPP_PC_DESCRIPTION@ +Requires: @GOOGLE_CLOUD_CPP_PC_REQUIRES@ +Version: @DOXYGEN_PROJECT_NUMBER@ + +Libs: -L${libdir} @GOOGLE_CLOUD_CPP_PC_LIBS@ +Cflags: -I${includedir} From 620940a411b3723e1641dc253e5a15d27852f515 Mon Sep 17 00:00:00 2001 From: Carlos O'Ryan Date: Mon, 1 Jul 2019 14:39:09 -0400 Subject: [PATCH 02/34] Fix installation path for protos. --- CMakeLists.txt | 2 +- cmake/CompileProtos.cmake | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index edc8f2320..d9894ff28 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -267,7 +267,7 @@ install(TARGETS ${googleapis_cpp_installed_libraries_list} foreach (target ${googleapis_cpp_installed_libraries_list}) google_cloud_cpp_install_proto_library_headers("${target}") - google_cloud_cpp_install_proto_library_protos("${target}") + google_cloud_cpp_install_proto_library_protos("${target}" "${GOOGLEAPIS_CPP_SOURCE}") endforeach () # Export the CMake targets to make it easy to create configuration files. diff --git a/cmake/CompileProtos.cmake b/cmake/CompileProtos.cmake index a01a90b82..c4bd8982b 100644 --- a/cmake/CompileProtos.cmake +++ b/cmake/CompileProtos.cmake @@ -221,22 +221,22 @@ function (google_cloud_cpp_install_proto_library_headers target) endfunction () # Install protos for a C++ proto library. -function (google_cloud_cpp_install_proto_library_protos target) +function (google_cloud_cpp_install_proto_library_protos target strip_prefix) get_target_property(target_protos ${target} PROTO_SOURCES) - foreach (header ${target_protos}) + foreach (proto ${target_protos}) # Skip anything that is not a header file. - if (NOT "${header}" MATCHES "\\.proto$") + if (NOT "${proto}" MATCHES "\\.proto$") continue() endif () - string(REPLACE "${CMAKE_CURRENT_BINARY_DIR}/" - "" - relative - "${header}") + string(REPLACE "${strip_prefix}/" + "" + relative + "${proto}") get_filename_component(dir "${relative}" DIRECTORY) # This is modeled after the Protobuf library, it installs the basic # protos (think google/protobuf/any.proto) in the include directory for # C/C++ code. :shrug: - install(FILES "${header}" DESTINATION + install(FILES "${proto}" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${dir}") endforeach () endfunction () From aefb8c98b00ffd23543f295b9b5b70532f1afee9 Mon Sep 17 00:00:00 2001 From: Takashi Matsuo Date: Thu, 11 Jul 2019 13:11:32 -0700 Subject: [PATCH 03/34] Add ci scripts (#1) * Add ci scripts * Move config files to ci/kokoro/docker * Remove dump-logs etc * Simplified grpc installation * Add Ubuntu 16.04 kokoro config * Address code review --- CMakeLists.txt | 33 ++- ci/check-style.sh | 81 ++++++++ ci/colors.sh | 28 +++ ci/install-grpc.sh | 41 ++++ ci/kokoro/Dockerfile.centos | 51 +++++ ci/kokoro/Dockerfile.fedora-install | 38 ++++ ci/kokoro/Dockerfile.ubuntu | 81 ++++++++ ci/kokoro/create-docker-image.sh | 28 +++ ci/kokoro/define-docker-variables.sh | 24 +++ ci/kokoro/docker/build-in-docker-cmake.sh | 108 ++++++++++ ci/kokoro/docker/build.sh | 218 ++++++++++++++++++++ ci/kokoro/docker/clang-3.8-presubmit.cfg | 0 ci/kokoro/docker/clang-3.8.cfg | 0 ci/kokoro/docker/clang-tidy-presubmit.cfg | 0 ci/kokoro/docker/clang-tidy.cfg | 0 ci/kokoro/docker/common.cfg | 17 ++ ci/kokoro/docker/gcc-4.8-presubmit.cfg | 0 ci/kokoro/docker/gcc-4.8.cfg | 0 ci/kokoro/docker/ubuntu-16.04-presubmit.cfg | 0 ci/kokoro/docker/ubuntu-16.04.cfg | 0 ci/kokoro/docker/ubuntu-18.04-presubmit.cfg | 0 ci/kokoro/docker/ubuntu-18.04.cfg | 0 ci/retry-command.sh | 48 +++++ cmake/CompileProtos.cmake | 63 ++++-- cmake/FindProtobufTargets.cmake | 8 +- cmake/FindgRPC.cmake | 16 +- 26 files changed, 834 insertions(+), 49 deletions(-) create mode 100755 ci/check-style.sh create mode 100755 ci/colors.sh create mode 100755 ci/install-grpc.sh create mode 100644 ci/kokoro/Dockerfile.centos create mode 100644 ci/kokoro/Dockerfile.fedora-install create mode 100644 ci/kokoro/Dockerfile.ubuntu create mode 100755 ci/kokoro/create-docker-image.sh create mode 100755 ci/kokoro/define-docker-variables.sh create mode 100755 ci/kokoro/docker/build-in-docker-cmake.sh create mode 100755 ci/kokoro/docker/build.sh create mode 100644 ci/kokoro/docker/clang-3.8-presubmit.cfg create mode 100644 ci/kokoro/docker/clang-3.8.cfg create mode 100644 ci/kokoro/docker/clang-tidy-presubmit.cfg create mode 100644 ci/kokoro/docker/clang-tidy.cfg create mode 100644 ci/kokoro/docker/common.cfg create mode 100644 ci/kokoro/docker/gcc-4.8-presubmit.cfg create mode 100644 ci/kokoro/docker/gcc-4.8.cfg create mode 100644 ci/kokoro/docker/ubuntu-16.04-presubmit.cfg create mode 100644 ci/kokoro/docker/ubuntu-16.04.cfg create mode 100644 ci/kokoro/docker/ubuntu-18.04-presubmit.cfg create mode 100644 ci/kokoro/docker/ubuntu-18.04.cfg create mode 100755 ci/retry-command.sh diff --git a/CMakeLists.txt b/CMakeLists.txt index d9894ff28..95a38ba18 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,7 +45,7 @@ set(GOOGLE_CLOUD_CPP_GOOGLEAPIS_SHA256 "6b8a9b2bcb4476e9a5a9872869996f0d639c8d5df76dd8a893e79201f211b1cf") include(ExternalProject) -externalproject_add(googleapis_download +ExternalProject_Add(googleapis_download EXCLUDE_FROM_ALL ON PREFIX "${CMAKE_BINARY_DIR}/external/googleapis" URL ${GOOGLE_CLOUD_CPP_GOOGLEAPIS_URL} @@ -54,7 +54,7 @@ externalproject_add(googleapis_download BUILD_COMMAND "" INSTALL_COMMAND "" LOG_DOWNLOAD OFF) -externalproject_get_property(googleapis_download SOURCE_DIR) +ExternalProject_Get_Property(googleapis_download SOURCE_DIR) set(GOOGLEAPIS_CPP_SOURCE "${SOURCE_DIR}") list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake") @@ -267,7 +267,8 @@ install(TARGETS ${googleapis_cpp_installed_libraries_list} foreach (target ${googleapis_cpp_installed_libraries_list}) google_cloud_cpp_install_proto_library_headers("${target}") - google_cloud_cpp_install_proto_library_protos("${target}" "${GOOGLEAPIS_CPP_SOURCE}") + google_cloud_cpp_install_proto_library_protos("${target}" + "${GOOGLEAPIS_CPP_SOURCE}") endforeach () # Export the CMake targets to make it easy to create configuration files. @@ -275,15 +276,12 @@ install(EXPORT googleapis-targets DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/googleapis") # Setup global variables used in the following *.in files. -set( - GOOGLE_CLOUD_CPP_CONFIG_VERSION_MAJOR ${GOOGLEAPIS_CPP_PROTOS_VERSION_MAJOR} - ) -set( - GOOGLE_CLOUD_CPP_CONFIG_VERSION_MINOR ${GOOGLEAPIS_CPP_PROTOS_VERSION_MINOR} - ) -set( - GOOGLE_CLOUD_CPP_CONFIG_VERSION_PATCH ${GOOGLEAPIS_CPP_PROTOS_VERSION_PATCH} - ) +set(GOOGLE_CLOUD_CPP_CONFIG_VERSION_MAJOR + ${GOOGLEAPIS_CPP_PROTOS_VERSION_MAJOR}) +set(GOOGLE_CLOUD_CPP_CONFIG_VERSION_MINOR + ${GOOGLEAPIS_CPP_PROTOS_VERSION_MINOR}) +set(GOOGLE_CLOUD_CPP_CONFIG_VERSION_PATCH + ${GOOGLEAPIS_CPP_PROTOS_VERSION_PATCH}) # Use a function to create a scope for the variables. function (googleapis_cpp_install_pc target) @@ -322,8 +320,8 @@ function (googleapis_cpp_install_pc target) string(CONCAT GOOGLE_CLOUD_CPP_PC_REQUIRES ${_target_pc_requires}) set(GOOGLE_CLOUD_CPP_PC_LIBS "-l${target}") configure_file("cmake/config.pc.in" "${target}.pc" @ONLY) - install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${target}.pc" DESTINATION - "${CMAKE_INSTALL_LIBDIR}/pkgconfig") + install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${target}.pc" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") endfunction () # Create and install the pkg-config files. @@ -355,8 +353,8 @@ string(CONCAT GOOGLE_CLOUD_CPP_PC_REQUIRES " libcares") set(GOOGLE_CLOUD_CPP_PC_LIBS "") configure_file("cmake/config.pc.in" "googleapis.pc" @ONLY) -install(FILES "${CMAKE_CURRENT_BINARY_DIR}/googleapis.pc" DESTINATION - "${CMAKE_INSTALL_LIBDIR}/pkgconfig") +install(FILES "${CMAKE_CURRENT_BINARY_DIR}/googleapis.pc" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") # Create and install the CMake configuration files. configure_file("cmake/config.cmake.in" "googleapis-config.cmake" @ONLY) @@ -367,5 +365,4 @@ install(FILES "${CMAKE_CURRENT_BINARY_DIR}/googleapis-config.cmake" "${PROJECT_SOURCE_DIR}/cmake/FindgRPC.cmake" "${PROJECT_SOURCE_DIR}/cmake/FindProtobufTargets.cmake" "${PROJECT_SOURCE_DIR}/cmake/CompileProtos.cmake" - DESTINATION - "${CMAKE_INSTALL_LIBDIR}/cmake/googleapis") + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/googleapis") diff --git a/ci/check-style.sh b/ci/check-style.sh new file mode 100755 index 000000000..9fe61bf03 --- /dev/null +++ b/ci/check-style.sh @@ -0,0 +1,81 @@ +#!/usr/bin/env bash +# Copyright 2019 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 +# +# http://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. + +set -eu + +if [[ "${CHECK_STYLE}" != "yes" ]]; then + echo "Skipping code style check as it is disabled for this build." + exit 0 +fi + +# This script assumes it is running the top-level google-cloud-cpp directory. + +readonly BINDIR="$(dirname "$0")" + +# Build paths to ignore in find(1) commands by reading .gitignore. +declare -a ignore=( -path ./.git ) +if [[ -f .gitignore ]]; then + while read -r line; do + case "${line}" in + [^#]*/*) ignore+=( -o -path "./$(expr "${line}" : '\(.*\)/')" ) ;; + [^#]*) ignore+=( -o -name "${line}" ) ;; + esac + done < .gitignore +fi + +replace_original_if_changed() { + if [[ $# != 2 ]]; then + return 1 + fi + + local original="$1" + local reformatted="$2" + + if cmp -s "${original}" "${reformatted}"; then + rm -f "${reformatted}" + else + chmod --reference="${original}" "${reformatted}" + mv -f "${reformatted}" "${original}" + fi +} + +# Apply cmake_format to all the CMake list files. +# https://github.com/cheshirekow/cmake_format +find . \( "${ignore[@]}" \) -prune -o \ + \( -name 'CMakeLists.txt' -o -name '*.cmake' \) \ + -print0 | + while IFS= read -r -d $'\0' file; do + cmake-format "${file}" >"${file}.tmp" + replace_original_if_changed "${file}" "${file}.tmp" + done + +# Apply buildifier to fix the BUILD and .bzl formatting rules. +# https://github.com/bazelbuild/buildtools/tree/master/buildifier +find . \( "${ignore[@]}" \) -prune -o \ + \( -name BUILD -o -name '*.bzl' \) \ + -print0 | + xargs -0 buildifier -mode=fix + +# Apply shellcheck(1) to emit warnings for common scripting mistakes. +find . \( "${ignore[@]}" \) -prune -o \ + -iname '*.sh' -exec shellcheck \ + --exclude=SC1090 \ + --exclude=SC2034 \ + --exclude=SC2153 \ + --exclude=SC2181 \ + '{}' \; + +# Report any differences created by running the formatting tools. +git diff --ignore-submodules=all --color --exit-code . diff --git a/ci/colors.sh b/ci/colors.sh new file mode 100755 index 000000000..23acd8e03 --- /dev/null +++ b/ci/colors.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash +# Copyright 2019 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 +# +# http://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. + +if [ -z "${COLOR_RESET+x}" ]; then + if type tput >/dev/null 2>&1; then + readonly COLOR_RED="$(tput setaf 1)" + readonly COLOR_GREEN="$(tput setaf 2)" + readonly COLOR_YELLOW="$(tput setaf 3)" + readonly COLOR_RESET="$(tput sgr0)" + else + readonly COLOR_RED="" + readonly COLOR_GREEN="" + readonly COLOR_YELLOW="" + readonly COLOR_RESET="" + fi +fi diff --git a/ci/install-grpc.sh b/ci/install-grpc.sh new file mode 100755 index 000000000..759b355bb --- /dev/null +++ b/ci/install-grpc.sh @@ -0,0 +1,41 @@ +#!/usr/bin/env bash +# Copyright 2019 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 +# +# http://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. + +set -eu + +mkdir -p /var/tmp/Downloads +cd /var/tmp/Downloads + +# Install protobuf +wget -q https://github.com/google/protobuf/archive/v3.8.0.tar.gz +tar -xf v3.8.0.tar.gz +(cd protobuf-3.8.0/cmake; + cmake \ + -DCMAKE_BUILD_TYPE=Release \ + -DBUILD_SHARED_LIBS=yes \ + -Dprotobuf_BUILD_TESTS=OFF \ + -H. -Bcmake-out + cmake --build cmake-out --target install -- -j "$(nproc)" + ldconfig +) + +# Install grpc +wget -q https://github.com/grpc/grpc/archive/v1.22.0.tar.gz +tar -xf v1.22.0.tar.gz +(cd grpc-1.22.0; + make -j "$(nproc)" + make install + ldconfig +) diff --git a/ci/kokoro/Dockerfile.centos b/ci/kokoro/Dockerfile.centos new file mode 100644 index 000000000..2982dae0e --- /dev/null +++ b/ci/kokoro/Dockerfile.centos @@ -0,0 +1,51 @@ +# Copyright 2019 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 +# +# http://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. + +ARG DISTRO_VERSION=7 +FROM centos:${DISTRO_VERSION} + +# Add /usr/local/lib + +# Search paths tweak for the build +ENV PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/local/lib64/pkgconfig +ENV LD_LIBRARY_PATH=/usr/local/lib:/usr/local/lib64 +ENV PATH=/usr/local/bin:${PATH} + +# First install the development tools and OpenSSL. The development tools +# distributed with CentOS (notably CMake) are too old to build +# `google-cloud-cpp`. In these instructions, we use `cmake3` obtained from +# [Software Collections](https://www.softwarecollections.org/). + +RUN rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm +RUN yum install -y centos-release-scl +RUN yum-config-manager --enable rhel-server-rhscl-7-rpms +RUN yum makecache && \ + yum install -y automake cmake3 curl-devel gcc gcc-c++ git libtool \ + make openssl-devel pkgconfig tar wget which zlib-devel +RUN ln -sf /usr/bin/cmake3 /usr/bin/cmake && ln -sf /usr/bin/ctest3 /usr/bin/ctest + +# Install c-ares +RUN mkdir -p /var/tmp/Downloads; \ + cd /var/tmp/Downloads; \ + wget -q https://github.com/c-ares/c-ares/archive/cares-1_15_0.tar.gz; \ + tar -xf cares-1_15_0.tar.gz; \ + cd /var/tmp/Downloads/c-ares-cares-1_15_0; \ + ./buildconf && ./configure && make -j $(nproc); \ + make install; \ + ldconfig + +# Install grpc from source +WORKDIR /var/tmp/ci +COPY install-grpc.sh /var/tmp/ci +RUN /var/tmp/ci/install-grpc.sh diff --git a/ci/kokoro/Dockerfile.fedora-install b/ci/kokoro/Dockerfile.fedora-install new file mode 100644 index 000000000..af3aa3803 --- /dev/null +++ b/ci/kokoro/Dockerfile.fedora-install @@ -0,0 +1,38 @@ +# Copyright 2019 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 +# +# http://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. + +ARG DISTRO_VERSION=30 +FROM fedora:${DISTRO_VERSION} + +# Fedora includes packages for gRPC, libcurl, and OpenSSL that are recent enough +# for `google-cloud-cpp`. Install these packages and additional development +# tools to compile the dependencies: +RUN dnf makecache && \ + dnf install -y clang clang-tools-extra cmake doxygen findutils gcc-c++ git \ + grpc-devel grpc-plugins libcxx-devel libcxxabi-devel libcurl-devel \ + make openssl-devel pkgconfig protobuf-compiler python-pip ShellCheck \ + tar wget zlib-devel + +# Install the the buildifier tool, which does not compile with the default +# golang compiler for Ubuntu 16.04 and Ubuntu 18.04. +RUN wget -q -O /usr/bin/buildifier https://github.com/bazelbuild/buildtools/releases/download/0.17.2/buildifier +RUN chmod 755 /usr/bin/buildifier + +# Install cmake_format to automatically format the CMake list files. +# https://github.com/cheshirekow/cmake_format +# Pin this to an specific version because the formatting changes when the +# "latest" version is updated, and we do not want the builds to break just +# because some third party changed something. +RUN pip install --upgrade pip +RUN pip install numpy cmake_format==0.5.2 diff --git a/ci/kokoro/Dockerfile.ubuntu b/ci/kokoro/Dockerfile.ubuntu new file mode 100644 index 000000000..32af422de --- /dev/null +++ b/ci/kokoro/Dockerfile.ubuntu @@ -0,0 +1,81 @@ +# Copyright 2019 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 +# +# http://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. + +ARG DISTRO_VERSION=18.04 +FROM ubuntu:${DISTRO_VERSION} + +RUN apt update && \ + apt install -y \ + build-essential \ + clang \ + cmake \ + curl \ + doxygen \ + gawk \ + git \ + gcc \ + golang \ + g++ \ + libc-ares-dev \ + libc-ares2 \ + libssl-dev \ + make \ + ninja-build \ + pkg-config \ + python-pip \ + shellcheck \ + tar \ + unzip \ + wget \ + zlib1g-dev + +# Install newer c-ares on Ubuntu 16.04. +RUN if grep -q 16.04 /etc/lsb-release; then \ + apt remove libc-ares-dev libc-ares2; \ + apt install -y automake libtool; \ + mkdir -p /var/tmp/Downloads; \ + cd /var/tmp/Downloads; \ + wget -q https://github.com/c-ares/c-ares/archive/cares-1_15_0.tar.gz; \ + tar -xf cares-1_15_0.tar.gz; \ + cd /var/tmp/Downloads/c-ares-cares-1_15_0; \ + ./buildconf && ./configure && make -j $(nproc); \ + make install; \ + ldconfig; \ + fi + +# By default, Ubuntu 18.04 does not install the alternatives for clang-format +# and clang-tidy, so we need to manually install those. +RUN if grep -q 18.04 /etc/lsb-release; then \ + apt update && apt install -y clang-tidy clang-format-7; \ + update-alternatives --install /usr/bin/clang-tidy clang-tidy /usr/bin/clang-tidy-6.0 100; \ + update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-7 100; \ + fi + +# Install the the buildifier tool, which does not compile with the default +# golang compiler for Ubuntu 16.04 and Ubuntu 18.04. +RUN wget -q -O /usr/bin/buildifier https://github.com/bazelbuild/buildtools/releases/download/0.17.2/buildifier +RUN chmod 755 /usr/bin/buildifier + +# Install cmake_format to automatically format the CMake list files. +# https://github.com/cheshirekow/cmake_format +# Pin this to an specific version because the formatting changes when the +# "latest" version is updated, and we do not want the builds to break just +# because some third party changed something. +RUN pip install --upgrade pip +RUN pip install numpy cmake_format==0.5.2 + +# Install grpc from source +WORKDIR /var/tmp/ci +COPY install-grpc.sh /var/tmp/ci +RUN /var/tmp/ci/install-grpc.sh diff --git a/ci/kokoro/create-docker-image.sh b/ci/kokoro/create-docker-image.sh new file mode 100755 index 000000000..df1d7af12 --- /dev/null +++ b/ci/kokoro/create-docker-image.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash +# Copyright 2019 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 +# +# http://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. + +set -eu + +# Create a Docker image with all the dependencies necessary to build the +# project. +if [[ -z "${PROJECT_ROOT+x}" ]]; then + readonly PROJECT_ROOT="$(cd "$(dirname "$0")/../.."; pwd)" +fi +source "${PROJECT_ROOT}/ci/kokoro/define-docker-variables.sh" + +cd "${PROJECT_ROOT}" +sudo docker build -t "${IMAGE}:tip" \ + --build-arg DISTRO_VERSION="${DISTRO_VERSION}" \ + -f "ci/kokoro/Dockerfile.${DISTRO}" ci diff --git a/ci/kokoro/define-docker-variables.sh b/ci/kokoro/define-docker-variables.sh new file mode 100755 index 000000000..7a659c7a7 --- /dev/null +++ b/ci/kokoro/define-docker-variables.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash +# Copyright 2019 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 +# +# http://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. + +set -eu + +if [[ -n "${IMAGE+x}" ]]; then + echo "IMAGE is already defined." +else + readonly IMAGE="apisci-${DISTRO}-${DISTRO_VERSION}" + readonly BUILD_OUTPUT="cmake-out/${IMAGE}-${BUILD_NAME}" + readonly BUILD_HOME="cmake-out/home/${IMAGE}-${BUILD_NAME}" +fi diff --git a/ci/kokoro/docker/build-in-docker-cmake.sh b/ci/kokoro/docker/build-in-docker-cmake.sh new file mode 100755 index 000000000..38e0d3d78 --- /dev/null +++ b/ci/kokoro/docker/build-in-docker-cmake.sh @@ -0,0 +1,108 @@ +#!/usr/bin/env bash +# Copyright 2019 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 +# +# http://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. + +set -eu + +if [[ $# != 2 ]]; then + echo "Usage: $(basename "$0") " + exit 1 +fi + +readonly SOURCE_DIR="$1" +readonly BINARY_DIR="$2" + +# This script is supposed to run inside a Docker container, see +# ci/kokoro/cmake/installed-dependencies/build.sh for the expected setup. The +# /v directory is a volume pointing to a (clean-ish) checkout of the project: +if [[ -z "${PROJECT_ROOT+x}" ]]; then + readonly PROJECT_ROOT="/v" +fi +source "${PROJECT_ROOT}/ci/colors.sh" + +echo +echo "${COLOR_YELLOW}Starting docker build $(date) with $(nproc) cores${COLOR_RESET}" +echo + +echo "================================================================" +echo "Verify formatting $(date)" +(cd "${PROJECT_ROOT}" ; ./ci/check-style.sh) +echo "================================================================" + +echo "================================================================" +echo "Compiling on $(date)" +echo "================================================================" +cd "${PROJECT_ROOT}" +cmake_flags=() +if [[ "${CLANG_TIDY:-}" = "yes" ]]; then + cmake_flags+=("-DGOOGLE_CLOUD_CPP_CLANG_TIDY=yes") +fi +if [[ "${GOOGLE_CLOUD_CPP_CXX_STANDARD:-}" != "" ]]; then + cmake_flags+=( + "-DGOOGLE_CLOUD_CPP_CXX_STANDARD=${GOOGLE_CLOUD_CPP_CXX_STANDARD}") +fi + +if [[ "${CODE_COVERAGE:-}" == "yes" ]]; then + cmake_flags+=( + "-DCMAKE_BUILD_TYPE=Coverage") +fi + +# Avoid unbound variable error with older bash +if [[ "${#cmake_flags[@]}" == 0 ]]; then + cmake "-H${SOURCE_DIR}" "-B${BINARY_DIR}" +else + cmake "-H${SOURCE_DIR}" "-B${BINARY_DIR}" "${cmake_flags[@]}" +fi +cmake --build "${BINARY_DIR}" -- -j "$(nproc)" + +# When user a super-build the tests are hidden in a subdirectory. We can tell +# that ${BINARY_DIR} does not have the tests by checking for this file: +if [[ -r "${BINARY_DIR}/CTestTestfile.cmake" ]]; then + echo "================================================================" + # It is Okay to skip the tests in this case because the super build + # automatically runs them. + echo "Running the unit tests $(date)" + env -C "${BINARY_DIR}" ctest \ + -LE integration-tests \ + --output-on-failure -j "$(nproc)" + echo "================================================================" +fi + +if [[ "${GENERATE_DOCS:-}" = "yes" ]]; then + echo "================================================================" + echo "Validate Doxygen documentation $(date)" + cmake --build "${BINARY_DIR}" --target doxygen-docs + echo "================================================================" +fi + +if [[ ${RUN_INTEGRATION_TESTS} == "yes" ]]; then + echo "================================================================" + echo "Running the integration tests $(date)" + echo "================================================================" + # shellcheck disable=SC1091 + source /c/spanner-integration-tests-config.sh + export GOOGLE_APPLICATION_CREDENTIALS=/c/spanner-credentials.json + + # Run the integration tests too. + env -C "${BINARY_DIR}" ctest \ + -L integration-tests \ + --output-on-failure + echo "================================================================" +fi + +echo "================================================================" +echo "Build finished at $(date)" +echo "================================================================" + +exit 0 diff --git a/ci/kokoro/docker/build.sh b/ci/kokoro/docker/build.sh new file mode 100755 index 000000000..a8dd2492f --- /dev/null +++ b/ci/kokoro/docker/build.sh @@ -0,0 +1,218 @@ +#!/usr/bin/env bash +# Copyright 2019 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 +# +# http://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. + +set -eu + +export CC=gcc +export CXX=g++ +export DISTRO=ubuntu +export DISTRO_VERSION=18.04 +export CMAKE_SOURCE_DIR="." + +in_docker_script="ci/kokoro/docker/build-in-docker-cmake.sh" + +if [[ $# -eq 1 ]]; then + export BUILD_NAME="${1}" +elif [[ -n "${KOKORO_JOB_NAME:-}" ]]; then + # Kokoro injects the KOKORO_JOB_NAME environment variable, the value of this + # variable is cloud-cpp/spanner/ (or more + # generally ). By convention we name these + # files `$foo.cfg` for continuous builds and `$foo-presubmit.cfg` for + # presubmit builds. Here we extract the value of "foo" and use it as the build + # name. + BUILD_NAME="$(basename "${KOKORO_JOB_NAME}" "-presubmit")" + export BUILD_NAME +else + echo "Aborting build as the build name is not defined." + echo "If you are invoking this script via the command line use:" + echo " $0 " + echo + echo "If this script is invoked by Kokoro, the CI system is expected to set" + echo "the KOKORO_JOB_NAME environment variable." + exit 1 +fi + +if [[ "${BUILD_NAME}" = "clang-tidy" ]]; then + # Compile with clang-tidy(1) turned on. The build treats clang-tidy warnings + # as errors. + export DISTRO=fedora-install + export DISTRO_VERSION=30 + export CC=clang + export CXX=clang++ + export CHECK_STYLE=yes + export CLANG_TIDY=yes +elif [[ "${BUILD_NAME}" = "ubuntu-18.04" ]]; then + export CC=gcc + export CXX=g++ +elif [[ "${BUILD_NAME}" = "ubuntu-16.04" ]]; then + export DISTRO_VERSION=16.04 + export CC=gcc + export CXX=g++ +elif [[ "${BUILD_NAME}" = "gcc-4.8" ]]; then + # The oldest version of GCC we support is 4.8, this build checks the code + # against that version. The use of CentOS 7 for that build is not a + # coincidence: the reason we support GCC 4.8 is to support this distribution + # (and its commercial cousin: RHEL 7). + export CC=gcc + export CXX=g++ + export DISTRO=centos + export DISTRO_VERSION=7 +elif [[ "${BUILD_NAME}" = "clang-3.8" ]]; then + # The oldest version of Clang we actively test is 3.8. There is nothing + # particularly interesting about that version. It is simply the version + # included with Ubuntu:16.04, and the oldest version tested by + # google-cloud-cpp. + export DISTRO=ubuntu + export DISTRO_VERSION=16.04 + export CC=clang + export CXX=clang++ +else + echo "Unknown BUILD_NAME (${BUILD_NAME}). Fix the Kokoro .cfg file." + exit 1 +fi + +if [[ -z "${PROJECT_ROOT+x}" ]]; then + readonly PROJECT_ROOT="$(cd "$(dirname "$0")/../../.."; pwd)" +fi +source "${PROJECT_ROOT}/ci/kokoro/define-docker-variables.sh" + +echo "================================================================" +cd "${PROJECT_ROOT}" +echo "Building with $(nproc) cores $(date) on ${PWD}." + +echo "================================================================" +echo "Capture Docker version to troubleshoot $(date)." +sudo docker version +echo "================================================================" + +echo "================================================================" +echo "Creating Docker image with all the development tools $(date)." +# We do not want to print the log unless there is an error, so disable the -e +# flag. Later, we will want to print out the emulator(s) logs *only* if there +# is an error, so disabling from this point on is the right choice. +set +e +mkdir -p "${BUILD_OUTPUT}" +readonly CREATE_DOCKER_IMAGE_LOG="${BUILD_OUTPUT}/create-build-docker-image.log" +echo "Logging to ${CREATE_DOCKER_IMAGE_LOG}" +if ! "${PROJECT_ROOT}/ci/retry-command.sh" \ + "${PROJECT_ROOT}/ci/kokoro/create-docker-image.sh" \ + >"${CREATE_DOCKER_IMAGE_LOG}" 2>&1 to CMake. + "--env" "GOOGLE_CLOUD_CPP_CXX_STANDARD=${GOOGLE_CLOUD_CPP_CXX_STANDARD:-}" + + # When running the integration tests this directory contains the + # configuration files needed to run said tests. Make it available inside + # the Docker container. + "--volume" "${KOKORO_GFILE_DIR:-/dev/shm}:/c" + + # Let the Docker image script know what kind of terminal we are using, that + # produces properly colorized error messages. + "--env" "TERM=${TERM:-dumb}" + + # Run the docker script and this user id. Because the docker image gets to + # write in ${PWD} you typically want this to be your user id. + "--user" "${docker_uid}" + + # Bazel needs this environment variable to work correctly. + "--env" "USER=${docker_user}" + + # We give Bazel and CMake a fake $HOME inside the docker image. Bazel caches + # build byproducts in this directory. CMake (when ccache is enabled) uses + # it to store $HOME/.ccache + "--env" "HOME=/h" + "--volume" "${PWD}/${BUILD_HOME}:/h" + + # Mount the current directory (which is the top-level directory for the + # project) as `/v` inside the docker image, and move to that directory. + "--volume" "${PWD}:/v" + "--workdir" "/v" + + # Mask any other builds that may exist at the same time. That is, these + # directories appear as empty inside the Docker container, this prevents the + # container from writing into other builds, or to get confused by the output + # of other builds. In the CI system this does not matter, as each build runs + # on a completely separate VM. This is useful when running multiple builds + # in your workstation. + "--volume" "/v/cmake-out/home" + "--volume" "/v/cmake-out" + "--volume" "${PWD}/${BUILD_OUTPUT}:/v/${BUILD_OUTPUT}" +) + +# When running the builds from the command-line they get a tty, and the scripts +# running inside the Docker container can produce nicer output. On Kokoro the +# script does not get a tty, and Docker terminates the program if we pass the +# `-it` flag. +if [[ -t 0 ]]; then + docker_flags+=("-it") +fi + +sudo docker run "${docker_flags[@]}" "${IMAGE}:tip" \ + "/v/${in_docker_script}" "${CMAKE_SOURCE_DIR}" \ + "${BUILD_OUTPUT}" diff --git a/ci/kokoro/docker/clang-3.8-presubmit.cfg b/ci/kokoro/docker/clang-3.8-presubmit.cfg new file mode 100644 index 000000000..e69de29bb diff --git a/ci/kokoro/docker/clang-3.8.cfg b/ci/kokoro/docker/clang-3.8.cfg new file mode 100644 index 000000000..e69de29bb diff --git a/ci/kokoro/docker/clang-tidy-presubmit.cfg b/ci/kokoro/docker/clang-tidy-presubmit.cfg new file mode 100644 index 000000000..e69de29bb diff --git a/ci/kokoro/docker/clang-tidy.cfg b/ci/kokoro/docker/clang-tidy.cfg new file mode 100644 index 000000000..e69de29bb diff --git a/ci/kokoro/docker/common.cfg b/ci/kokoro/docker/common.cfg new file mode 100644 index 000000000..213d93419 --- /dev/null +++ b/ci/kokoro/docker/common.cfg @@ -0,0 +1,17 @@ +# Format: //devtools/kokoro/config/proto/build.proto +# Copyright 2019 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 +# +# http://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. + +build_file: "cpp-cmakefiles/ci/kokoro/docker/build.sh" +timeout_mins: 120 diff --git a/ci/kokoro/docker/gcc-4.8-presubmit.cfg b/ci/kokoro/docker/gcc-4.8-presubmit.cfg new file mode 100644 index 000000000..e69de29bb diff --git a/ci/kokoro/docker/gcc-4.8.cfg b/ci/kokoro/docker/gcc-4.8.cfg new file mode 100644 index 000000000..e69de29bb diff --git a/ci/kokoro/docker/ubuntu-16.04-presubmit.cfg b/ci/kokoro/docker/ubuntu-16.04-presubmit.cfg new file mode 100644 index 000000000..e69de29bb diff --git a/ci/kokoro/docker/ubuntu-16.04.cfg b/ci/kokoro/docker/ubuntu-16.04.cfg new file mode 100644 index 000000000..e69de29bb diff --git a/ci/kokoro/docker/ubuntu-18.04-presubmit.cfg b/ci/kokoro/docker/ubuntu-18.04-presubmit.cfg new file mode 100644 index 000000000..e69de29bb diff --git a/ci/kokoro/docker/ubuntu-18.04.cfg b/ci/kokoro/docker/ubuntu-18.04.cfg new file mode 100644 index 000000000..e69de29bb diff --git a/ci/retry-command.sh b/ci/retry-command.sh new file mode 100755 index 000000000..190bce481 --- /dev/null +++ b/ci/retry-command.sh @@ -0,0 +1,48 @@ +#!/usr/bin/env bash +# Copyright 2019 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 +# +# http://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. + +set -eu + +# Make three attempts to install the dependencies. It is rare, but from time to +# time the downloading the packages, building the Docker images, or an installer +# Bazel, or the Google Cloud SDK fails. To make the CI build more robust, try +# again when that happens. + +if (( $# < 1 )); then + echo "Usage: $(basename "$0") program [arguments]" + exit 1 +fi +readonly PROGRAM=${1} +shift + +# Initially, wait at least 2 minutes (the times are in seconds), because it +# makes no sense to try faster. This used to be 180 seconds, but that ends with +# sleeps close to 10 minutes, and Travis aborts builds that do not output in +# 10m. +min_wait=120 +# Do not exit on failures for this loop. +set +e +for i in 1 2 3; do + if "${PROGRAM}" "$@"; then + exit 0 + fi + # Sleep for a few minutes before trying again. + period=$(( (RANDOM % 60) + min_wait )) + echo "${PROGRAM} failed (attempt ${i}); trying again in ${period} seconds." + sleep ${period}s + min_wait=$(( min_wait * 2 )) +done + +exit 1 diff --git a/cmake/CompileProtos.cmake b/cmake/CompileProtos.cmake index c4bd8982b..37e71040d 100644 --- a/cmake/CompileProtos.cmake +++ b/cmake/CompileProtos.cmake @@ -54,7 +54,11 @@ endfunction () # `foo/bar/baz.proto` then the directory containing `foo` must be in the search # path. function (google_cloud_cpp_generate_proto SRCS) - cmake_parse_arguments(_opt "" "" "PROTO_PATH_DIRECTORIES" ${ARGN}) + cmake_parse_arguments(_opt + "" + "" + "PROTO_PATH_DIRECTORIES" + ${ARGN}) if (NOT _opt_UNPARSED_ARGUMENTS) message(SEND_ERROR "Error: google_cloud_cpp_generate_proto() called" " without any proto files") @@ -100,14 +104,19 @@ function (google_cloud_cpp_generate_proto SRCS) OUTPUT "${pb_cc}" "${pb_h}" COMMAND $ ARGS - --cpp_out "${CMAKE_CURRENT_BINARY_DIR}" - ${protobuf_include_path} "${filename}" + --cpp_out + "${CMAKE_CURRENT_BINARY_DIR}" + ${protobuf_include_path} + "${filename}" DEPENDS "${filename}" protobuf::protoc COMMENT "Running C++ protocol buffer compiler on ${filename}" VERBATIM) endforeach () - set_source_files_properties(${${SRCS}} PROPERTIES GENERATED TRUE) + set_source_files_properties(${${SRCS}} + PROPERTIES + GENERATED + TRUE) set(${SRCS} ${${SRCS}} PARENT_SCOPE) endfunction () @@ -138,7 +147,11 @@ endfunction () # `foo/bar/baz.proto` then the directory containing `foo` must be in the search # path. function (google_cloud_cpp_generate_grpcpp SRCS) - cmake_parse_arguments(_opt "" "" "PROTO_PATH_DIRECTORIES" ${ARGN}) + cmake_parse_arguments(_opt + "" + "" + "PROTO_PATH_DIRECTORIES" + ${ARGN}) if (NOT _opt_UNPARSED_ARGUMENTS) message( SEND_ERROR "Error: google_cloud_cpp_generate_grpc() called without" @@ -188,15 +201,19 @@ function (google_cloud_cpp_generate_grpcpp SRCS) $ ARGS --plugin=protoc-gen-grpc=$ - "--grpc_out=${CMAKE_CURRENT_BINARY_DIR}" - "--cpp_out=${CMAKE_CURRENT_BINARY_DIR}" - ${protobuf_include_path} "${filename}" + "--grpc_out=${CMAKE_CURRENT_BINARY_DIR}" + "--cpp_out=${CMAKE_CURRENT_BINARY_DIR}" + ${protobuf_include_path} + "${filename}" DEPENDS "${filename}" protobuf::protoc gRPC::grpc_cpp_plugin COMMENT "Running gRPC C++ protocol buffer compiler on ${filename}" VERBATIM) endforeach () - set_source_files_properties(${${SRCS}} PROPERTIES GENERATED TRUE) + set_source_files_properties(${${SRCS}} + PROPERTIES + GENERATED + TRUE) set(${SRCS} ${${SRCS}} PARENT_SCOPE) endfunction () @@ -215,8 +232,8 @@ function (google_cloud_cpp_install_proto_library_headers target) relative "${header}") get_filename_component(dir "${relative}" DIRECTORY) - install(FILES "${header}" DESTINATION - "${CMAKE_INSTALL_INCLUDEDIR}/${dir}") + install(FILES "${header}" + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${dir}") endforeach () endfunction () @@ -228,21 +245,25 @@ function (google_cloud_cpp_install_proto_library_protos target strip_prefix) if (NOT "${proto}" MATCHES "\\.proto$") continue() endif () - string(REPLACE "${strip_prefix}/" - "" - relative - "${proto}") + string(REPLACE "${strip_prefix}/" + "" + relative + "${proto}") get_filename_component(dir "${relative}" DIRECTORY) # This is modeled after the Protobuf library, it installs the basic # protos (think google/protobuf/any.proto) in the include directory for # C/C++ code. :shrug: - install(FILES "${proto}" DESTINATION - "${CMAKE_INSTALL_INCLUDEDIR}/${dir}") + install(FILES "${proto}" + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${dir}") endforeach () endfunction () function (google_cloud_cpp_proto_library libname) - cmake_parse_arguments(_opt "" "" "PROTO_PATH_DIRECTORIES" ${ARGN}) + cmake_parse_arguments(_opt + "" + "" + "PROTO_PATH_DIRECTORIES" + ${ARGN}) if (NOT _opt_UNPARSED_ARGUMENTS) message(SEND_ERROR "Error: google_cloud_cpp_proto_library() called" " without any proto files") @@ -267,7 +288,11 @@ function (google_cloud_cpp_proto_library libname) endfunction () function (google_cloud_cpp_grpcpp_library libname) - cmake_parse_arguments(_opt "" "" "PROTO_PATH_DIRECTORIES" ${ARGN}) + cmake_parse_arguments(_opt + "" + "" + "PROTO_PATH_DIRECTORIES" + ${ARGN}) if (NOT _opt_UNPARSED_ARGUMENTS) message(SEND_ERROR "Error: google_cloud_cpp_proto_library() called" " without any proto files") diff --git a/cmake/FindProtobufTargets.cmake b/cmake/FindProtobufTargets.cmake index db260280d..28cb36fca 100644 --- a/cmake/FindProtobufTargets.cmake +++ b/cmake/FindProtobufTargets.cmake @@ -99,14 +99,14 @@ if (protobuf_FOUND) "ProtobufTargets_FOUND = ${ProtobufTargets_FOUND}" " ProtobufTargets_VERSION = ${ProtobufTargets_VERSION}") endif () -else() +else () find_package(Protobuf QUIET) if (Protobuf_FOUND) set(ProtobufTargets_FOUND 1) set(ProtobufTargets_VERSION ${Protobuf_VERSION}) if (NOT TARGET protobuf::libprotobuf) - add_library(protobuf::libprotobuf INTERFACE IMPORTED) + add_library(protobuf::libprotobuf IMPORTED INTERFACE) set_property(TARGET protobuf::libprotobuf PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${Protobuf_INCLUDE_DIR}) @@ -117,7 +117,7 @@ else() endif () if (NOT TARGET protobuf::libprotobuf-lite) - add_library(protobuf::libprotobuf-lite INTERFACE IMPORTED) + add_library(protobuf::libprotobuf-lite IMPORTED INTERFACE) set_property(TARGET protobuf::libprotobuf-lite PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${Protobuf_INCLUDE_DIR}) @@ -128,7 +128,7 @@ else() endif () if (NOT TARGET protobuf::libprotoc) - add_library(protobuf::libprotoc INTERFACE IMPORTED) + add_library(protobuf::libprotoc IMPORTED INTERFACE) set_property(TARGET protobuf::libprotoc PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${Protobuf_INCLUDE_DIR}) diff --git a/cmake/FindgRPC.cmake b/cmake/FindgRPC.cmake index 5895cf067..9db315ad4 100644 --- a/cmake/FindgRPC.cmake +++ b/cmake/FindgRPC.cmake @@ -95,7 +95,7 @@ function (_grpc_fix_grpc_cpp_plugin_target) set_property(TARGET gRPC::grpc_cpp_plugin PROPERTY IMPORTED_LOCATION ${_gRPC_CPP_PLUGIN_EXECUTABLE}) - else() + else () set(gRPC_FOUND "grpc_cpp_plugin-NOTFOUND") endif () endif () @@ -140,7 +140,7 @@ function (_gRPC_find_library name filename) if (${name}_LIBRARY) # Use result recorded by a previous call. return() - else() + else () find_library(${name}_LIBRARY_RELEASE NAMES ${filename}) mark_as_advanced(${name}_LIBRARY_RELEASE) @@ -171,7 +171,7 @@ if (_gRPC_USE_STATIC_LIBS) set(_gRPC_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES}) if (WIN32) set(CMAKE_FIND_LIBRARY_SUFFIXES .lib .a ${CMAKE_FIND_LIBRARY_SUFFIXES}) - else() + else () set(CMAKE_FIND_LIBRARY_SUFFIXES .a) endif () endif () @@ -195,7 +195,7 @@ endif () if (_gRPC_grpc_LIBRARY) if (NOT TARGET gRPC::grpc) - add_library(gRPC::grpc UNKNOWN IMPORTED) + add_library(gRPC::grpc IMPORTED UNKNOWN) set_target_properties(gRPC::grpc PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${_gRPC_INCLUDE_DIR}") @@ -229,7 +229,7 @@ endif () if (_gRPC_grpc++_LIBRARY) if (NOT TARGET gRPC::grpc++) - add_library(gRPC::grpc++ UNKNOWN IMPORTED) + add_library(gRPC::grpc++ IMPORTED UNKNOWN) set_target_properties(gRPC::grpc++ PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${_gRPC++_INCLUDE_DIR}") @@ -266,17 +266,17 @@ if (_gRPC_grpc++_LIBRARY) set_property(TARGET gRPC::grpc++ APPEND PROPERTY INTERFACE_COMPILE_FEATURES cxx_std_11) - elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") + elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") # CMake 3.5 is still alive and kicking in some older distros, use # the compiler-specific versions in these cases. set_property(TARGET gRPC::grpc++ APPEND PROPERTY INTERFACE_COMPILE_OPTIONS "-std=c++11") - elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") set_property(TARGET gRPC::grpc++ APPEND PROPERTY INTERFACE_COMPILE_OPTIONS "-std=c++11") - else() + else () message( WARNING "gRPC::grpc++ requires C++11, but this module" From d6e90be651ccc153840fd6a118ae6f50fb0fd9f5 Mon Sep 17 00:00:00 2001 From: Takashi Matsuo Date: Fri, 12 Jul 2019 10:12:30 -0700 Subject: [PATCH 04/34] Refactor Dockerfiles (#6) --- ...rfile.fedora-install => Dockerfile.fedora} | 0 ci/kokoro/Dockerfile.ubuntu | 81 ------------------- ci/kokoro/Dockerfile.ubuntu-16.04 | 53 ++++++++++++ ci/kokoro/Dockerfile.ubuntu-18.04 | 45 +++++++++++ ci/kokoro/create-docker-image.sh | 13 ++- ci/kokoro/docker/build.sh | 2 +- 6 files changed, 109 insertions(+), 85 deletions(-) rename ci/kokoro/{Dockerfile.fedora-install => Dockerfile.fedora} (100%) delete mode 100644 ci/kokoro/Dockerfile.ubuntu create mode 100644 ci/kokoro/Dockerfile.ubuntu-16.04 create mode 100644 ci/kokoro/Dockerfile.ubuntu-18.04 diff --git a/ci/kokoro/Dockerfile.fedora-install b/ci/kokoro/Dockerfile.fedora similarity index 100% rename from ci/kokoro/Dockerfile.fedora-install rename to ci/kokoro/Dockerfile.fedora diff --git a/ci/kokoro/Dockerfile.ubuntu b/ci/kokoro/Dockerfile.ubuntu deleted file mode 100644 index 32af422de..000000000 --- a/ci/kokoro/Dockerfile.ubuntu +++ /dev/null @@ -1,81 +0,0 @@ -# Copyright 2019 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 -# -# http://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. - -ARG DISTRO_VERSION=18.04 -FROM ubuntu:${DISTRO_VERSION} - -RUN apt update && \ - apt install -y \ - build-essential \ - clang \ - cmake \ - curl \ - doxygen \ - gawk \ - git \ - gcc \ - golang \ - g++ \ - libc-ares-dev \ - libc-ares2 \ - libssl-dev \ - make \ - ninja-build \ - pkg-config \ - python-pip \ - shellcheck \ - tar \ - unzip \ - wget \ - zlib1g-dev - -# Install newer c-ares on Ubuntu 16.04. -RUN if grep -q 16.04 /etc/lsb-release; then \ - apt remove libc-ares-dev libc-ares2; \ - apt install -y automake libtool; \ - mkdir -p /var/tmp/Downloads; \ - cd /var/tmp/Downloads; \ - wget -q https://github.com/c-ares/c-ares/archive/cares-1_15_0.tar.gz; \ - tar -xf cares-1_15_0.tar.gz; \ - cd /var/tmp/Downloads/c-ares-cares-1_15_0; \ - ./buildconf && ./configure && make -j $(nproc); \ - make install; \ - ldconfig; \ - fi - -# By default, Ubuntu 18.04 does not install the alternatives for clang-format -# and clang-tidy, so we need to manually install those. -RUN if grep -q 18.04 /etc/lsb-release; then \ - apt update && apt install -y clang-tidy clang-format-7; \ - update-alternatives --install /usr/bin/clang-tidy clang-tidy /usr/bin/clang-tidy-6.0 100; \ - update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-7 100; \ - fi - -# Install the the buildifier tool, which does not compile with the default -# golang compiler for Ubuntu 16.04 and Ubuntu 18.04. -RUN wget -q -O /usr/bin/buildifier https://github.com/bazelbuild/buildtools/releases/download/0.17.2/buildifier -RUN chmod 755 /usr/bin/buildifier - -# Install cmake_format to automatically format the CMake list files. -# https://github.com/cheshirekow/cmake_format -# Pin this to an specific version because the formatting changes when the -# "latest" version is updated, and we do not want the builds to break just -# because some third party changed something. -RUN pip install --upgrade pip -RUN pip install numpy cmake_format==0.5.2 - -# Install grpc from source -WORKDIR /var/tmp/ci -COPY install-grpc.sh /var/tmp/ci -RUN /var/tmp/ci/install-grpc.sh diff --git a/ci/kokoro/Dockerfile.ubuntu-16.04 b/ci/kokoro/Dockerfile.ubuntu-16.04 new file mode 100644 index 000000000..8ef65dd9b --- /dev/null +++ b/ci/kokoro/Dockerfile.ubuntu-16.04 @@ -0,0 +1,53 @@ +# Copyright 2019 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 +# +# http://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. + +FROM ubuntu:16.04 + +RUN apt update && \ + apt install -y \ + automake \ + build-essential \ + clang \ + cmake \ + curl \ + doxygen \ + gawk \ + git \ + gcc \ + golang \ + g++ \ + libssl-dev \ + libtool \ + make \ + ninja-build \ + pkg-config \ + python-pip \ + shellcheck \ + tar \ + unzip \ + wget \ + zlib1g-dev + +WORKDIR /var/tmp/Downloads +RUN wget -q https://github.com/c-ares/c-ares/archive/cares-1_15_0.tar.gz && \ + tar -xf cares-1_15_0.tar.gz && \ + cd /var/tmp/Downloads/c-ares-cares-1_15_0 && \ + ./buildconf && ./configure && make -j $(nproc) && \ + make install && \ + ldconfig + +# Install grpc from source +WORKDIR /var/tmp/ci +COPY install-grpc.sh /var/tmp/ci +RUN /var/tmp/ci/install-grpc.sh diff --git a/ci/kokoro/Dockerfile.ubuntu-18.04 b/ci/kokoro/Dockerfile.ubuntu-18.04 new file mode 100644 index 000000000..d3660dafa --- /dev/null +++ b/ci/kokoro/Dockerfile.ubuntu-18.04 @@ -0,0 +1,45 @@ +# Copyright 2019 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 +# +# http://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. + +FROM ubuntu:18.04 + +RUN apt update && \ + apt install -y \ + build-essential \ + clang \ + cmake \ + curl \ + doxygen \ + gawk \ + git \ + gcc \ + golang \ + g++ \ + libc-ares-dev \ + libc-ares2 \ + libssl-dev \ + make \ + ninja-build \ + pkg-config \ + python-pip \ + shellcheck \ + tar \ + unzip \ + wget \ + zlib1g-dev + +# Install grpc from source +WORKDIR /var/tmp/ci +COPY install-grpc.sh /var/tmp/ci +RUN /var/tmp/ci/install-grpc.sh diff --git a/ci/kokoro/create-docker-image.sh b/ci/kokoro/create-docker-image.sh index df1d7af12..82882072f 100755 --- a/ci/kokoro/create-docker-image.sh +++ b/ci/kokoro/create-docker-image.sh @@ -23,6 +23,13 @@ fi source "${PROJECT_ROOT}/ci/kokoro/define-docker-variables.sh" cd "${PROJECT_ROOT}" -sudo docker build -t "${IMAGE}:tip" \ - --build-arg DISTRO_VERSION="${DISTRO_VERSION}" \ - -f "ci/kokoro/Dockerfile.${DISTRO}" ci + +# If there's a version specific Dockerfile, we use it. +if [[ -f "ci/kokoro/Dockerfile.${DISTRO}-${DISTRO_VERSION}" ]]; then + sudo docker build -t "${IMAGE}:tip" \ + -f "ci/kokoro/Dockerfile.${DISTRO}-${DISTRO_VERSION}" ci +else + sudo docker build -t "${IMAGE}:tip" \ + --build-arg DISTRO_VERSION="${DISTRO_VERSION}" \ + -f "ci/kokoro/Dockerfile.${DISTRO}" ci +fi diff --git a/ci/kokoro/docker/build.sh b/ci/kokoro/docker/build.sh index a8dd2492f..b42c49de2 100755 --- a/ci/kokoro/docker/build.sh +++ b/ci/kokoro/docker/build.sh @@ -47,7 +47,7 @@ fi if [[ "${BUILD_NAME}" = "clang-tidy" ]]; then # Compile with clang-tidy(1) turned on. The build treats clang-tidy warnings # as errors. - export DISTRO=fedora-install + export DISTRO=fedora export DISTRO_VERSION=30 export CC=clang export CXX=clang++ From 015e0a3dafe4f7bdd0a4360c8a07248ab34aba2c Mon Sep 17 00:00:00 2001 From: Takashi Matsuo Date: Fri, 12 Jul 2019 15:43:32 -0700 Subject: [PATCH 05/34] Use gcr to cache the docker images (#7) * Use gcr to cache the docker images * Remove sudo from docker command --- ci/kokoro/create-docker-image.sh | 35 ------------ ci/kokoro/define-docker-variables.sh | 24 --------- ci/kokoro/docker/build.sh | 81 ++++++++++++++++++++++------ 3 files changed, 64 insertions(+), 76 deletions(-) delete mode 100755 ci/kokoro/create-docker-image.sh delete mode 100755 ci/kokoro/define-docker-variables.sh diff --git a/ci/kokoro/create-docker-image.sh b/ci/kokoro/create-docker-image.sh deleted file mode 100755 index 82882072f..000000000 --- a/ci/kokoro/create-docker-image.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2019 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 -# -# http://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. - -set -eu - -# Create a Docker image with all the dependencies necessary to build the -# project. -if [[ -z "${PROJECT_ROOT+x}" ]]; then - readonly PROJECT_ROOT="$(cd "$(dirname "$0")/../.."; pwd)" -fi -source "${PROJECT_ROOT}/ci/kokoro/define-docker-variables.sh" - -cd "${PROJECT_ROOT}" - -# If there's a version specific Dockerfile, we use it. -if [[ -f "ci/kokoro/Dockerfile.${DISTRO}-${DISTRO_VERSION}" ]]; then - sudo docker build -t "${IMAGE}:tip" \ - -f "ci/kokoro/Dockerfile.${DISTRO}-${DISTRO_VERSION}" ci -else - sudo docker build -t "${IMAGE}:tip" \ - --build-arg DISTRO_VERSION="${DISTRO_VERSION}" \ - -f "ci/kokoro/Dockerfile.${DISTRO}" ci -fi diff --git a/ci/kokoro/define-docker-variables.sh b/ci/kokoro/define-docker-variables.sh deleted file mode 100755 index 7a659c7a7..000000000 --- a/ci/kokoro/define-docker-variables.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2019 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 -# -# http://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. - -set -eu - -if [[ -n "${IMAGE+x}" ]]; then - echo "IMAGE is already defined." -else - readonly IMAGE="apisci-${DISTRO}-${DISTRO_VERSION}" - readonly BUILD_OUTPUT="cmake-out/${IMAGE}-${BUILD_NAME}" - readonly BUILD_HOME="cmake-out/home/${IMAGE}-${BUILD_NAME}" -fi diff --git a/ci/kokoro/docker/build.sh b/ci/kokoro/docker/build.sh index b42c49de2..87edff528 100755 --- a/ci/kokoro/docker/build.sh +++ b/ci/kokoro/docker/build.sh @@ -86,7 +86,15 @@ fi if [[ -z "${PROJECT_ROOT+x}" ]]; then readonly PROJECT_ROOT="$(cd "$(dirname "$0")/../../.."; pwd)" fi -source "${PROJECT_ROOT}/ci/kokoro/define-docker-variables.sh" + +if [[ -z "${PROJECT_ID+x}" ]]; then + readonly PROJECT_ID="cloud-devrel-kokoro-resources" +fi + +# Determine the image name. +readonly IMAGE="gcr.io/${PROJECT_ID}/cpp-cmakefiles/${DISTRO}-${DISTRO_VERSION}" +readonly BUILD_OUTPUT="cmake-out/${BUILD_NAME}" +readonly BUILD_HOME="cmake-out/home/${BUILD_NAME}" echo "================================================================" cd "${PROJECT_ROOT}" @@ -94,28 +102,66 @@ echo "Building with $(nproc) cores $(date) on ${PWD}." echo "================================================================" echo "Capture Docker version to troubleshoot $(date)." -sudo docker version +docker version echo "================================================================" +has_cache="false" + +if [[ -n "${KOKORO_JOB_NAME:-}" ]]; then + # Download the docker image from the previous build on kokoro for speed. + echo "================================================================" + echo "Downloading Docker image $(date)." + gcloud auth configure-docker + if docker pull "${IMAGE}:latest"; then + echo "Existing image successfully downloaded." + has_cache="true" + fi + echo "================================================================" +fi + +docker_build_flags=( + "-t" "${IMAGE}:latest" +) + +if [[ -f "ci/kokoro/Dockerfile.${DISTRO}-${DISTRO_VERSION}" ]]; then + docker_build_flags+=("-f" "ci/kokoro/Dockerfile.${DISTRO}-${DISTRO_VERSION}") +else + docker_build_flags+=( + "-f" "ci/kokoro/Dockerfile.${DISTRO}" + "--build-arg" "DISTRO_VERSION=${DISTRO_VERSION}" + ) +fi + +if "${has_cache}"; then + docker_build_flags+=("--cache-from=${IMAGE}:latest") +fi + +update_cache="false" echo "================================================================" echo "Creating Docker image with all the development tools $(date)." -# We do not want to print the log unless there is an error, so disable the -e -# flag. Later, we will want to print out the emulator(s) logs *only* if there -# is an error, so disabling from this point on is the right choice. -set +e -mkdir -p "${BUILD_OUTPUT}" -readonly CREATE_DOCKER_IMAGE_LOG="${BUILD_OUTPUT}/create-build-docker-image.log" -echo "Logging to ${CREATE_DOCKER_IMAGE_LOG}" -if ! "${PROJECT_ROOT}/ci/retry-command.sh" \ - "${PROJECT_ROOT}/ci/kokoro/create-docker-image.sh" \ - >"${CREATE_DOCKER_IMAGE_LOG}" 2>&1 Date: Tue, 16 Jul 2019 12:31:19 -0400 Subject: [PATCH 06/34] Add install test (#8) * Add first install test * Fix style * Split the test into spanner and bigtable * Correct indentation * Add other distros, shared lib test, and kokoro configs * Fix style --- ci/kokoro/install/Dockerfile.centos-7 | 105 ++++++++++++++++ ci/kokoro/install/Dockerfile.fedora-30 | 58 +++++++++ ci/kokoro/install/Dockerfile.fedora-30-shared | 58 +++++++++ ci/kokoro/install/Dockerfile.opensuse-leap | 114 ++++++++++++++++++ .../install/Dockerfile.opensuse-tumbleweed | 54 +++++++++ ci/kokoro/install/Dockerfile.ubuntu-16.04 | 100 +++++++++++++++ ci/kokoro/install/Dockerfile.ubuntu-18.04 | 84 +++++++++++++ ci/kokoro/install/build.sh | 106 ++++++++++++++++ ci/kokoro/install/centos-7-presubmit.cfg | 0 ci/kokoro/install/centos-7.cfg | 0 ci/kokoro/install/common.cfg | 17 +++ ci/kokoro/install/fedora-30-presubmit.cfg | 0 .../install/fedora-30-shared-presubmit.cfg | 0 ci/kokoro/install/fedora-30-shared.cfg | 0 ci/kokoro/install/fedora-30.cfg | 0 ci/kokoro/install/opensuse-leap-presubmit.cfg | 0 ci/kokoro/install/opensuse-leap.cfg | 0 .../install/opensuse-tumbleweed-presubmit.cfg | 0 ci/kokoro/install/opensuse-tumbleweed.cfg | 0 ci/kokoro/install/ubuntu-16.04-presubmit.cfg | 0 ci/kokoro/install/ubuntu-16.04.cfg | 0 ci/kokoro/install/ubuntu-18.04-presubmit.cfg | 0 ci/kokoro/install/ubuntu-18.04.cfg | 0 ci/test-install/bigtable/CMakeLists.txt | 28 +++++ ci/test-install/bigtable/main.cc | 22 ++++ ci/test-install/compile-test-projects.sh | 36 ++++++ ci/test-install/spanner/CMakeLists.txt | 28 +++++ ci/test-install/spanner/main.cc | 22 ++++ 28 files changed, 832 insertions(+) create mode 100644 ci/kokoro/install/Dockerfile.centos-7 create mode 100644 ci/kokoro/install/Dockerfile.fedora-30 create mode 100644 ci/kokoro/install/Dockerfile.fedora-30-shared create mode 100644 ci/kokoro/install/Dockerfile.opensuse-leap create mode 100644 ci/kokoro/install/Dockerfile.opensuse-tumbleweed create mode 100644 ci/kokoro/install/Dockerfile.ubuntu-16.04 create mode 100644 ci/kokoro/install/Dockerfile.ubuntu-18.04 create mode 100755 ci/kokoro/install/build.sh create mode 100644 ci/kokoro/install/centos-7-presubmit.cfg create mode 100644 ci/kokoro/install/centos-7.cfg create mode 100644 ci/kokoro/install/common.cfg create mode 100644 ci/kokoro/install/fedora-30-presubmit.cfg create mode 100644 ci/kokoro/install/fedora-30-shared-presubmit.cfg create mode 100644 ci/kokoro/install/fedora-30-shared.cfg create mode 100644 ci/kokoro/install/fedora-30.cfg create mode 100644 ci/kokoro/install/opensuse-leap-presubmit.cfg create mode 100644 ci/kokoro/install/opensuse-leap.cfg create mode 100644 ci/kokoro/install/opensuse-tumbleweed-presubmit.cfg create mode 100644 ci/kokoro/install/opensuse-tumbleweed.cfg create mode 100644 ci/kokoro/install/ubuntu-16.04-presubmit.cfg create mode 100644 ci/kokoro/install/ubuntu-16.04.cfg create mode 100644 ci/kokoro/install/ubuntu-18.04-presubmit.cfg create mode 100644 ci/kokoro/install/ubuntu-18.04.cfg create mode 100644 ci/test-install/bigtable/CMakeLists.txt create mode 100644 ci/test-install/bigtable/main.cc create mode 100755 ci/test-install/compile-test-projects.sh create mode 100644 ci/test-install/spanner/CMakeLists.txt create mode 100644 ci/test-install/spanner/main.cc diff --git a/ci/kokoro/install/Dockerfile.centos-7 b/ci/kokoro/install/Dockerfile.centos-7 new file mode 100644 index 000000000..21b890813 --- /dev/null +++ b/ci/kokoro/install/Dockerfile.centos-7 @@ -0,0 +1,105 @@ +# Copyright 2019 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 +# +# http://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. + +FROM centos:7 AS devtools + +# Please keep the formatting in these commands, it is optimized to cut & paste +# into the INSTALL.md file. + +## [START INSTALL.md] + +# First install the development tools and OpenSSL. The development tools +# distributed with CentOS (notably CMake) are too old to build +# `cpp-cmakefiles`. In these instructions, we use `cmake3` obtained from +# [Software Collections](https://www.softwarecollections.org/). + +# ```bash +RUN rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm +RUN yum install -y centos-release-scl +RUN yum-config-manager --enable rhel-server-rhscl-7-rpms +RUN yum makecache && \ + yum install -y automake cmake3 curl-devel gcc gcc-c++ git libtool \ + make openssl-devel pkgconfig tar wget which zlib-devel +RUN ln -sf /usr/bin/cmake3 /usr/bin/cmake && ln -sf /usr/bin/ctest3 /usr/bin/ctest +# ``` + +# #### Protobuf + +# Likewise, manually install protobuf: + +# ```bash +WORKDIR /var/tmp/build +RUN wget -q https://github.com/google/protobuf/archive/v3.9.0.tar.gz +RUN tar -xf v3.9.0.tar.gz +WORKDIR /var/tmp/build/protobuf-3.9.0/cmake +RUN cmake \ + -DCMAKE_BUILD_TYPE=Release \ + -DBUILD_SHARED_LIBS=yes \ + -Dprotobuf_BUILD_TESTS=OFF \ + -H. -Bcmake-out +RUN cmake --build cmake-out --target install -- -j $(nproc) +RUN ldconfig +# ``` + +# #### c-ares + +# Recent versions of gRPC require c-ares >= 1.11, while CentOS-7 +# distributes c-ares-1.10. Manually install a newer version: + +# ```bash +WORKDIR /var/tmp/build +RUN wget -q https://github.com/c-ares/c-ares/archive/cares-1_15_0.tar.gz +RUN tar -xf cares-1_15_0.tar.gz +WORKDIR /var/tmp/build/c-ares-cares-1_15_0 +RUN ./buildconf && ./configure && make -j $(nproc) +RUN make install +RUN ldconfig +# ``` + +# #### gRPC + +# Can be manually installed using: + +# ```bash +WORKDIR /var/tmp/build +RUN wget -q https://github.com/grpc/grpc/archive/v1.22.0.tar.gz +RUN tar -xf v1.22.0.tar.gz +WORKDIR /var/tmp/build/grpc-1.22.0 +ENV PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/local/lib64/pkgconfig +ENV LD_LIBRARY_PATH=/usr/local/lib:/usr/local/lib64 +ENV PATH=/usr/local/bin:${PATH} +RUN make -j $(nproc) +RUN make install +RUN ldconfig +# ``` + +FROM devtools AS install + +# #### googleapis + +# Finally we can install `googleapis`. + +# ```bash +WORKDIR /home/build/cpp-cmakefiles +COPY . /home/build/cpp-cmakefiles +RUN cmake -H. -Bcmake-out +RUN cmake --build cmake-out -- -j $(nproc) +WORKDIR /home/build/cpp-cmakefiles/cmake-out +RUN cmake --build . --target install +# ``` + +## [END INSTALL.md] + +# Verify that the installed files are actually usable +RUN /home/build/cpp-cmakefiles/ci/test-install/compile-test-projects.sh diff --git a/ci/kokoro/install/Dockerfile.fedora-30 b/ci/kokoro/install/Dockerfile.fedora-30 new file mode 100644 index 000000000..d6e57b91e --- /dev/null +++ b/ci/kokoro/install/Dockerfile.fedora-30 @@ -0,0 +1,58 @@ +# Copyright 2019 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 +# +# http://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. + +FROM fedora:30 AS devtools + +# Please keep the formatting below, it is used by `extract-install.md` +# to generate the contents of the top-level INSTALL.md. + +## [START INSTALL.md] + +# Install the minimal development tools: + +# ```bash +RUN dnf makecache && \ + dnf install -y cmake gcc-c++ git make openssl-devel pkgconfig \ + zlib-devel +# ``` + +# Fedora includes packages for gRPC, libcurl, and OpenSSL that are recent enough +# for `cpp-cmakefiles`. Install these packages and additional development +# tools to compile the dependencies: + +# ```bash +RUN dnf makecache && \ + dnf install -y grpc-devel grpc-plugins \ + libcurl-devel protobuf-compiler tar wget zlib-devel +# ``` + +FROM devtools AS install + +# #### googleapis + +# We can now compile and install `googleapis`. + +# ```bash +WORKDIR /home/build/cpp-cmakefiles +COPY . /home/build/cpp-cmakefiles +RUN cmake -H. -Bcmake-out +RUN cmake --build cmake-out -- -j $(nproc) +WORKDIR /home/build/cpp-cmakefiles/cmake-out +RUN cmake --build . --target install +# ``` + +## [END INSTALL.md] + +# Verify that the installed files are actually usable +RUN /home/build/cpp-cmakefiles/ci/test-install/compile-test-projects.sh diff --git a/ci/kokoro/install/Dockerfile.fedora-30-shared b/ci/kokoro/install/Dockerfile.fedora-30-shared new file mode 100644 index 000000000..3a0accf70 --- /dev/null +++ b/ci/kokoro/install/Dockerfile.fedora-30-shared @@ -0,0 +1,58 @@ +# Copyright 2019 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 +# +# http://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. + +FROM fedora:30 AS devtools + +# Please keep the formatting below, it is used by `extract-install.md` +# to generate the contents of the top-level INSTALL.md. + +## [START INSTALL.md] + +# Install the minimal development tools: + +# ```bash +RUN dnf makecache && \ + dnf install -y cmake gcc-c++ git make openssl-devel pkgconfig \ + zlib-devel +# ``` + +# Fedora includes packages for gRPC, libcurl, and OpenSSL that are recent enough +# for `cpp-cmakefiles`. Install these packages and additional development +# tools to compile the dependencies: + +# ```bash +RUN dnf makecache && \ + dnf install -y grpc-devel grpc-plugins \ + libcurl-devel protobuf-compiler tar wget zlib-devel +# ``` + +FROM devtools AS install + +# #### googleapis + +# We can now compile and install `googleapis` as shared library. + +# ```bash +WORKDIR /home/build/cpp-cmakefiles +COPY . /home/build/cpp-cmakefiles +RUN cmake -H. -Bcmake-out -DBUILD_SHARED_LIBS=yes +RUN cmake --build cmake-out -- -j $(nproc) +WORKDIR /home/build/cpp-cmakefiles/cmake-out +RUN cmake --build . --target install +# ``` + +## [END INSTALL.md] + +# Verify that the installed files are actually usable +RUN /home/build/cpp-cmakefiles/ci/test-install/compile-test-projects.sh diff --git a/ci/kokoro/install/Dockerfile.opensuse-leap b/ci/kokoro/install/Dockerfile.opensuse-leap new file mode 100644 index 000000000..ea2dda5ec --- /dev/null +++ b/ci/kokoro/install/Dockerfile.opensuse-leap @@ -0,0 +1,114 @@ +# Copyright 2019 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 +# +# http://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. + +FROM opensuse/leap:latest AS devtools + +## [START INSTALL.md] + +# Install the minimal development tools: + +# ```bash +RUN zypper refresh && \ + zypper install --allow-downgrade -y cmake gcc gcc-c++ git gzip \ + libcurl-devel libopenssl-devel make tar wget +# ``` + +# #### Protobuf + +# OpenSUSE Leap includes a package for protobuf-2.6, but this is too old to +# support the Google Cloud Platform proto files, or to support gRPC for that +# matter. Manually install protobuf: + +# ```bash +WORKDIR /var/tmp/build +RUN wget -q https://github.com/google/protobuf/archive/v3.9.0.tar.gz +RUN tar -xf v3.9.0.tar.gz +WORKDIR /var/tmp/build/protobuf-3.9.0/cmake +RUN cmake \ + -DCMAKE_BUILD_TYPE=Release \ + -DBUILD_SHARED_LIBS=yes \ + -Dprotobuf_BUILD_TESTS=OFF \ + -H. -Bcmake-out +RUN cmake --build cmake-out --target install -- -j $(nproc) +RUN ldconfig +# ``` + +# #### c-ares + +# Recent versions of gRPC require c-ares >= 1.11, while OpenSUSE Leap +# distributes c-ares-1.9. We need some additional development tools to compile +# this library: + +# ```bash +RUN zypper refresh && \ + zypper install -y automake libtool +# ``` + +# Manually install a newer version: + +# ```bash +WORKDIR /var/tmp/build +RUN wget -q https://github.com/c-ares/c-ares/archive/cares-1_15_0.tar.gz +RUN tar -xf cares-1_15_0.tar.gz +WORKDIR /var/tmp/build/c-ares-cares-1_15_0 +RUN ./buildconf && ./configure && make -j $(nproc) +RUN make install +RUN ldconfig +# ``` + +# #### gRPC + +# The gRPC Makefile uses `which` to determine whether the compiler is available. +# Install this command for the extremely rare case where it may be missing from +# your workstation or build server: + +# ```bash +RUN zypper refresh && \ + zypper install -y which +# ``` + +# Then gRPC can be manually installed using: + +# ```bash +WORKDIR /var/tmp/build +RUN wget -q https://github.com/grpc/grpc/archive/v1.22.0.tar.gz +RUN tar -xf v1.22.0.tar.gz +WORKDIR /var/tmp/build/grpc-1.22.0 +ENV PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/local/lib64/pkgconfig +ENV LD_LIBRARY_PATH=/usr/local/lib:/usr/local/lib64 +ENV PATH=/usr/local/bin:${PATH} +RUN make -j $(nproc) +RUN make install +RUN ldconfig +# ``` + +FROM devtools AS install + +# #### googleapis + +# We can now compile and install `googleapis`. + +# ```bash +WORKDIR /home/build/cpp-cmakefiles +COPY . /home/build/cpp-cmakefiles +RUN cmake -H. -Bcmake-out +RUN cmake --build cmake-out -- -j $(nproc) +WORKDIR /home/build/cpp-cmakefiles/cmake-out +RUN cmake --build . --target install +# ``` + +## [END INSTALL.md] + +# Verify that the installed files are actually usable +RUN /home/build/cpp-cmakefiles/ci/test-install/compile-test-projects.sh diff --git a/ci/kokoro/install/Dockerfile.opensuse-tumbleweed b/ci/kokoro/install/Dockerfile.opensuse-tumbleweed new file mode 100644 index 000000000..0c466697c --- /dev/null +++ b/ci/kokoro/install/Dockerfile.opensuse-tumbleweed @@ -0,0 +1,54 @@ +# Copyright 2018 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 +# +# http://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. + +FROM opensuse/tumbleweed:latest AS devtools + +## [START INSTALL.md] + +# Install the minimal development tools: + +# ```bash +RUN zypper refresh && \ + zypper install --allow-downgrade -y cmake gcc gcc-c++ git gzip \ + libcurl-devel libopenssl-devel make tar wget zlib-devel +# ``` + +# OpenSUSE:tumbleweed provides packages for gRPC, libcurl, and protobuf, and the +# versions of these packages are recent enough to support the Google Cloud +# Platform proto files. + +# ```bash +RUN zypper refresh && \ + zypper install -y grpc-devel gzip libcurl-devel pkg-config tar wget +# ``` + +FROM devtools AS install + +# #### googleapis + +# We can now compile and install `googleapis`. + +# ```bash +WORKDIR /home/build/cpp-cmakefiles +COPY . /home/build/cpp-cmakefiles +RUN cmake -H. -Bcmake-out +RUN cmake --build cmake-out -- -j $(nproc) +WORKDIR /home/build/cpp-cmakefiles/cmake-out +RUN cmake --build . --target install +# ``` + +## [END INSTALL.md] + +# Verify that the installed files are actually usable +RUN /home/build/cpp-cmakefiles/ci/test-install/compile-test-projects.sh diff --git a/ci/kokoro/install/Dockerfile.ubuntu-16.04 b/ci/kokoro/install/Dockerfile.ubuntu-16.04 new file mode 100644 index 000000000..030ed4a2a --- /dev/null +++ b/ci/kokoro/install/Dockerfile.ubuntu-16.04 @@ -0,0 +1,100 @@ +# Copyright 2018 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 +# +# http://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. + +FROM ubuntu:16.04 AS devtools + +# Please keep the formatting in these commands, it is optimized to cut & paste +# into the README.md file. + +## [START INSTALL.md] + +# Install the minimal development tools: + +# ```bash +RUN apt update && \ + apt install -y automake build-essential cmake git gcc g++ cmake \ + libcurl4-openssl-dev libssl-dev libtool make pkg-config tar wget \ + zlib1g-dev +# ``` + +# #### c-ares + +# Recent versions of gRPC require c-ares >= 1.11, while Ubuntu-16.04 +# distributes c-ares-1.10. We can manually install a newer version +# of c-ares: + +# ```bash +WORKDIR /var/tmp/build +RUN wget -q https://github.com/c-ares/c-ares/archive/cares-1_15_0.tar.gz +RUN tar -xf cares-1_15_0.tar.gz +WORKDIR /var/tmp/build/c-ares-cares-1_15_0 +RUN ./buildconf && ./configure && make -j $(nproc) +RUN make install +RUN ldconfig +# ``` + +# #### Protobuf + +# While protobuf-3.0 is distributed with Ubuntu, the Google Cloud Plaform proto +# files require more recent versions (circa 3.4.x). To manually install a more +# recent version use: + +# ```bash +WORKDIR /var/tmp/build +RUN wget -q https://github.com/google/protobuf/archive/v3.9.0.tar.gz +RUN tar -xf v3.9.0.tar.gz +WORKDIR /var/tmp/build/protobuf-3.9.0/cmake +RUN cmake \ + -DCMAKE_BUILD_TYPE=Release \ + -DBUILD_SHARED_LIBS=yes \ + -Dprotobuf_BUILD_TESTS=OFF \ + -H. -Bcmake-out +RUN cmake --build cmake-out --target install -- -j $(nproc) +RUN ldconfig +# ``` + +# #### gRPC + +# Likewise, Ubuntu has packages for grpc-1.3.x, but this version is too old for +# the Google Cloud Platform APIs: + +# ```bash +WORKDIR /var/tmp/build +RUN wget -q https://github.com/grpc/grpc/archive/v1.22.0.tar.gz +RUN tar -xf v1.22.0.tar.gz +WORKDIR /var/tmp/build/grpc-1.22.0 +RUN make -j $(nproc) +RUN make install +RUN ldconfig +# ``` + +FROM devtools AS install + +# #### googleapis + +# Finally we can install `googleapis`. + +# ```bash +WORKDIR /home/build/cpp-cmakefiles +COPY . /home/build/cpp-cmakefiles +RUN cmake -H. -Bcmake-out +RUN cmake --build cmake-out -- -j $(nproc) +WORKDIR /home/build/cpp-cmakefiles/cmake-out +RUN cmake --build . --target install +# ``` + +## [END INSTALL.md] + +# Verify that the installed files are actually usable +RUN /home/build/cpp-cmakefiles/ci/test-install/compile-test-projects.sh diff --git a/ci/kokoro/install/Dockerfile.ubuntu-18.04 b/ci/kokoro/install/Dockerfile.ubuntu-18.04 new file mode 100644 index 000000000..486d24aa4 --- /dev/null +++ b/ci/kokoro/install/Dockerfile.ubuntu-18.04 @@ -0,0 +1,84 @@ +# Copyright 2018 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 +# +# http://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. + +FROM ubuntu:18.04 AS devtools + +# Please keep the formatting in these commands, it is optimized to cut & paste +# into the README.md file. + +## [START INSTALL.md] + +# Install the minimal development tools: + +# ```bash +RUN apt update && \ + apt install -y build-essential cmake git gcc g++ cmake \ + libc-ares-dev libc-ares2 libcurl4-openssl-dev libssl-dev make \ + pkg-config tar wget zlib1g-dev +# ``` + +# #### Protobuf + +# While protobuf-3.0 is distributed with Ubuntu, the Google Cloud Plaform proto +# files require more recent versions (circa 3.4.x). To manually install a more +# recent version use: + +# ```bash +WORKDIR /var/tmp/build +RUN wget -q https://github.com/google/protobuf/archive/v3.9.0.tar.gz +RUN tar -xf v3.9.0.tar.gz +WORKDIR /var/tmp/build/protobuf-3.9.0/cmake +RUN cmake \ + -DCMAKE_BUILD_TYPE=Release \ + -DBUILD_SHARED_LIBS=yes \ + -Dprotobuf_BUILD_TESTS=OFF \ + -H. -Bcmake-out +RUN cmake --build cmake-out --target install -- -j $(nproc) +RUN ldconfig +# ``` + +# #### gRPC + +# Likewise, Ubuntu has packages for grpc-1.3.x, but this version is too old for +# the Google Cloud Platform APIs: + +# ```bash +WORKDIR /var/tmp/build +RUN wget -q https://github.com/grpc/grpc/archive/v1.22.0.tar.gz +RUN tar -xf v1.22.0.tar.gz +WORKDIR /var/tmp/build/grpc-1.22.0 +RUN make -j $(nproc) +RUN make install +RUN ldconfig +# ``` + +FROM devtools AS install + +# #### googleapis + +# Finally we can install `googleapis`. + +# ```bash +WORKDIR /home/build/cpp-cmakefiles +COPY . /home/build/cpp-cmakefiles +RUN cmake -H. -Bcmake-out +RUN cmake --build cmake-out -- -j $(nproc) +WORKDIR /home/build/cpp-cmakefiles/cmake-out +RUN cmake --build . --target install +# ``` + +## [END INSTALL.md] + +# Verify that the installed files are actually usable +RUN /home/build/cpp-cmakefiles/ci/test-install/compile-test-projects.sh diff --git a/ci/kokoro/install/build.sh b/ci/kokoro/install/build.sh new file mode 100755 index 000000000..42e85f39b --- /dev/null +++ b/ci/kokoro/install/build.sh @@ -0,0 +1,106 @@ +#!/usr/bin/env bash +# +# Copyright 2019 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 +# +# http://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. + +set -eu + +if [[ $# -eq 1 ]]; then + export TEST_TARGET="${1}" +elif [[ -n "${KOKORO_JOB_NAME:-}" ]]; then + # Kokoro injects the KOKORO_JOB_NAME environment variable, the value of this + # variable is cloud-cpp/spanner/ (or more + # generally ). By convention we name these + # files `$foo.cfg` for continuous builds and `$foo-presubmit.cfg` for + # presubmit builds. Here we extract the value of "foo" and use it as the build + # name. + TEST_TARGET="$(basename "${KOKORO_JOB_NAME}" "-presubmit")" + export TEST_TARGET +else + echo "Aborting build as the distribution name is not defined." + echo "If you are invoking this script via the command line use:" + echo " $0 " + echo + echo "If this script is invoked by Kokoro, the CI system is expected to set" + echo "the KOKORO_JOB_NAME environment variable." + exit 1 +fi + +echo "================================================================" +echo "Change working directory to project root $(date)." +cd "$(dirname "$0")/../../.." + +if [[ -z "${PROJECT_ID+x}" ]]; then + readonly PROJECT_ID="cloud-devrel-kokoro-resources" +fi + +readonly DEV_IMAGE="gcr.io/${PROJECT_ID}/cpp-cmakefiles/test-install-dev-${TEST_TARGET}" +readonly IMAGE="gcr.io/${PROJECT_ID}/cpp-cmakefiles/test-install-${TEST_TARGET}" + +has_cache="false" + +# We download the cached dev image for pull requests on kokoro. For continuous +# jobs, we don't download the cached image. This means we build from scratch and +# upload the image for future builds for pull requests. +if [[ -n "${KOKORO_JOB_NAME:-}" ]] \ + && [[ -n "${KOKORO_GITHUB_PULL_REQUEST_NUMBER:-}" ]]; then + echo "================================================================" + echo "Download existing image (if available) for ${TEST_TARGET} $(date)." + if docker pull "${DEV_IMAGE}:latest"; then + echo "Existing image successfully downloaded." + has_cache="true" + fi + echo "================================================================" +fi + +echo "================================================================" +echo "Build base image with minimal development tools for ${TEST_TARGET} $(date)." +update_cache="false" + +devtools_flags=( + # Only build up to the stage that installs the minimal development tools, but + # does not compile any of our code. + "--target" "devtools" + # Create the image with the same tag as the cache we are using, so we can + # upload it. + "-t" "${DEV_IMAGE}:latest" + "-f" "ci/kokoro/install/Dockerfile.${TEST_TARGET}" +) + +if "${has_cache}"; then + devtools_flags+=("--cache-from=${DEV_IMAGE}:latest") +fi + +echo "Running docker build with " "${devtools_flags[@]}" +if docker build "${devtools_flags[@]}" ci; then + update_cache="true" +fi + +# We upload the cached image for continuous builds. +if "${update_cache}" && [[ -z "${KOKORO_GITHUB_PULL_REQUEST_NUMBER:-}" ]] \ + && [[ -n "${KOKORO_JOB_NAME:-}" ]]; then + echo "================================================================" + echo "Uploading updated base image for ${TEST_TARGET} $(date)." + # Do not stop the build on a failure to update the cache. + docker push "${DEV_IMAGE}:latest" || true +fi + +echo "================================================================" +echo "Run validation script for INSTALL instructions on ${TEST_TARGET}." +docker build \ + "--cache-from=${DEV_IMAGE}:latest" \ + "--target=install" \ + -t "${IMAGE}" \ + -f "ci/kokoro/install/Dockerfile.${TEST_TARGET}" . +echo "================================================================" diff --git a/ci/kokoro/install/centos-7-presubmit.cfg b/ci/kokoro/install/centos-7-presubmit.cfg new file mode 100644 index 000000000..e69de29bb diff --git a/ci/kokoro/install/centos-7.cfg b/ci/kokoro/install/centos-7.cfg new file mode 100644 index 000000000..e69de29bb diff --git a/ci/kokoro/install/common.cfg b/ci/kokoro/install/common.cfg new file mode 100644 index 000000000..77a3a1f9f --- /dev/null +++ b/ci/kokoro/install/common.cfg @@ -0,0 +1,17 @@ +# Format: //devtools/kokoro/config/proto/build.proto +# Copyright 2019 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 +# +# http://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. + +build_file: "cpp-cmakefiles/ci/kokoro/install/build.sh" +timeout_mins: 120 diff --git a/ci/kokoro/install/fedora-30-presubmit.cfg b/ci/kokoro/install/fedora-30-presubmit.cfg new file mode 100644 index 000000000..e69de29bb diff --git a/ci/kokoro/install/fedora-30-shared-presubmit.cfg b/ci/kokoro/install/fedora-30-shared-presubmit.cfg new file mode 100644 index 000000000..e69de29bb diff --git a/ci/kokoro/install/fedora-30-shared.cfg b/ci/kokoro/install/fedora-30-shared.cfg new file mode 100644 index 000000000..e69de29bb diff --git a/ci/kokoro/install/fedora-30.cfg b/ci/kokoro/install/fedora-30.cfg new file mode 100644 index 000000000..e69de29bb diff --git a/ci/kokoro/install/opensuse-leap-presubmit.cfg b/ci/kokoro/install/opensuse-leap-presubmit.cfg new file mode 100644 index 000000000..e69de29bb diff --git a/ci/kokoro/install/opensuse-leap.cfg b/ci/kokoro/install/opensuse-leap.cfg new file mode 100644 index 000000000..e69de29bb diff --git a/ci/kokoro/install/opensuse-tumbleweed-presubmit.cfg b/ci/kokoro/install/opensuse-tumbleweed-presubmit.cfg new file mode 100644 index 000000000..e69de29bb diff --git a/ci/kokoro/install/opensuse-tumbleweed.cfg b/ci/kokoro/install/opensuse-tumbleweed.cfg new file mode 100644 index 000000000..e69de29bb diff --git a/ci/kokoro/install/ubuntu-16.04-presubmit.cfg b/ci/kokoro/install/ubuntu-16.04-presubmit.cfg new file mode 100644 index 000000000..e69de29bb diff --git a/ci/kokoro/install/ubuntu-16.04.cfg b/ci/kokoro/install/ubuntu-16.04.cfg new file mode 100644 index 000000000..e69de29bb diff --git a/ci/kokoro/install/ubuntu-18.04-presubmit.cfg b/ci/kokoro/install/ubuntu-18.04-presubmit.cfg new file mode 100644 index 000000000..e69de29bb diff --git a/ci/kokoro/install/ubuntu-18.04.cfg b/ci/kokoro/install/ubuntu-18.04.cfg new file mode 100644 index 000000000..e69de29bb diff --git a/ci/test-install/bigtable/CMakeLists.txt b/ci/test-install/bigtable/CMakeLists.txt new file mode 100644 index 000000000..7aed05ff1 --- /dev/null +++ b/ci/test-install/bigtable/CMakeLists.txt @@ -0,0 +1,28 @@ +# ~~~ +# Copyright 2019 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 +# +# http://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. +# ~~~ + +cmake_minimum_required(VERSION 3.5) + +project(utilize-googleapis CXX C) + +# Configure the compiler options, we will be using C++11 features. +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +find_package(googleapis REQUIRED) + +add_executable(utilize-googleapis main.cc) +target_link_libraries(utilize-googleapis googleapis-c++::bigtable_protos) diff --git a/ci/test-install/bigtable/main.cc b/ci/test-install/bigtable/main.cc new file mode 100644 index 000000000..08fce3c7b --- /dev/null +++ b/ci/test-install/bigtable/main.cc @@ -0,0 +1,22 @@ +// Copyright 2019 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 +// +// http://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 +#include + +int main() { + auto creds = grpc::InsecureChannelCredentials(); + auto channel = grpc::CreateChannel("localhost:12345", creds); + auto stub = google::bigtable::v2::Bigtable::NewStub(channel); +} diff --git a/ci/test-install/compile-test-projects.sh b/ci/test-install/compile-test-projects.sh new file mode 100755 index 000000000..12487ef54 --- /dev/null +++ b/ci/test-install/compile-test-projects.sh @@ -0,0 +1,36 @@ +#!/usr/bin/env bash +# Copyright 2019 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 +# +# http://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. + +# Compile projects that utilize the cpp-cmakefiles header files and libraries +# installed to the system. This script expects that the entire source tree is +# copied to /home/build/cpp-cmakefiles. Don't try to run this locally. + +set -eu + +# For bigtable protos +cp -R /home/build/cpp-cmakefiles/ci/test-install/bigtable \ + /home/build/test-install-bigtable +cd /home/build/test-install-bigtable +cmake -H. -Bcmake-out +cmake --build cmake-out -- -j "$(nproc)" +cmake-out/utilize-googleapis + +# For spanner protos +cp -R /home/build/cpp-cmakefiles/ci/test-install/spanner \ + /home/build/test-install-spanner +cd /home/build/test-install-spanner +cmake -H. -Bcmake-out +cmake --build cmake-out -- -j "$(nproc)" +cmake-out/utilize-googleapis diff --git a/ci/test-install/spanner/CMakeLists.txt b/ci/test-install/spanner/CMakeLists.txt new file mode 100644 index 000000000..2a4577ace --- /dev/null +++ b/ci/test-install/spanner/CMakeLists.txt @@ -0,0 +1,28 @@ +# ~~~ +# Copyright 2019 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 +# +# http://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. +# ~~~ + +cmake_minimum_required(VERSION 3.5) + +project(utilize-googleapis CXX C) + +# Configure the compiler options, we will be using C++11 features. +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +find_package(googleapis REQUIRED) + +add_executable(utilize-googleapis main.cc) +target_link_libraries(utilize-googleapis googleapis-c++::spanner_protos) diff --git a/ci/test-install/spanner/main.cc b/ci/test-install/spanner/main.cc new file mode 100644 index 000000000..f1866655a --- /dev/null +++ b/ci/test-install/spanner/main.cc @@ -0,0 +1,22 @@ +// Copyright 2019 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 +// +// http://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 +#include + +int main() { + auto creds = grpc::InsecureChannelCredentials(); + auto channel = grpc::CreateChannel("localhost:12345", creds); + auto stub = google::spanner::v1::Spanner::NewStub(channel); +} From 763c73147015fa9a229362bc6ff646cef310c801 Mon Sep 17 00:00:00 2001 From: Takashi Matsuo Date: Thu, 18 Jul 2019 14:20:41 -0400 Subject: [PATCH 07/34] Try to fix tumbleweed install build (#11) --- ci/kokoro/install/Dockerfile.opensuse-tumbleweed | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/kokoro/install/Dockerfile.opensuse-tumbleweed b/ci/kokoro/install/Dockerfile.opensuse-tumbleweed index 0c466697c..9a8733787 100644 --- a/ci/kokoro/install/Dockerfile.opensuse-tumbleweed +++ b/ci/kokoro/install/Dockerfile.opensuse-tumbleweed @@ -30,7 +30,7 @@ RUN zypper refresh && \ # ```bash RUN zypper refresh && \ - zypper install -y grpc-devel gzip libcurl-devel pkg-config tar wget + zypper install -y grpc-devel gzip libcurl-devel tar wget # ``` FROM devtools AS install From 8c2add05fa9f3cf83ff7acfba61090d07e67f6fc Mon Sep 17 00:00:00 2001 From: Takashi Matsuo Date: Thu, 18 Jul 2019 14:33:32 -0400 Subject: [PATCH 08/34] Add BUILD_BYPRODUCTS (#9) --- CMakeLists.txt | 51 +++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 40 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 95a38ba18..0914a89bb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -44,18 +44,47 @@ set( set(GOOGLE_CLOUD_CPP_GOOGLEAPIS_SHA256 "6b8a9b2bcb4476e9a5a9872869996f0d639c8d5df76dd8a893e79201f211b1cf") +set(GOOGLEAPIS_CPP_SOURCE + "${CMAKE_BINARY_DIR}/external/googleapis/src/googleapis_download") + include(ExternalProject) -ExternalProject_Add(googleapis_download - EXCLUDE_FROM_ALL ON - PREFIX "${CMAKE_BINARY_DIR}/external/googleapis" - URL ${GOOGLE_CLOUD_CPP_GOOGLEAPIS_URL} - URL_HASH SHA256=${GOOGLE_CLOUD_CPP_GOOGLEAPIS_SHA256} - CONFIGURE_COMMAND "" - BUILD_COMMAND "" - INSTALL_COMMAND "" - LOG_DOWNLOAD OFF) -ExternalProject_Get_Property(googleapis_download SOURCE_DIR) -set(GOOGLEAPIS_CPP_SOURCE "${SOURCE_DIR}") +ExternalProject_Add( + googleapis_download + EXCLUDE_FROM_ALL ON + PREFIX "${CMAKE_BINARY_DIR}/external/googleapis" + URL ${GOOGLE_CLOUD_CPP_GOOGLEAPIS_URL} + URL_HASH SHA256=${GOOGLE_CLOUD_CPP_GOOGLEAPIS_SHA256} + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + INSTALL_COMMAND "" + BUILD_BYPRODUCTS + "${GOOGLEAPIS_CPP_SOURCE}/google/api/http.proto" + "${GOOGLEAPIS_CPP_SOURCE}/google/api/annotations.proto" + "${GOOGLEAPIS_CPP_SOURCE}/google/api/auth.proto" + "${GOOGLEAPIS_CPP_SOURCE}/google/api/resource.proto" + "${GOOGLEAPIS_CPP_SOURCE}/google/type/expr.proto" + "${GOOGLEAPIS_CPP_SOURCE}/google/rpc/error_details.proto" + "${GOOGLEAPIS_CPP_SOURCE}/google/rpc/status.proto" + "${GOOGLEAPIS_CPP_SOURCE}/google/iam/v1/policy.proto" + "${GOOGLEAPIS_CPP_SOURCE}/google/iam/v1/iam_policy.proto" + "${GOOGLEAPIS_CPP_SOURCE}/google/longrunning/operations.proto" + "${GOOGLEAPIS_CPP_SOURCE}/google/bigtable/admin/v2/bigtable_instance_admin.proto" + "${GOOGLEAPIS_CPP_SOURCE}/google/bigtable/admin/v2/bigtable_table_admin.proto" + "${GOOGLEAPIS_CPP_SOURCE}/google/bigtable/admin/v2/common.proto" + "${GOOGLEAPIS_CPP_SOURCE}/google/bigtable/admin/v2/instance.proto" + "${GOOGLEAPIS_CPP_SOURCE}/google/bigtable/admin/v2/table.proto" + "${GOOGLEAPIS_CPP_SOURCE}/google/bigtable/v2/bigtable.proto" + "${GOOGLEAPIS_CPP_SOURCE}/google/bigtable/v2/data.proto" + "${GOOGLEAPIS_CPP_SOURCE}/google/spanner/admin/database/v1/spanner_database_admin.proto" + "${GOOGLEAPIS_CPP_SOURCE}/google/spanner/admin/instance/v1/spanner_instance_admin.proto" + "${GOOGLEAPIS_CPP_SOURCE}/google/spanner/v1/keys.proto" + "${GOOGLEAPIS_CPP_SOURCE}/google/spanner/v1/mutation.proto" + "${GOOGLEAPIS_CPP_SOURCE}/google/spanner/v1/query_plan.proto" + "${GOOGLEAPIS_CPP_SOURCE}/google/spanner/v1/result_set.proto" + "${GOOGLEAPIS_CPP_SOURCE}/google/spanner/v1/spanner.proto" + "${GOOGLEAPIS_CPP_SOURCE}/google/spanner/v1/transaction.proto" + "${GOOGLEAPIS_CPP_SOURCE}/google/spanner/v1/type.proto" + LOG_DOWNLOAD OFF) list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake") find_package(ProtobufTargets REQUIRED) From 22b90b89b9f33d394b26b0b03655a7325c598de6 Mon Sep 17 00:00:00 2001 From: Carlos O'Ryan Date: Thu, 15 Aug 2019 08:51:36 -0400 Subject: [PATCH 09/34] feat: Add library for api/client.proto. Also fixed the list of libraries in googleapis-config.cmake. --- CMakeLists.txt | 11 +++++++++++ cmake/config.cmake.in | 21 ++++++++++++--------- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0914a89bb..37c38002e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -61,6 +61,7 @@ ExternalProject_Add( "${GOOGLEAPIS_CPP_SOURCE}/google/api/http.proto" "${GOOGLEAPIS_CPP_SOURCE}/google/api/annotations.proto" "${GOOGLEAPIS_CPP_SOURCE}/google/api/auth.proto" + "${GOOGLEAPIS_CPP_SOURCE}/google/api/client.proto" "${GOOGLEAPIS_CPP_SOURCE}/google/api/resource.proto" "${GOOGLEAPIS_CPP_SOURCE}/google/type/expr.proto" "${GOOGLEAPIS_CPP_SOURCE}/google/rpc/error_details.proto" @@ -148,6 +149,16 @@ target_link_libraries(googleapis_cpp_api_auth_protos PUBLIC googleapis-c++::api_annotations_protos PRIVATE googleapis_cpp_common_flags) +google_cloud_cpp_grpcpp_library( + googleapis_cpp_api_client_protos + "${GOOGLEAPIS_CPP_SOURCE}/google/api/client.proto" + PROTO_PATH_DIRECTORIES + "${GOOGLEAPIS_CPP_SOURCE}" + "${PROTO_INCLUDE_DIR}") +googleapis_cpp_set_version_and_alias(api_client_protos) +target_link_libraries(googleapis_cpp_api_client_protos + PRIVATE googleapis_cpp_common_flags) + google_cloud_cpp_grpcpp_library( googleapis_cpp_api_resource_protos "${GOOGLEAPIS_CPP_SOURCE}/google/api/resource.proto" diff --git a/cmake/config.cmake.in b/cmake/config.cmake.in index 50ddd6bbd..266756cc2 100644 --- a/cmake/config.cmake.in +++ b/cmake/config.cmake.in @@ -1,3 +1,4 @@ +# ~~~ # Copyright 2019 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -11,6 +12,7 @@ # 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("${CMAKE_CURRENT_LIST_DIR}/FindProtobufTargets.cmake") include("${CMAKE_CURRENT_LIST_DIR}/FindgRPC.cmake") @@ -18,19 +20,20 @@ include("${CMAKE_CURRENT_LIST_DIR}/FindgRPC.cmake") include("${CMAKE_CURRENT_LIST_DIR}/googleapis-targets.cmake") foreach (_target - api_http api_annotations api_auth - rpc_status - rpc_error_details - longrunning_operations - iam_v1_policy - iam_v1_iam_policy + api_client + api_http + api_resource bigtable - spanner) + longrunning_operations + rpc_error_details + rpc_status + spanner + type_expr) set(scoped_name "googleapis-c++::${_target}_protos") set(imported_name "googleapis_cpp_${_target}_protos") add_library(${scoped_name} IMPORTED INTERFACE) - set_target_properties(${scoped_name} PROPERTIES - INTERFACE_LINK_LIBRARIES ${imported_name}) + set_target_properties(${scoped_name} + PROPERTIES INTERFACE_LINK_LIBRARIES ${imported_name}) endforeach () From 815a54fd92bc4be8db03070243bcad83e391ec61 Mon Sep 17 00:00:00 2001 From: Carlos O'Ryan Date: Thu, 15 Aug 2019 10:01:30 -0400 Subject: [PATCH 10/34] Missed two libraries. --- cmake/config.cmake.in | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cmake/config.cmake.in b/cmake/config.cmake.in index 266756cc2..422540496 100644 --- a/cmake/config.cmake.in +++ b/cmake/config.cmake.in @@ -26,6 +26,8 @@ foreach (_target api_http api_resource bigtable + iam_v1_iam_policy + iam_v1_policy longrunning_operations rpc_error_details rpc_status From 62991403ddd4c064c2f5cac99bb9d75d8ca94b99 Mon Sep 17 00:00:00 2001 From: Carlos O'Ryan Date: Fri, 16 Aug 2019 09:00:17 -0400 Subject: [PATCH 11/34] feat: Add library for cloudtrace/v2/trace.proto. --- CMakeLists.txt | 14 ++++++++++++++ cmake/config.cmake.in | 1 + 2 files changed, 15 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 37c38002e..d4e51b2ea 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -63,6 +63,7 @@ ExternalProject_Add( "${GOOGLEAPIS_CPP_SOURCE}/google/api/auth.proto" "${GOOGLEAPIS_CPP_SOURCE}/google/api/client.proto" "${GOOGLEAPIS_CPP_SOURCE}/google/api/resource.proto" + "${GOOGLEAPIS_CPP_SOURCE}/google/devtools/cloudtrace/v2/trace.proto" "${GOOGLEAPIS_CPP_SOURCE}/google/type/expr.proto" "${GOOGLEAPIS_CPP_SOURCE}/google/rpc/error_details.proto" "${GOOGLEAPIS_CPP_SOURCE}/google/rpc/status.proto" @@ -280,6 +281,18 @@ target_link_libraries(googleapis_cpp_spanner_protos googleapis-c++::iam_v1_iam_policy_protos PRIVATE googleapis_cpp_common_flags) +google_cloud_cpp_grpcpp_library( + googleapis_cpp_devtools_cloudtrace_v2_trace_protos + "${GOOGLEAPIS_CPP_SOURCE}/google/devtools/cloudtrace/v2/trace.proto" + PROTO_PATH_DIRECTORIES + "${GOOGLEAPIS_CPP_SOURCE}" + "${PROTO_INCLUDE_DIR}") +googleapis_cpp_set_version_and_alias(devtools_cloudtrace_v2_trace_protos) +target_link_libraries(googleapis_cpp_devtools_cloudtrace_v2_trace_protos + PUBLIC googleapis-c++::api_annotations_protos + googleapis-c++::rpc_status_protos + PRIVATE googleapis_cpp_common_flags) + # Install the libraries and headers in the locations determined by # GNUInstallDirs include(GNUInstallDirs) @@ -292,6 +305,7 @@ set(googleapis_cpp_installed_libraries_list googleapis_cpp_api_annotations_protos googleapis_cpp_api_auth_protos googleapis_cpp_api_resource_protos + googleapis_cpp_devtools_cloudtrace_v2_trace_protos googleapis_cpp_iam_v1_policy_protos googleapis_cpp_iam_v1_iam_policy_protos googleapis_cpp_rpc_error_details_protos diff --git a/cmake/config.cmake.in b/cmake/config.cmake.in index 422540496..c733cb237 100644 --- a/cmake/config.cmake.in +++ b/cmake/config.cmake.in @@ -26,6 +26,7 @@ foreach (_target api_http api_resource bigtable + devtools_cloudtrace_v2_trace iam_v1_iam_policy iam_v1_policy longrunning_operations From 1e638c6002209a08be784f1ee044a034cbf0f2ab Mon Sep 17 00:00:00 2001 From: Carlos O'Ryan Date: Fri, 16 Aug 2019 10:10:41 -0400 Subject: [PATCH 12/34] Addressed review comments. --- CMakeLists.txt | 15 +++++++++++++++ cmake/config.cmake.in | 1 + 2 files changed, 16 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index d4e51b2ea..ea6e09867 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -64,6 +64,7 @@ ExternalProject_Add( "${GOOGLEAPIS_CPP_SOURCE}/google/api/client.proto" "${GOOGLEAPIS_CPP_SOURCE}/google/api/resource.proto" "${GOOGLEAPIS_CPP_SOURCE}/google/devtools/cloudtrace/v2/trace.proto" + "${GOOGLEAPIS_CPP_SOURCE}/google/devtools/cloudtrace/v2/tracing.proto" "${GOOGLEAPIS_CPP_SOURCE}/google/type/expr.proto" "${GOOGLEAPIS_CPP_SOURCE}/google/rpc/error_details.proto" "${GOOGLEAPIS_CPP_SOURCE}/google/rpc/status.proto" @@ -293,6 +294,19 @@ target_link_libraries(googleapis_cpp_devtools_cloudtrace_v2_trace_protos googleapis-c++::rpc_status_protos PRIVATE googleapis_cpp_common_flags) +google_cloud_cpp_grpcpp_library( + googleapis_cpp_devtools_cloudtrace_v2_tracing_protos + "${GOOGLEAPIS_CPP_SOURCE}/google/devtools/cloudtrace/v2/tracing.proto" + PROTO_PATH_DIRECTORIES + "${GOOGLEAPIS_CPP_SOURCE}" + "${PROTO_INCLUDE_DIR}") +googleapis_cpp_set_version_and_alias(devtools_cloudtrace_v2_tracing_protos) +target_link_libraries(googleapis_cpp_devtools_cloudtrace_v2_tracing_protos + PUBLIC googleapis-c++::devtools_cloudtrace_v2_trace_protos + googleapis-c++::api_annotations_protos + googleapis-c++::rpc_status_protos + PRIVATE googleapis_cpp_common_flags) + # Install the libraries and headers in the locations determined by # GNUInstallDirs include(GNUInstallDirs) @@ -306,6 +320,7 @@ set(googleapis_cpp_installed_libraries_list googleapis_cpp_api_auth_protos googleapis_cpp_api_resource_protos googleapis_cpp_devtools_cloudtrace_v2_trace_protos + googleapis_cpp_devtools_cloudtrace_v2_tracing_protos googleapis_cpp_iam_v1_policy_protos googleapis_cpp_iam_v1_iam_policy_protos googleapis_cpp_rpc_error_details_protos diff --git a/cmake/config.cmake.in b/cmake/config.cmake.in index c733cb237..a06216e72 100644 --- a/cmake/config.cmake.in +++ b/cmake/config.cmake.in @@ -27,6 +27,7 @@ foreach (_target api_resource bigtable devtools_cloudtrace_v2_trace + devtools_cloudtrace_v2_tracing iam_v1_iam_policy iam_v1_policy longrunning_operations From 7e50ad50b84ed6098060531e8980a2925323bc9b Mon Sep 17 00:00:00 2001 From: Carlos O'Ryan Date: Fri, 23 Aug 2019 10:17:09 -0400 Subject: [PATCH 13/34] chore: Irregularly scheduled update for the protos. Update to the version of googleapis/googleapis as-of 2019-08-23. --- CMakeLists.txt | 18 ++++++++++++++++-- cmake/config.cmake.in | 3 ++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ea6e09867..78fbb7bf3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,10 +39,10 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) # downloaded from GitHub. set( GOOGLE_CLOUD_CPP_GOOGLEAPIS_URL - "https://github.com/googleapis/googleapis/archive/a8ee1416f4c588f2ab92da72e7c1f588c784d3e6.tar.gz" + "https://github.com/googleapis/googleapis/archive/9c9f778aedde02f9826d2ae5d0f9c96409ba0f25.tar.gz" ) set(GOOGLE_CLOUD_CPP_GOOGLEAPIS_SHA256 - "6b8a9b2bcb4476e9a5a9872869996f0d639c8d5df76dd8a893e79201f211b1cf") + "13af135d8cc9b81b47d6fbfc258fe790a151956d06e01fd16671aa49fe536ab1") set(GOOGLEAPIS_CPP_SOURCE "${CMAKE_BINARY_DIR}/external/googleapis/src/googleapis_download") @@ -68,6 +68,7 @@ ExternalProject_Add( "${GOOGLEAPIS_CPP_SOURCE}/google/type/expr.proto" "${GOOGLEAPIS_CPP_SOURCE}/google/rpc/error_details.proto" "${GOOGLEAPIS_CPP_SOURCE}/google/rpc/status.proto" + "${GOOGLEAPIS_CPP_SOURCE}/google/iam/v1/options.proto" "${GOOGLEAPIS_CPP_SOURCE}/google/iam/v1/policy.proto" "${GOOGLEAPIS_CPP_SOURCE}/google/iam/v1/iam_policy.proto" "${GOOGLEAPIS_CPP_SOURCE}/google/longrunning/operations.proto" @@ -202,6 +203,17 @@ target_link_libraries(googleapis_cpp_rpc_status_protos PUBLIC googleapis-c++::rpc_error_details_protos PRIVATE googleapis_cpp_common_flags) +google_cloud_cpp_grpcpp_library( + googleapis_cpp_iam_v1_options_protos + "${GOOGLEAPIS_CPP_SOURCE}/google/iam/v1/options.proto" + PROTO_PATH_DIRECTORIES + "${GOOGLEAPIS_CPP_SOURCE}" + "${PROTO_INCLUDE_DIR}") +googleapis_cpp_set_version_and_alias(iam_v1_options_protos) +target_link_libraries(googleapis_cpp_iam_v1_options_protos + PUBLIC googleapis-c++::api_annotations_protos + PRIVATE googleapis_cpp_common_flags) + google_cloud_cpp_grpcpp_library( googleapis_cpp_iam_v1_policy_protos "${GOOGLEAPIS_CPP_SOURCE}/google/iam/v1/policy.proto" @@ -321,6 +333,7 @@ set(googleapis_cpp_installed_libraries_list googleapis_cpp_api_resource_protos googleapis_cpp_devtools_cloudtrace_v2_trace_protos googleapis_cpp_devtools_cloudtrace_v2_tracing_protos + googleapis_cpp_iam_v1_options_protos googleapis_cpp_iam_v1_policy_protos googleapis_cpp_iam_v1_iam_policy_protos googleapis_cpp_rpc_error_details_protos @@ -407,6 +420,7 @@ set(GOOGLE_CLOUD_CPP_PC_DESCRIPTION string(CONCAT GOOGLE_CLOUD_CPP_PC_REQUIRES "googleapis_cpp_bigtable_protos" " googleapis_cpp_iam_v1_iam_policy_protos" + " googleapis_cpp_iam_v1_options_protos" " googleapis_cpp_iam_v1_policy_protos" " googleapis_cpp_longrunning_operations_protos" " googleapis_cpp_api_auth_protos" diff --git a/cmake/config.cmake.in b/cmake/config.cmake.in index a06216e72..88b6fff02 100644 --- a/cmake/config.cmake.in +++ b/cmake/config.cmake.in @@ -29,7 +29,8 @@ foreach (_target devtools_cloudtrace_v2_trace devtools_cloudtrace_v2_tracing iam_v1_iam_policy - iam_v1_policy + iam_v1_iam_policy + iam_v1_options longrunning_operations rpc_error_details rpc_status From 3c87089d12ae5b6099546a122b7230ec02dd1d17 Mon Sep 17 00:00:00 2001 From: Carlos O'Ryan Date: Fri, 23 Aug 2019 11:29:53 -0400 Subject: [PATCH 14/34] Argh, wrong target names. --- cmake/config.cmake.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/config.cmake.in b/cmake/config.cmake.in index 88b6fff02..2dd920197 100644 --- a/cmake/config.cmake.in +++ b/cmake/config.cmake.in @@ -29,8 +29,8 @@ foreach (_target devtools_cloudtrace_v2_trace devtools_cloudtrace_v2_tracing iam_v1_iam_policy - iam_v1_iam_policy iam_v1_options + iam_v1_policy longrunning_operations rpc_error_details rpc_status From e9bbfa0288f19c7135b2a4a5236ce847a0cfc9b2 Mon Sep 17 00:00:00 2001 From: Carlos O'Ryan Date: Fri, 23 Aug 2019 11:43:02 -0400 Subject: [PATCH 15/34] Fix dependencies, yay for CI builds. --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 78fbb7bf3..c521608e6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -236,6 +236,7 @@ google_cloud_cpp_grpcpp_library( googleapis_cpp_set_version_and_alias(iam_v1_iam_policy_protos) target_link_libraries(googleapis_cpp_iam_v1_iam_policy_protos PUBLIC googleapis-c++::api_annotations_protos + googleapis-c++::iam_v1_options_protos googleapis-c++::iam_v1_policy_protos PRIVATE googleapis_cpp_common_flags) From f19bdd987fff993d529195e78b7810f100c5a4a5 Mon Sep 17 00:00:00 2001 From: Carlos O'Ryan Date: Fri, 23 Aug 2019 12:27:08 -0400 Subject: [PATCH 16/34] Add yet another new dependency. --- CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index c521608e6..57384b87a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -236,6 +236,7 @@ google_cloud_cpp_grpcpp_library( googleapis_cpp_set_version_and_alias(iam_v1_iam_policy_protos) target_link_libraries(googleapis_cpp_iam_v1_iam_policy_protos PUBLIC googleapis-c++::api_annotations_protos + googleapis-c++::api_client_protos googleapis-c++::iam_v1_options_protos googleapis-c++::iam_v1_policy_protos PRIVATE googleapis_cpp_common_flags) @@ -331,6 +332,7 @@ set(googleapis_cpp_installed_libraries_list googleapis_cpp_api_http_protos googleapis_cpp_api_annotations_protos googleapis_cpp_api_auth_protos + googleapis_cpp_api_client_protos googleapis_cpp_api_resource_protos googleapis_cpp_devtools_cloudtrace_v2_trace_protos googleapis_cpp_devtools_cloudtrace_v2_tracing_protos From 1f68a41e38079373d763478ec56cc2eeafb26906 Mon Sep 17 00:00:00 2001 From: Carlos O'Ryan Date: Sun, 1 Sep 2019 09:40:27 -0400 Subject: [PATCH 17/34] bug: do not redefine targets in config file. If the config file is included twice (via `find_dependency()` or `find_package()`) some of the targets could get redefined, breaking the configuration. --- cmake/config.cmake.in | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/cmake/config.cmake.in b/cmake/config.cmake.in index 2dd920197..295501e56 100644 --- a/cmake/config.cmake.in +++ b/cmake/config.cmake.in @@ -38,7 +38,10 @@ foreach (_target type_expr) set(scoped_name "googleapis-c++::${_target}_protos") set(imported_name "googleapis_cpp_${_target}_protos") - add_library(${scoped_name} IMPORTED INTERFACE) - set_target_properties(${scoped_name} - PROPERTIES INTERFACE_LINK_LIBRARIES ${imported_name}) + if (NOT TARGET ${scoped_name}) + add_library(${scoped_name} IMPORTED INTERFACE) + set_target_properties(${scoped_name} + PROPERTIES INTERFACE_LINK_LIBRARIES + ${imported_name}) + endif () endforeach () From d496568000e98f166822d747bc2fc9cb96a3f571 Mon Sep 17 00:00:00 2001 From: Carlos O'Ryan Date: Mon, 9 Sep 2019 15:44:25 -0400 Subject: [PATCH 18/34] cleanup: refactor single-source library definitions. A lot of the libraries have a single source and can be refactored to a function that creates them. --- CMakeLists.txt | 308 +++++++++++++++++++------------------------------ 1 file changed, 118 insertions(+), 190 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 57384b87a..c17806cc9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,48 +47,58 @@ set(GOOGLE_CLOUD_CPP_GOOGLEAPIS_SHA256 set(GOOGLEAPIS_CPP_SOURCE "${CMAKE_BINARY_DIR}/external/googleapis/src/googleapis_download") +set(GOOGLEAPIS_CPP_PROTO_FILES + "google/api/http.proto" + "google/api/annotations.proto" + "google/api/auth.proto" + "google/api/client.proto" + "google/api/label.proto" + "google/api/launch_stage.proto" + "google/api/metric.proto" + "google/api/monitored_resource.proto" + "google/api/resource.proto" + "google/devtools/cloudtrace/v2/trace.proto" + "google/devtools/cloudtrace/v2/tracing.proto" + "google/type/expr.proto" + "google/rpc/error_details.proto" + "google/rpc/status.proto" + "google/iam/v1/options.proto" + "google/iam/v1/policy.proto" + "google/iam/v1/iam_policy.proto" + "google/longrunning/operations.proto" + "google/bigtable/admin/v2/bigtable_instance_admin.proto" + "google/bigtable/admin/v2/bigtable_table_admin.proto" + "google/bigtable/admin/v2/common.proto" + "google/bigtable/admin/v2/instance.proto" + "google/bigtable/admin/v2/table.proto" + "google/bigtable/v2/bigtable.proto" + "google/bigtable/v2/data.proto" + "google/spanner/admin/database/v1/spanner_database_admin.proto" + "google/spanner/admin/instance/v1/spanner_instance_admin.proto" + "google/spanner/v1/keys.proto" + "google/spanner/v1/mutation.proto" + "google/spanner/v1/query_plan.proto" + "google/spanner/v1/result_set.proto" + "google/spanner/v1/spanner.proto" + "google/spanner/v1/transaction.proto" + "google/spanner/v1/type.proto") + +set(GOOGLEAPIS_CPP_BYPRODUCTS) +foreach (proto ${GOOGLEAPIS_PROTO_FILES}) + list(APPEND GOOGLEAPIS_CPP_BYPRODUCTS "${GOOGLEAPIS_CPP_SOURCE}/${proto}") +endforeach () + include(ExternalProject) -ExternalProject_Add( - googleapis_download - EXCLUDE_FROM_ALL ON - PREFIX "${CMAKE_BINARY_DIR}/external/googleapis" - URL ${GOOGLE_CLOUD_CPP_GOOGLEAPIS_URL} - URL_HASH SHA256=${GOOGLE_CLOUD_CPP_GOOGLEAPIS_SHA256} - CONFIGURE_COMMAND "" - BUILD_COMMAND "" - INSTALL_COMMAND "" - BUILD_BYPRODUCTS - "${GOOGLEAPIS_CPP_SOURCE}/google/api/http.proto" - "${GOOGLEAPIS_CPP_SOURCE}/google/api/annotations.proto" - "${GOOGLEAPIS_CPP_SOURCE}/google/api/auth.proto" - "${GOOGLEAPIS_CPP_SOURCE}/google/api/client.proto" - "${GOOGLEAPIS_CPP_SOURCE}/google/api/resource.proto" - "${GOOGLEAPIS_CPP_SOURCE}/google/devtools/cloudtrace/v2/trace.proto" - "${GOOGLEAPIS_CPP_SOURCE}/google/devtools/cloudtrace/v2/tracing.proto" - "${GOOGLEAPIS_CPP_SOURCE}/google/type/expr.proto" - "${GOOGLEAPIS_CPP_SOURCE}/google/rpc/error_details.proto" - "${GOOGLEAPIS_CPP_SOURCE}/google/rpc/status.proto" - "${GOOGLEAPIS_CPP_SOURCE}/google/iam/v1/options.proto" - "${GOOGLEAPIS_CPP_SOURCE}/google/iam/v1/policy.proto" - "${GOOGLEAPIS_CPP_SOURCE}/google/iam/v1/iam_policy.proto" - "${GOOGLEAPIS_CPP_SOURCE}/google/longrunning/operations.proto" - "${GOOGLEAPIS_CPP_SOURCE}/google/bigtable/admin/v2/bigtable_instance_admin.proto" - "${GOOGLEAPIS_CPP_SOURCE}/google/bigtable/admin/v2/bigtable_table_admin.proto" - "${GOOGLEAPIS_CPP_SOURCE}/google/bigtable/admin/v2/common.proto" - "${GOOGLEAPIS_CPP_SOURCE}/google/bigtable/admin/v2/instance.proto" - "${GOOGLEAPIS_CPP_SOURCE}/google/bigtable/admin/v2/table.proto" - "${GOOGLEAPIS_CPP_SOURCE}/google/bigtable/v2/bigtable.proto" - "${GOOGLEAPIS_CPP_SOURCE}/google/bigtable/v2/data.proto" - "${GOOGLEAPIS_CPP_SOURCE}/google/spanner/admin/database/v1/spanner_database_admin.proto" - "${GOOGLEAPIS_CPP_SOURCE}/google/spanner/admin/instance/v1/spanner_instance_admin.proto" - "${GOOGLEAPIS_CPP_SOURCE}/google/spanner/v1/keys.proto" - "${GOOGLEAPIS_CPP_SOURCE}/google/spanner/v1/mutation.proto" - "${GOOGLEAPIS_CPP_SOURCE}/google/spanner/v1/query_plan.proto" - "${GOOGLEAPIS_CPP_SOURCE}/google/spanner/v1/result_set.proto" - "${GOOGLEAPIS_CPP_SOURCE}/google/spanner/v1/spanner.proto" - "${GOOGLEAPIS_CPP_SOURCE}/google/spanner/v1/transaction.proto" - "${GOOGLEAPIS_CPP_SOURCE}/google/spanner/v1/type.proto" - LOG_DOWNLOAD OFF) +ExternalProject_Add(googleapis_download + EXCLUDE_FROM_ALL ON + PREFIX "${CMAKE_BINARY_DIR}/external/googleapis" + URL ${GOOGLE_CLOUD_CPP_GOOGLEAPIS_URL} + URL_HASH SHA256=${GOOGLE_CLOUD_CPP_GOOGLEAPIS_SHA256} + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + INSTALL_COMMAND "" + BUILD_BYPRODUCTS ${GOOGLEAPIS_CPP_BYPRODUCTS} + LOG_DOWNLOAD OFF) list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake") find_package(ProtobufTargets REQUIRED) @@ -111,6 +121,47 @@ include(CompileProtos) google_cloud_cpp_add_protos_property() +function (googleapis_cpp_short_name var proto) + string(REPLACE "google/" + "" + short_name + "${proto}") + string(REPLACE "/" + "_" + short_name + "${short_name}") + string(REPLACE ".proto" + "_protos" + short_name + "${short_name}") + set("${var}" "${short_name}" PARENT_SCOPE) +endfunction () + +function (googleapis_cpp_add_library proto) + googleapis_cpp_short_name(short_name "${proto}") + google_cloud_cpp_grpcpp_library(googleapis_cpp_${short_name} + "${GOOGLEAPIS_CPP_SOURCE}/${proto}" + PROTO_PATH_DIRECTORIES + "${GOOGLEAPIS_CPP_SOURCE}" + "${PROTO_INCLUDE_DIR}") + + googleapis_cpp_set_version_and_alias("${short_name}") + + set(public_deps) + foreach (dep_short_name ${ARGN}) + list(APPEND public_deps "googleapis-c++::${dep_short_name}") + endforeach () + list(LENGTH public_deps public_deps_length) + if (public_deps_length EQUAL 0) + target_link_libraries("googleapis_cpp_${short_name}" + PRIVATE googleapis_cpp_common_flags) + else () + target_link_libraries("googleapis_cpp_${short_name}" + PUBLIC ${public_deps} + PRIVATE googleapis_cpp_common_flags) + endif () +endfunction () + function (googleapis_cpp_set_version_and_alias short_name) add_dependencies("googleapis_cpp_${short_name}" googleapis_download) set_target_properties("googleapis_cpp_${short_name}" @@ -122,136 +173,38 @@ function (googleapis_cpp_set_version_and_alias short_name) "googleapis_cpp_${short_name}") endfunction () -google_cloud_cpp_grpcpp_library(googleapis_cpp_api_http_protos - "${GOOGLEAPIS_CPP_SOURCE}/google/api/http.proto" - PROTO_PATH_DIRECTORIES - "${GOOGLEAPIS_CPP_SOURCE}" - "${PROTO_INCLUDE_DIR}") -googleapis_cpp_set_version_and_alias(api_http_protos) -target_link_libraries(googleapis_cpp_api_http_protos - PRIVATE googleapis_cpp_common_flags) +googleapis_cpp_add_library("google/api/http.proto") +googleapis_cpp_add_library("google/api/annotations.proto" api_http_protos) +googleapis_cpp_add_library("google/api/auth.proto" api_annotations_protos) +googleapis_cpp_add_library("google/api/client.proto") +googleapis_cpp_add_library("google/api/resource.proto") -google_cloud_cpp_grpcpp_library( - googleapis_cpp_api_annotations_protos - "${GOOGLEAPIS_CPP_SOURCE}/google/api/annotations.proto" - PROTO_PATH_DIRECTORIES - "${GOOGLEAPIS_CPP_SOURCE}" - "${PROTO_INCLUDE_DIR}") -googleapis_cpp_set_version_and_alias(api_annotations_protos) -target_link_libraries(googleapis_cpp_api_annotations_protos - PUBLIC googleapis-c++::api_http_protos - PRIVATE googleapis_cpp_common_flags) +googleapis_cpp_add_library("google/type/expr.proto") -google_cloud_cpp_grpcpp_library(googleapis_cpp_api_auth_protos - "${GOOGLEAPIS_CPP_SOURCE}/google/api/auth.proto" - PROTO_PATH_DIRECTORIES - "${GOOGLEAPIS_CPP_SOURCE}" - "${PROTO_INCLUDE_DIR}") -googleapis_cpp_set_version_and_alias(api_auth_protos) -target_link_libraries(googleapis_cpp_api_auth_protos - PUBLIC googleapis-c++::api_annotations_protos - PRIVATE googleapis_cpp_common_flags) +googleapis_cpp_add_library("google/rpc/error_details.proto") +googleapis_cpp_add_library("google/rpc/status.proto" rpc_error_details_protos) -google_cloud_cpp_grpcpp_library( - googleapis_cpp_api_client_protos - "${GOOGLEAPIS_CPP_SOURCE}/google/api/client.proto" - PROTO_PATH_DIRECTORIES - "${GOOGLEAPIS_CPP_SOURCE}" - "${PROTO_INCLUDE_DIR}") -googleapis_cpp_set_version_and_alias(api_client_protos) -target_link_libraries(googleapis_cpp_api_client_protos - PRIVATE googleapis_cpp_common_flags) +googleapis_cpp_add_library("google/iam/v1/options.proto" api_annotations_protos) +googleapis_cpp_add_library("google/iam/v1/policy.proto" + api_annotations_protos + api_resource_protos + type_expr_protos) -google_cloud_cpp_grpcpp_library( - googleapis_cpp_api_resource_protos - "${GOOGLEAPIS_CPP_SOURCE}/google/api/resource.proto" - PROTO_PATH_DIRECTORIES - "${GOOGLEAPIS_CPP_SOURCE}" - "${PROTO_INCLUDE_DIR}") -googleapis_cpp_set_version_and_alias(api_resource_protos) -target_link_libraries(googleapis_cpp_api_resource_protos - PRIVATE googleapis_cpp_common_flags) +googleapis_cpp_add_library("google/iam/v1/iam_policy.proto" + api_annotations_protos + api_client_protos + iam_v1_options_protos + iam_v1_policy_protos) -google_cloud_cpp_grpcpp_library( - googleapis_cpp_type_expr_protos - "${GOOGLEAPIS_CPP_SOURCE}/google/type/expr.proto" - PROTO_PATH_DIRECTORIES - "${GOOGLEAPIS_CPP_SOURCE}" - "${PROTO_INCLUDE_DIR}") -googleapis_cpp_set_version_and_alias(type_expr_protos) -target_link_libraries(googleapis_cpp_type_expr_protos - PRIVATE googleapis_cpp_common_flags) +googleapis_cpp_add_library("google/longrunning/operations.proto" + api_annotations_protos rpc_status_protos) -google_cloud_cpp_grpcpp_library( - googleapis_cpp_rpc_error_details_protos - "${GOOGLEAPIS_CPP_SOURCE}/google/rpc/error_details.proto" - PROTO_PATH_DIRECTORIES - "${GOOGLEAPIS_CPP_SOURCE}" - "${PROTO_INCLUDE_DIR}") -googleapis_cpp_set_version_and_alias(rpc_error_details_protos) -target_link_libraries(googleapis_cpp_rpc_error_details_protos - PRIVATE googleapis_cpp_common_flags) - -google_cloud_cpp_grpcpp_library( - googleapis_cpp_rpc_status_protos - "${GOOGLEAPIS_CPP_SOURCE}/google/rpc/status.proto" - PROTO_PATH_DIRECTORIES - "${GOOGLEAPIS_CPP_SOURCE}" - "${PROTO_INCLUDE_DIR}") -googleapis_cpp_set_version_and_alias(rpc_status_protos) -target_link_libraries(googleapis_cpp_rpc_status_protos - PUBLIC googleapis-c++::rpc_error_details_protos - PRIVATE googleapis_cpp_common_flags) - -google_cloud_cpp_grpcpp_library( - googleapis_cpp_iam_v1_options_protos - "${GOOGLEAPIS_CPP_SOURCE}/google/iam/v1/options.proto" - PROTO_PATH_DIRECTORIES - "${GOOGLEAPIS_CPP_SOURCE}" - "${PROTO_INCLUDE_DIR}") -googleapis_cpp_set_version_and_alias(iam_v1_options_protos) -target_link_libraries(googleapis_cpp_iam_v1_options_protos - PUBLIC googleapis-c++::api_annotations_protos - PRIVATE googleapis_cpp_common_flags) - -google_cloud_cpp_grpcpp_library( - googleapis_cpp_iam_v1_policy_protos - "${GOOGLEAPIS_CPP_SOURCE}/google/iam/v1/policy.proto" - PROTO_PATH_DIRECTORIES - "${GOOGLEAPIS_CPP_SOURCE}" - "${PROTO_INCLUDE_DIR}") -googleapis_cpp_set_version_and_alias(iam_v1_policy_protos) -target_link_libraries(googleapis_cpp_iam_v1_policy_protos - PUBLIC googleapis-c++::api_annotations_protos - googleapis-c++::api_resource_protos - googleapis-c++::type_expr_protos - PRIVATE googleapis_cpp_common_flags) - -google_cloud_cpp_grpcpp_library( - googleapis_cpp_iam_v1_iam_policy_protos - "${GOOGLEAPIS_CPP_SOURCE}/google/iam/v1/iam_policy.proto" - PROTO_PATH_DIRECTORIES - "${GOOGLEAPIS_CPP_SOURCE}" - "${PROTO_INCLUDE_DIR}") -googleapis_cpp_set_version_and_alias(iam_v1_iam_policy_protos) -target_link_libraries(googleapis_cpp_iam_v1_iam_policy_protos - PUBLIC googleapis-c++::api_annotations_protos - googleapis-c++::api_client_protos - googleapis-c++::iam_v1_options_protos - googleapis-c++::iam_v1_policy_protos - PRIVATE googleapis_cpp_common_flags) - -google_cloud_cpp_grpcpp_library( - googleapis_cpp_longrunning_operations_protos - "${GOOGLEAPIS_CPP_SOURCE}/google/longrunning/operations.proto" - PROTO_PATH_DIRECTORIES - "${GOOGLEAPIS_CPP_SOURCE}" - "${PROTO_INCLUDE_DIR}") -googleapis_cpp_set_version_and_alias(longrunning_operations_protos) -target_link_libraries(googleapis_cpp_longrunning_operations_protos - PUBLIC googleapis-c++::api_annotations_protos - googleapis-c++::rpc_status_protos - PRIVATE googleapis_cpp_common_flags) +googleapis_cpp_add_library("google/devtools/cloudtrace/v2/trace.proto" + api_annotations_protos rpc_status_protos) +googleapis_cpp_add_library("google/devtools/cloudtrace/v2/tracing.proto" + devtools_cloudtrace_v2_trace_protos + api_annotations_protos + rpc_status_protos) google_cloud_cpp_grpcpp_library( googleapis_cpp_bigtable_protos @@ -296,31 +249,6 @@ target_link_libraries(googleapis_cpp_spanner_protos googleapis-c++::iam_v1_iam_policy_protos PRIVATE googleapis_cpp_common_flags) -google_cloud_cpp_grpcpp_library( - googleapis_cpp_devtools_cloudtrace_v2_trace_protos - "${GOOGLEAPIS_CPP_SOURCE}/google/devtools/cloudtrace/v2/trace.proto" - PROTO_PATH_DIRECTORIES - "${GOOGLEAPIS_CPP_SOURCE}" - "${PROTO_INCLUDE_DIR}") -googleapis_cpp_set_version_and_alias(devtools_cloudtrace_v2_trace_protos) -target_link_libraries(googleapis_cpp_devtools_cloudtrace_v2_trace_protos - PUBLIC googleapis-c++::api_annotations_protos - googleapis-c++::rpc_status_protos - PRIVATE googleapis_cpp_common_flags) - -google_cloud_cpp_grpcpp_library( - googleapis_cpp_devtools_cloudtrace_v2_tracing_protos - "${GOOGLEAPIS_CPP_SOURCE}/google/devtools/cloudtrace/v2/tracing.proto" - PROTO_PATH_DIRECTORIES - "${GOOGLEAPIS_CPP_SOURCE}" - "${PROTO_INCLUDE_DIR}") -googleapis_cpp_set_version_and_alias(devtools_cloudtrace_v2_tracing_protos) -target_link_libraries(googleapis_cpp_devtools_cloudtrace_v2_tracing_protos - PUBLIC googleapis-c++::devtools_cloudtrace_v2_trace_protos - googleapis-c++::api_annotations_protos - googleapis-c++::rpc_status_protos - PRIVATE googleapis_cpp_common_flags) - # Install the libraries and headers in the locations determined by # GNUInstallDirs include(GNUInstallDirs) From d39abd950f7f4ee3013b0f4180902e20e31721db Mon Sep 17 00:00:00 2001 From: Carlos O'Ryan Date: Mon, 9 Sep 2019 17:14:23 -0400 Subject: [PATCH 19/34] Address review comments. --- CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index c17806cc9..6163a103d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -137,6 +137,10 @@ function (googleapis_cpp_short_name var proto) set("${var}" "${short_name}" PARENT_SCOPE) endfunction () +# Create a single source proto library. +# +# - proto: the filename for the proto source. +# - (optional) ARGN: proto libraries the new library depends on. function (googleapis_cpp_add_library proto) googleapis_cpp_short_name(short_name "${proto}") google_cloud_cpp_grpcpp_library(googleapis_cpp_${short_name} From 984abcc860570fe95d4ddef83bcd2bcc04c8def3 Mon Sep 17 00:00:00 2001 From: Carlos O'Ryan Date: Tue, 10 Sep 2019 07:35:10 -0400 Subject: [PATCH 20/34] Fix formatting. --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6163a103d..ffd61728c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -139,8 +139,8 @@ endfunction () # Create a single source proto library. # -# - proto: the filename for the proto source. -# - (optional) ARGN: proto libraries the new library depends on. +# * proto: the filename for the proto source. +# * (optional) ARGN: proto libraries the new library depends on. function (googleapis_cpp_add_library proto) googleapis_cpp_short_name(short_name "${proto}") google_cloud_cpp_grpcpp_library(googleapis_cpp_${short_name} From 0432a87fc99d84b1e82c3d6a3c5a479ab0cf1037 Mon Sep 17 00:00:00 2001 From: Carlos O'Ryan Date: Wed, 11 Sep 2019 12:13:01 -0400 Subject: [PATCH 21/34] feat: add libraries for metric and monitored_resource. (#22) --- CMakeLists.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index ffd61728c..0250f5dc3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -181,6 +181,12 @@ googleapis_cpp_add_library("google/api/http.proto") googleapis_cpp_add_library("google/api/annotations.proto" api_http_protos) googleapis_cpp_add_library("google/api/auth.proto" api_annotations_protos) googleapis_cpp_add_library("google/api/client.proto") +googleapis_cpp_add_library("google/api/label.proto") +googleapis_cpp_add_library("google/api/launch_stage.proto") +googleapis_cpp_add_library("google/api/metric.proto" api_launch_stage_protos + api_label_protos) +googleapis_cpp_add_library("google/api/monitored_resource.proto" + api_launch_stage_protos api_label_protos) googleapis_cpp_add_library("google/api/resource.proto") googleapis_cpp_add_library("google/type/expr.proto") From 3b7a52d9f799d35244a91aca5b576d20a831b88d Mon Sep 17 00:00:00 2001 From: Carlos O'Ryan Date: Wed, 16 Oct 2019 16:08:14 -0400 Subject: [PATCH 22/34] feat: add BigQuery proto library (#23) --- CMakeLists.txt | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0250f5dc3..ab4ca87a2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -73,6 +73,14 @@ set(GOOGLEAPIS_CPP_PROTO_FILES "google/bigtable/admin/v2/table.proto" "google/bigtable/v2/bigtable.proto" "google/bigtable/v2/data.proto" + "google/cloud/bigquery/v2/model_reference.proto" + "google/cloud/bigquery/v2/standard_sql.proto" + "google/cloud/bigquery/v2/model.proto" + "google/cloud/bigquery/storage/v1beta1/read_options.proto" + "google/cloud/bigquery/storage/v1beta1/storage.proto" + "google/cloud/bigquery/storage/v1beta1/avro.proto" + "google/cloud/bigquery/storage/v1beta1/table_reference.proto" + "google/cloud/bigquery/storage/v1beta1/arrow.proto" "google/spanner/admin/database/v1/spanner_database_admin.proto" "google/spanner/admin/instance/v1/spanner_instance_admin.proto" "google/spanner/v1/keys.proto" @@ -216,6 +224,26 @@ googleapis_cpp_add_library("google/devtools/cloudtrace/v2/tracing.proto" api_annotations_protos rpc_status_protos) +google_cloud_cpp_grpcpp_library( + googleapis_cpp_cloud_bigquery_protos + "${GOOGLEAPIS_CPP_SOURCE}/google/cloud/bigquery/v2/model_reference.proto" + "${GOOGLEAPIS_CPP_SOURCE}/google/cloud/bigquery/v2/standard_sql.proto" + "${GOOGLEAPIS_CPP_SOURCE}/google/cloud/bigquery/v2/model.proto" + "${GOOGLEAPIS_CPP_SOURCE}/google/cloud/bigquery/storage/v1beta1/read_options.proto" + "${GOOGLEAPIS_CPP_SOURCE}/google/cloud/bigquery/storage/v1beta1/storage.proto" + "${GOOGLEAPIS_CPP_SOURCE}/google/cloud/bigquery/storage/v1beta1/avro.proto" + "${GOOGLEAPIS_CPP_SOURCE}/google/cloud/bigquery/storage/v1beta1/table_reference.proto" + "${GOOGLEAPIS_CPP_SOURCE}/google/cloud/bigquery/storage/v1beta1/arrow.proto" + PROTO_PATH_DIRECTORIES + "${GOOGLEAPIS_CPP_SOURCE}" + "${PROTO_INCLUDE_DIR}") +googleapis_cpp_set_version_and_alias(cloud_bigquery_protos) +target_link_libraries(googleapis_cpp_cloud_bigquery_protos + PUBLIC googleapis-c++::api_annotations_protos + googleapis-c++::api_http_protos + googleapis-c++::api_client_protos + PRIVATE googleapis_cpp_common_flags) + google_cloud_cpp_grpcpp_library( googleapis_cpp_bigtable_protos "${GOOGLEAPIS_CPP_SOURCE}/google/bigtable/admin/v2/bigtable_instance_admin.proto" @@ -265,6 +293,7 @@ include(GNUInstallDirs) set(googleapis_cpp_installed_libraries_list googleapis_cpp_bigtable_protos + googleapis_cpp_cloud_bigquery_protos googleapis_cpp_spanner_protos googleapis_cpp_longrunning_operations_protos googleapis_cpp_api_http_protos @@ -360,6 +389,7 @@ set(GOOGLE_CLOUD_CPP_PC_DESCRIPTION # need to add the separator ourselves. string(CONCAT GOOGLE_CLOUD_CPP_PC_REQUIRES "googleapis_cpp_bigtable_protos" + " googleapis_cpp_bigquery_protos" " googleapis_cpp_iam_v1_iam_policy_protos" " googleapis_cpp_iam_v1_options_protos" " googleapis_cpp_iam_v1_policy_protos" From c1d1b77f3040dc58cec174b83e57c6ba3078552d Mon Sep 17 00:00:00 2001 From: Carlos O'Ryan Date: Wed, 16 Oct 2019 17:26:56 -0400 Subject: [PATCH 23/34] feat: upgrade googleapis and bigquery protos (#24) --- CMakeLists.txt | 45 +++++++++++++++++------- ci/test-install/bigquery/CMakeLists.txt | 28 +++++++++++++++ ci/test-install/bigquery/main.cc | 22 ++++++++++++ ci/test-install/compile-test-projects.sh | 10 +++++- cmake/config.cmake.in | 6 ++-- 5 files changed, 96 insertions(+), 15 deletions(-) create mode 100644 ci/test-install/bigquery/CMakeLists.txt create mode 100644 ci/test-install/bigquery/main.cc diff --git a/CMakeLists.txt b/CMakeLists.txt index ab4ca87a2..8b159faa2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,10 +39,10 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) # downloaded from GitHub. set( GOOGLE_CLOUD_CPP_GOOGLEAPIS_URL - "https://github.com/googleapis/googleapis/archive/9c9f778aedde02f9826d2ae5d0f9c96409ba0f25.tar.gz" + "https://github.com/googleapis/googleapis/archive/c6e62c7e5e61e6dae7fdc3bc3de81f60e6a9445c.tar.gz" ) set(GOOGLE_CLOUD_CPP_GOOGLEAPIS_SHA256 - "13af135d8cc9b81b47d6fbfc258fe790a151956d06e01fd16671aa49fe536ab1") + "33520d6ac51fbb2ca136c06b32b5f5f04f9b5ae8596b161dbe0ae05b1927b4de") set(GOOGLEAPIS_CPP_SOURCE "${CMAKE_BINARY_DIR}/external/googleapis/src/googleapis_download") @@ -52,6 +52,7 @@ set(GOOGLEAPIS_CPP_PROTO_FILES "google/api/annotations.proto" "google/api/auth.proto" "google/api/client.proto" + "google/api/field_behavior.proto" "google/api/label.proto" "google/api/launch_stage.proto" "google/api/metric.proto" @@ -73,14 +74,20 @@ set(GOOGLEAPIS_CPP_PROTO_FILES "google/bigtable/admin/v2/table.proto" "google/bigtable/v2/bigtable.proto" "google/bigtable/v2/data.proto" - "google/cloud/bigquery/v2/model_reference.proto" - "google/cloud/bigquery/v2/standard_sql.proto" - "google/cloud/bigquery/v2/model.proto" + "google/cloud/bigquery/connection/v1beta1/connection.proto" + "google/cloud/bigquery/datatransfer/v1/datasource.proto" + "google/cloud/bigquery/datatransfer/v1/datatransfer.proto" + "google/cloud/bigquery/datatransfer/v1/transfer.proto" + "google/cloud/bigquery/logging/v1/audit_data.proto" + "google/cloud/bigquery/storage/v1beta1/arrow.proto" + "google/cloud/bigquery/storage/v1beta1/avro.proto" "google/cloud/bigquery/storage/v1beta1/read_options.proto" "google/cloud/bigquery/storage/v1beta1/storage.proto" - "google/cloud/bigquery/storage/v1beta1/avro.proto" "google/cloud/bigquery/storage/v1beta1/table_reference.proto" - "google/cloud/bigquery/storage/v1beta1/arrow.proto" + "google/cloud/bigquery/v2/encryption_config.proto" + "google/cloud/bigquery/v2/model.proto" + "google/cloud/bigquery/v2/model_reference.proto" + "google/cloud/bigquery/v2/standard_sql.proto" "google/spanner/admin/database/v1/spanner_database_admin.proto" "google/spanner/admin/instance/v1/spanner_instance_admin.proto" "google/spanner/v1/keys.proto" @@ -189,6 +196,7 @@ googleapis_cpp_add_library("google/api/http.proto") googleapis_cpp_add_library("google/api/annotations.proto" api_http_protos) googleapis_cpp_add_library("google/api/auth.proto" api_annotations_protos) googleapis_cpp_add_library("google/api/client.proto") +googleapis_cpp_add_library("google/api/field_behavior.proto") googleapis_cpp_add_library("google/api/label.proto") googleapis_cpp_add_library("google/api/launch_stage.proto") googleapis_cpp_add_library("google/api/metric.proto" api_launch_stage_protos @@ -211,6 +219,7 @@ googleapis_cpp_add_library("google/iam/v1/policy.proto" googleapis_cpp_add_library("google/iam/v1/iam_policy.proto" api_annotations_protos api_client_protos + api_field_behavior_protos iam_v1_options_protos iam_v1_policy_protos) @@ -226,14 +235,20 @@ googleapis_cpp_add_library("google/devtools/cloudtrace/v2/tracing.proto" google_cloud_cpp_grpcpp_library( googleapis_cpp_cloud_bigquery_protos - "${GOOGLEAPIS_CPP_SOURCE}/google/cloud/bigquery/v2/model_reference.proto" - "${GOOGLEAPIS_CPP_SOURCE}/google/cloud/bigquery/v2/standard_sql.proto" - "${GOOGLEAPIS_CPP_SOURCE}/google/cloud/bigquery/v2/model.proto" + "${GOOGLEAPIS_CPP_SOURCE}/google/cloud/bigquery/connection/v1beta1/connection.proto" + "${GOOGLEAPIS_CPP_SOURCE}/google/cloud/bigquery/datatransfer/v1/datasource.proto" + "${GOOGLEAPIS_CPP_SOURCE}/google/cloud/bigquery/datatransfer/v1/datatransfer.proto" + "${GOOGLEAPIS_CPP_SOURCE}/google/cloud/bigquery/datatransfer/v1/transfer.proto" + "${GOOGLEAPIS_CPP_SOURCE}/google/cloud/bigquery/logging/v1/audit_data.proto" + "${GOOGLEAPIS_CPP_SOURCE}/google/cloud/bigquery/storage/v1beta1/arrow.proto" + "${GOOGLEAPIS_CPP_SOURCE}/google/cloud/bigquery/storage/v1beta1/avro.proto" "${GOOGLEAPIS_CPP_SOURCE}/google/cloud/bigquery/storage/v1beta1/read_options.proto" "${GOOGLEAPIS_CPP_SOURCE}/google/cloud/bigquery/storage/v1beta1/storage.proto" - "${GOOGLEAPIS_CPP_SOURCE}/google/cloud/bigquery/storage/v1beta1/avro.proto" "${GOOGLEAPIS_CPP_SOURCE}/google/cloud/bigquery/storage/v1beta1/table_reference.proto" - "${GOOGLEAPIS_CPP_SOURCE}/google/cloud/bigquery/storage/v1beta1/arrow.proto" + "${GOOGLEAPIS_CPP_SOURCE}/google/cloud/bigquery/v2/encryption_config.proto" + "${GOOGLEAPIS_CPP_SOURCE}/google/cloud/bigquery/v2/model.proto" + "${GOOGLEAPIS_CPP_SOURCE}/google/cloud/bigquery/v2/model_reference.proto" + "${GOOGLEAPIS_CPP_SOURCE}/google/cloud/bigquery/v2/standard_sql.proto" PROTO_PATH_DIRECTORIES "${GOOGLEAPIS_CPP_SOURCE}" "${PROTO_INCLUDE_DIR}") @@ -241,7 +256,10 @@ googleapis_cpp_set_version_and_alias(cloud_bigquery_protos) target_link_libraries(googleapis_cpp_cloud_bigquery_protos PUBLIC googleapis-c++::api_annotations_protos googleapis-c++::api_http_protos + googleapis-c++::api_field_behavior_protos googleapis-c++::api_client_protos + googleapis-c++::iam_v1_iam_policy_protos + googleapis-c++::rpc_status_protos PRIVATE googleapis_cpp_common_flags) google_cloud_cpp_grpcpp_library( @@ -300,6 +318,7 @@ set(googleapis_cpp_installed_libraries_list googleapis_cpp_api_annotations_protos googleapis_cpp_api_auth_protos googleapis_cpp_api_client_protos + googleapis_cpp_api_field_behavior_protos googleapis_cpp_api_resource_protos googleapis_cpp_devtools_cloudtrace_v2_trace_protos googleapis_cpp_devtools_cloudtrace_v2_tracing_protos @@ -396,6 +415,8 @@ string(CONCAT GOOGLE_CLOUD_CPP_PC_REQUIRES " googleapis_cpp_longrunning_operations_protos" " googleapis_cpp_api_auth_protos" " googleapis_cpp_api_annotations_protos" + " googleapis_cpp_api_client_protos" + " googleapis_cpp_api_field_behavior_protos" " googleapis_cpp_api_http_protos" " googleapis_cpp_rpc_status_protos" " googleapis_cpp_rpc_error_details_protos" diff --git a/ci/test-install/bigquery/CMakeLists.txt b/ci/test-install/bigquery/CMakeLists.txt new file mode 100644 index 000000000..3086ef461 --- /dev/null +++ b/ci/test-install/bigquery/CMakeLists.txt @@ -0,0 +1,28 @@ +# ~~~ +# Copyright 2019 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 +# +# http://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. +# ~~~ + +cmake_minimum_required(VERSION 3.5) + +project(utilize-googleapis CXX C) + +# Configure the compiler options, we will be using C++11 features. +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +find_package(googleapis REQUIRED) + +add_executable(utilize-googleapis main.cc) +target_link_libraries(utilize-googleapis googleapis-c++::cloud_bigquery_protos) diff --git a/ci/test-install/bigquery/main.cc b/ci/test-install/bigquery/main.cc new file mode 100644 index 000000000..bd00013ed --- /dev/null +++ b/ci/test-install/bigquery/main.cc @@ -0,0 +1,22 @@ +// Copyright 2019 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 +// +// http://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 +#include + +int main() { + auto creds = grpc::InsecureChannelCredentials(); + auto channel = grpc::CreateChannel("localhost:12345", creds); + auto stub = google::cloud::bigquery::storage::v1beta1::BigQueryStorage::NewStub(channel); +} diff --git a/ci/test-install/compile-test-projects.sh b/ci/test-install/compile-test-projects.sh index 12487ef54..47d612833 100755 --- a/ci/test-install/compile-test-projects.sh +++ b/ci/test-install/compile-test-projects.sh @@ -19,7 +19,15 @@ set -eu -# For bigtable protos +# For BigQuery protos +cp -R /home/build/cpp-cmakefiles/ci/test-install/bigquery \ + /home/build/test-install-bigquery +cd /home/build/test-install-bigquery +cmake -H. -Bcmake-out +cmake --build cmake-out -- -j "$(nproc)" +cmake-out/utilize-googleapis + +# For Bigtable protos cp -R /home/build/cpp-cmakefiles/ci/test-install/bigtable \ /home/build/test-install-bigtable cd /home/build/test-install-bigtable diff --git a/cmake/config.cmake.in b/cmake/config.cmake.in index 295501e56..90c3d4648 100644 --- a/cmake/config.cmake.in +++ b/cmake/config.cmake.in @@ -23,11 +23,13 @@ foreach (_target api_annotations api_auth api_client + api_field_behavior api_http api_resource bigtable - devtools_cloudtrace_v2_trace - devtools_cloudtrace_v2_tracing + cloud_bigquery + devtools_cloudtrace_v2_trace + devtools_cloudtrace_v2_tracing iam_v1_iam_policy iam_v1_options iam_v1_policy From b6c30c0eee8a8e0a5971ee87f428febe8d256d05 Mon Sep 17 00:00:00 2001 From: Carlos O'Ryan Date: Thu, 17 Oct 2019 11:15:39 -0400 Subject: [PATCH 24/34] bug: fix build with Ninja (#26) --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8b159faa2..6d04e63fa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -99,7 +99,7 @@ set(GOOGLEAPIS_CPP_PROTO_FILES "google/spanner/v1/type.proto") set(GOOGLEAPIS_CPP_BYPRODUCTS) -foreach (proto ${GOOGLEAPIS_PROTO_FILES}) +foreach (proto ${GOOGLEAPIS_CPP_PROTO_FILES}) list(APPEND GOOGLEAPIS_CPP_BYPRODUCTS "${GOOGLEAPIS_CPP_SOURCE}/${proto}") endforeach () From 449df1fd379fecc3f6ec05cc5650651d694e3a53 Mon Sep 17 00:00:00 2001 From: Carlos O'Ryan Date: Thu, 17 Oct 2019 14:47:50 -0400 Subject: [PATCH 25/34] ci: add configs for a CMake+Ninja build (#27) --- ci/kokoro/docker/build-in-docker-cmake.sh | 4 ++++ ci/kokoro/docker/build.sh | 7 +++++++ ci/kokoro/docker/ninja-presubmit.cfg | 0 ci/kokoro/docker/ninja.cfg | 0 4 files changed, 11 insertions(+) create mode 100644 ci/kokoro/docker/ninja-presubmit.cfg create mode 100644 ci/kokoro/docker/ninja.cfg diff --git a/ci/kokoro/docker/build-in-docker-cmake.sh b/ci/kokoro/docker/build-in-docker-cmake.sh index 38e0d3d78..4dd9e7eb3 100755 --- a/ci/kokoro/docker/build-in-docker-cmake.sh +++ b/ci/kokoro/docker/build-in-docker-cmake.sh @@ -58,6 +58,10 @@ if [[ "${CODE_COVERAGE:-}" == "yes" ]]; then "-DCMAKE_BUILD_TYPE=Coverage") fi +if [[ "${USE_NINJA:-}" == "yes" ]]; then + cmake_flags+=( "-GNinja" ) +fi + # Avoid unbound variable error with older bash if [[ "${#cmake_flags[@]}" == 0 ]]; then cmake "-H${SOURCE_DIR}" "-B${BINARY_DIR}" diff --git a/ci/kokoro/docker/build.sh b/ci/kokoro/docker/build.sh index 87edff528..fbd886f02 100755 --- a/ci/kokoro/docker/build.sh +++ b/ci/kokoro/docker/build.sh @@ -78,6 +78,9 @@ elif [[ "${BUILD_NAME}" = "clang-3.8" ]]; then export DISTRO_VERSION=16.04 export CC=clang export CXX=clang++ +elif [[ "${BUILD_NAME}" = "ninja" ]]; then + # Compiling with Ninja can catch bugs that may not be caught using Make. + export USE_NINJA=yes else echo "Unknown BUILD_NAME (${BUILD_NAME}). Fix the Kokoro .cfg file." exit 1 @@ -211,6 +214,10 @@ docker_flags=( # CMake builds use this flag. "--env" "CODE_COVERAGE=${CODE_COVERAGE:-}" + # If set to 'yes', use Ninja as the CMake generator. Ninja is more strict + # that Make and can detect errors in your CMake files, it is also faster. + "--env" "USE_NINJA=${USE_NINJA:-}" + # If set, pass -DGOOGLE_CLOUD_CPP_CXX_STANDARD= to CMake. "--env" "GOOGLE_CLOUD_CPP_CXX_STANDARD=${GOOGLE_CLOUD_CPP_CXX_STANDARD:-}" diff --git a/ci/kokoro/docker/ninja-presubmit.cfg b/ci/kokoro/docker/ninja-presubmit.cfg new file mode 100644 index 000000000..e69de29bb diff --git a/ci/kokoro/docker/ninja.cfg b/ci/kokoro/docker/ninja.cfg new file mode 100644 index 000000000..e69de29bb From 7abccfa1ecc1a0d45673c25e4cfc33ebfb90c74e Mon Sep 17 00:00:00 2001 From: Scott Hart Date: Wed, 11 Dec 2019 16:18:51 -0500 Subject: [PATCH 26/34] chore: update googleapis version (#29) --- CMakeLists.txt | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6d04e63fa..88f3c2a5c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,7 +21,7 @@ set(PACKAGE_BUGREPORT "https://github.com/googleapis/google-cloud-cpp/issues") project(googleapis-cpp-protos CXX C) set(GOOGLEAPIS_CPP_PROTOS_VERSION_MAJOR 0) -set(GOOGLEAPIS_CPP_PROTOS_VERSION_MINOR 2) +set(GOOGLEAPIS_CPP_PROTOS_VERSION_MINOR 3) set(GOOGLEAPIS_CPP_PROTOS_VERSION_PATCH 0) string(CONCAT GOOGLE_APIS_CPP_PROTOS_VERSION @@ -39,10 +39,10 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) # downloaded from GitHub. set( GOOGLE_CLOUD_CPP_GOOGLEAPIS_URL - "https://github.com/googleapis/googleapis/archive/c6e62c7e5e61e6dae7fdc3bc3de81f60e6a9445c.tar.gz" + "https://github.com/googleapis/googleapis/archive/19c4589a3cb44b3679f7b3fba88365b3d055d5f8.tar.gz" ) set(GOOGLE_CLOUD_CPP_GOOGLEAPIS_SHA256 - "33520d6ac51fbb2ca136c06b32b5f5f04f9b5ae8596b161dbe0ae05b1927b4de") + "ef455e46cfb967962aef30248f1a2a69bc78b041e89b04644e24e7844f0215c4") set(GOOGLEAPIS_CPP_SOURCE "${CMAKE_BINARY_DIR}/external/googleapis/src/googleapis_download") @@ -75,7 +75,6 @@ set(GOOGLEAPIS_CPP_PROTO_FILES "google/bigtable/v2/bigtable.proto" "google/bigtable/v2/data.proto" "google/cloud/bigquery/connection/v1beta1/connection.proto" - "google/cloud/bigquery/datatransfer/v1/datasource.proto" "google/cloud/bigquery/datatransfer/v1/datatransfer.proto" "google/cloud/bigquery/datatransfer/v1/transfer.proto" "google/cloud/bigquery/logging/v1/audit_data.proto" @@ -236,7 +235,6 @@ googleapis_cpp_add_library("google/devtools/cloudtrace/v2/tracing.proto" google_cloud_cpp_grpcpp_library( googleapis_cpp_cloud_bigquery_protos "${GOOGLEAPIS_CPP_SOURCE}/google/cloud/bigquery/connection/v1beta1/connection.proto" - "${GOOGLEAPIS_CPP_SOURCE}/google/cloud/bigquery/datatransfer/v1/datasource.proto" "${GOOGLEAPIS_CPP_SOURCE}/google/cloud/bigquery/datatransfer/v1/datatransfer.proto" "${GOOGLEAPIS_CPP_SOURCE}/google/cloud/bigquery/datatransfer/v1/transfer.proto" "${GOOGLEAPIS_CPP_SOURCE}/google/cloud/bigquery/logging/v1/audit_data.proto" From 20009f59de903d5a70038adee308020a82e3ecad Mon Sep 17 00:00:00 2001 From: Carlos O'Ryan Date: Wed, 15 Jan 2020 17:44:36 -0500 Subject: [PATCH 27/34] ci: verify pkg-config files actually work (#30) Change the CI builds to verify the pkg-config files we create actually work. Some improvements in the `.*ignore` files. --- .dockerignore | 22 +++++++++++++++ .gitignore | 3 -- ci/test-install/bigquery/Makefile | 36 ++++++++++++++++++++++++ ci/test-install/bigtable/Makefile | 36 ++++++++++++++++++++++++ ci/test-install/compile-test-projects.sh | 22 ++++++++++----- ci/test-install/spanner/Makefile | 36 ++++++++++++++++++++++++ 6 files changed, 145 insertions(+), 10 deletions(-) create mode 100644 .dockerignore create mode 100644 ci/test-install/bigquery/Makefile create mode 100644 ci/test-install/bigtable/Makefile create mode 100644 ci/test-install/spanner/Makefile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..4b7b2c0bd --- /dev/null +++ b/.dockerignore @@ -0,0 +1,22 @@ +# Common build output directory names +.build/ +_build/ +build-output/ +cmake-out/ + +# Common bazel output directories +bazel-* + +# Backup files for Emacs +*~ + +# Ignore IDEA / IntelliJ files +.idea/ +cmake-build-*/ + +# This is a staging directory used to upload the documents to gihub.io +github-io-staging/ + +# Ignore Visual Studio Code files +.vsbuild/ +.vscode/ diff --git a/.gitignore b/.gitignore index 765f3e124..4b7b2c0bd 100644 --- a/.gitignore +++ b/.gitignore @@ -20,6 +20,3 @@ github-io-staging/ # Ignore Visual Studio Code files .vsbuild/ .vscode/ - -google/cloud/storage/testbench/__pycache__/ -google/cloud/storage/testbench/*.pyc diff --git a/ci/test-install/bigquery/Makefile b/ci/test-install/bigquery/Makefile new file mode 100644 index 000000000..bca2a7dc5 --- /dev/null +++ b/ci/test-install/bigquery/Makefile @@ -0,0 +1,36 @@ +# Copyright 2019 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 +# +# http://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. + +# A simple Makefile to test the `install` target. +# +# This is not intended to be a demonstration of how to write good Makefiles, +# nor is it a general solution on how to build Makefiles for google-cloud-cpp. +# It is simply a minimal file to test the installed pkg-config support files. + +# The CXX, CXXFLAGS and CXXLD variables are hard-coded. These values work for +# our tests, but applications would typically make them configurable parameters. +CXX=g++ -std=c++11 +CXXLD=$(CXX) + +all: main + +# Configuration variables to compile and link against the library. +PROTOS := googleapis_cpp_cloud_bigquery_protos +CXXFLAGS := $(shell pkg-config $(PROTOS) --cflags) +CXXLDFLAGS := $(shell pkg-config $(PROTOS) --libs-only-L) +LIBS := $(shell pkg-config $(PROTOS) --libs-only-l) + +# A target using the Google Cloud Storage C++ client library. +main: main.cc + $(CXXLD) $(CXXFLAGS) $(CXXFLAGS) $(CXXLDFLAGS) -o $@ $^ $(LIBS) diff --git a/ci/test-install/bigtable/Makefile b/ci/test-install/bigtable/Makefile new file mode 100644 index 000000000..5643b234d --- /dev/null +++ b/ci/test-install/bigtable/Makefile @@ -0,0 +1,36 @@ +# Copyright 2019 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 +# +# http://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. + +# A simple Makefile to test the `install` target. +# +# This is not intended to be a demonstration of how to write good Makefiles, +# nor is it a general solution on how to build Makefiles for google-cloud-cpp. +# It is simply a minimal file to test the installed pkg-config support files. + +# The CXX, CXXFLAGS and CXXLD variables are hard-coded. These values work for +# our tests, but applications would typically make them configurable parameters. +CXX=g++ -std=c++11 +CXXLD=$(CXX) + +all: main + +# Configuration variables to compile and link against the library. +PROTOS := googleapis_cpp_bigtable_protos +CXXFLAGS := $(shell pkg-config $(PROTOS) --cflags) +CXXLDFLAGS := $(shell pkg-config $(PROTOS) --libs-only-L) +LIBS := $(shell pkg-config $(PROTOS) --libs-only-l) + +# A target using the Google Cloud Storage C++ client library. +main: main.cc + $(CXXLD) $(CXXFLAGS) $(CXXFLAGS) $(CXXLDFLAGS) -o $@ $^ $(LIBS) diff --git a/ci/test-install/compile-test-projects.sh b/ci/test-install/compile-test-projects.sh index 47d612833..d5398f1e4 100755 --- a/ci/test-install/compile-test-projects.sh +++ b/ci/test-install/compile-test-projects.sh @@ -19,13 +19,7 @@ set -eu -# For BigQuery protos -cp -R /home/build/cpp-cmakefiles/ci/test-install/bigquery \ - /home/build/test-install-bigquery -cd /home/build/test-install-bigquery -cmake -H. -Bcmake-out -cmake --build cmake-out -- -j "$(nproc)" -cmake-out/utilize-googleapis +# Verify the installed CMake config and pkgconfig files are actually usable. # For Bigtable protos cp -R /home/build/cpp-cmakefiles/ci/test-install/bigtable \ @@ -34,6 +28,18 @@ cd /home/build/test-install-bigtable cmake -H. -Bcmake-out cmake --build cmake-out -- -j "$(nproc)" cmake-out/utilize-googleapis +env PKG_CONFIG_PATH=/usr/local/lib64/pkgconfig:/usr/local/lib/pkgconfig \ + make + +# For BigQuery protos +cp -R /home/build/cpp-cmakefiles/ci/test-install/bigquery \ + /home/build/test-install-bigquery +cd /home/build/test-install-bigquery +cmake -H. -Bcmake-out +cmake --build cmake-out -- -j "$(nproc)" +cmake-out/utilize-googleapis +env PKG_CONFIG_PATH=/usr/local/lib64/pkgconfig:/usr/local/lib/pkgconfig \ + make # For spanner protos cp -R /home/build/cpp-cmakefiles/ci/test-install/spanner \ @@ -42,3 +48,5 @@ cd /home/build/test-install-spanner cmake -H. -Bcmake-out cmake --build cmake-out -- -j "$(nproc)" cmake-out/utilize-googleapis +env PKG_CONFIG_PATH=/usr/local/lib64/pkgconfig:/usr/local/lib/pkgconfig \ + make diff --git a/ci/test-install/spanner/Makefile b/ci/test-install/spanner/Makefile new file mode 100644 index 000000000..74bf292ce --- /dev/null +++ b/ci/test-install/spanner/Makefile @@ -0,0 +1,36 @@ +# Copyright 2019 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 +# +# http://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. + +# A simple Makefile to test the `install` target. +# +# This is not intended to be a demonstration of how to write good Makefiles, +# nor is it a general solution on how to build Makefiles for google-cloud-cpp. +# It is simply a minimal file to test the installed pkg-config support files. + +# The CXX, CXXFLAGS and CXXLD variables are hard-coded. These values work for +# our tests, but applications would typically make them configurable parameters. +CXX=g++ -std=c++11 +CXXLD=$(CXX) + +all: main + +# Configuration variables to compile and link against the library. +PROTOS := googleapis_cpp_spanner_protos +CXXFLAGS := $(shell pkg-config $(PROTOS) --cflags) +CXXLDFLAGS := $(shell pkg-config $(PROTOS) --libs-only-L) +LIBS := $(shell pkg-config $(PROTOS) --libs-only-l) + +# A target using the Google Cloud Storage C++ client library. +main: main.cc + $(CXXLD) $(CXXFLAGS) $(CXXFLAGS) $(CXXLDFLAGS) -o $@ $^ $(LIBS) From 52758bec0324a6b120f0bb938f527b1759a0da3d Mon Sep 17 00:00:00 2001 From: Carlos O'Ryan Date: Thu, 16 Jan 2020 11:04:40 -0500 Subject: [PATCH 28/34] feat: add Cloud Pub/Sub protos (#31) --- CMakeLists.txt | 14 +++++ ci/kokoro/install/Dockerfile.fedora-30-shared | 4 ++ ci/test-install/compile-test-projects.sh | 53 +++++++++---------- ci/test-install/pubsub/CMakeLists.txt | 28 ++++++++++ ci/test-install/pubsub/Makefile | 36 +++++++++++++ ci/test-install/pubsub/main.cc | 22 ++++++++ cmake/config.cmake.in | 1 + 7 files changed, 129 insertions(+), 29 deletions(-) create mode 100644 ci/test-install/pubsub/CMakeLists.txt create mode 100644 ci/test-install/pubsub/Makefile create mode 100644 ci/test-install/pubsub/main.cc diff --git a/CMakeLists.txt b/CMakeLists.txt index 88f3c2a5c..187a12bf9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -87,6 +87,7 @@ set(GOOGLEAPIS_CPP_PROTO_FILES "google/cloud/bigquery/v2/model.proto" "google/cloud/bigquery/v2/model_reference.proto" "google/cloud/bigquery/v2/standard_sql.proto" + "google/pubsub/v1/pubsub.proto" "google/spanner/admin/database/v1/spanner_database_admin.proto" "google/spanner/admin/instance/v1/spanner_instance_admin.proto" "google/spanner/v1/keys.proto" @@ -281,6 +282,18 @@ target_link_libraries(googleapis_cpp_bigtable_protos googleapis-c++::iam_v1_iam_policy_protos PRIVATE googleapis_cpp_common_flags) +google_cloud_cpp_grpcpp_library( + googleapis_cpp_pubsub_protos + "${GOOGLEAPIS_CPP_SOURCE}/google/pubsub/v1/pubsub.proto" + PROTO_PATH_DIRECTORIES + "${GOOGLEAPIS_CPP_SOURCE}" + "${PROTO_INCLUDE_DIR}") +googleapis_cpp_set_version_and_alias(pubsub_protos) +target_link_libraries(googleapis_cpp_pubsub_protos + PUBLIC googleapis-c++::api_annotations_protos + googleapis-c++::api_client_protos + PRIVATE googleapis_cpp_common_flags) + google_cloud_cpp_grpcpp_library( googleapis_cpp_spanner_protos "${GOOGLEAPIS_CPP_SOURCE}/google/spanner/admin/database/v1/spanner_database_admin.proto" @@ -310,6 +323,7 @@ include(GNUInstallDirs) set(googleapis_cpp_installed_libraries_list googleapis_cpp_bigtable_protos googleapis_cpp_cloud_bigquery_protos + googleapis_cpp_pubsub_protos googleapis_cpp_spanner_protos googleapis_cpp_longrunning_operations_protos googleapis_cpp_api_http_protos diff --git a/ci/kokoro/install/Dockerfile.fedora-30-shared b/ci/kokoro/install/Dockerfile.fedora-30-shared index 3a0accf70..572018f99 100644 --- a/ci/kokoro/install/Dockerfile.fedora-30-shared +++ b/ci/kokoro/install/Dockerfile.fedora-30-shared @@ -50,6 +50,10 @@ RUN cmake -H. -Bcmake-out -DBUILD_SHARED_LIBS=yes RUN cmake --build cmake-out -- -j $(nproc) WORKDIR /home/build/cpp-cmakefiles/cmake-out RUN cmake --build . --target install +# The share libraries will install in `/usr/local/lib64` we need that directory +# in the ld.so cache: +RUN echo "/usr/local/lib64" | tee /etc/ld.so.conf.d/local.conf +RUN ldconfig # ``` ## [END INSTALL.md] diff --git a/ci/test-install/compile-test-projects.sh b/ci/test-install/compile-test-projects.sh index d5398f1e4..25eea82ff 100755 --- a/ci/test-install/compile-test-projects.sh +++ b/ci/test-install/compile-test-projects.sh @@ -21,32 +21,27 @@ set -eu # Verify the installed CMake config and pkgconfig files are actually usable. -# For Bigtable protos -cp -R /home/build/cpp-cmakefiles/ci/test-install/bigtable \ - /home/build/test-install-bigtable -cd /home/build/test-install-bigtable -cmake -H. -Bcmake-out -cmake --build cmake-out -- -j "$(nproc)" -cmake-out/utilize-googleapis -env PKG_CONFIG_PATH=/usr/local/lib64/pkgconfig:/usr/local/lib/pkgconfig \ - make - -# For BigQuery protos -cp -R /home/build/cpp-cmakefiles/ci/test-install/bigquery \ - /home/build/test-install-bigquery -cd /home/build/test-install-bigquery -cmake -H. -Bcmake-out -cmake --build cmake-out -- -j "$(nproc)" -cmake-out/utilize-googleapis -env PKG_CONFIG_PATH=/usr/local/lib64/pkgconfig:/usr/local/lib/pkgconfig \ - make - -# For spanner protos -cp -R /home/build/cpp-cmakefiles/ci/test-install/spanner \ - /home/build/test-install-spanner -cd /home/build/test-install-spanner -cmake -H. -Bcmake-out -cmake --build cmake-out -- -j "$(nproc)" -cmake-out/utilize-googleapis -env PKG_CONFIG_PATH=/usr/local/lib64/pkgconfig:/usr/local/lib/pkgconfig \ - make +for subdir in bigquery bigtable pubsub spanner; do + # Compile a test program using CMake. + echo "================================================================" + echo "Testing ${subdir} $(date) with CMake" + echo "================================================================" + src_dir="/home/build/cpp-cmakefiles/ci/test-install/${subdir}" + cmake_dir="/home/build/test-cmake-${subdir}" + make_dir="/home/build/test-make-${subdir}" + cmake -H"${src_dir}" -B"${cmake_dir}" + cmake --build "${cmake_dir}" -- -j "$(nproc)" + # Verify the generated program is runnable + "${cmake_dir}/utilize-googleapis" + echo "================================================================" + echo "Testing ${subdir} $(date) with Make" + echo "================================================================" + cp -R "${src_dir}" "${make_dir}" + cd "${make_dir}" + # With Make we may need to set PKG_CONFIG_PATH because the code is installed + # in /usr/local and that is not a default search location in some distros. + env PKG_CONFIG_PATH=/usr/local/lib64/pkgconfig:/usr/local/lib/pkgconfig \ + make + # Verify the generated program is runnable + "${make_dir}/main" +done diff --git a/ci/test-install/pubsub/CMakeLists.txt b/ci/test-install/pubsub/CMakeLists.txt new file mode 100644 index 000000000..cc8d59e18 --- /dev/null +++ b/ci/test-install/pubsub/CMakeLists.txt @@ -0,0 +1,28 @@ +# ~~~ +# Copyright 2019 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 +# +# http://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. +# ~~~ + +cmake_minimum_required(VERSION 3.5) + +project(utilize-googleapis CXX C) + +# Configure the compiler options, we will be using C++11 features. +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +find_package(googleapis REQUIRED) + +add_executable(utilize-googleapis main.cc) +target_link_libraries(utilize-googleapis googleapis-c++::pubsub_protos) diff --git a/ci/test-install/pubsub/Makefile b/ci/test-install/pubsub/Makefile new file mode 100644 index 000000000..a5cbdcf78 --- /dev/null +++ b/ci/test-install/pubsub/Makefile @@ -0,0 +1,36 @@ +# Copyright 2019 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 +# +# http://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. + +# A simple Makefile to test the `install` target. +# +# This is not intended to be a demonstration of how to write good Makefiles, +# nor is it a general solution on how to build Makefiles for google-cloud-cpp. +# It is simply a minimal file to test the installed pkg-config support files. + +# The CXX, CXXFLAGS and CXXLD variables are hard-coded. These values work for +# our tests, but applications would typically make them configurable parameters. +CXX=g++ -std=c++11 +CXXLD=$(CXX) + +all: main + +# Configuration variables to compile and link against the library. +PROTOS := googleapis_cpp_pubsub_protos +CXXFLAGS := $(shell pkg-config $(PROTOS) --cflags) +CXXLDFLAGS := $(shell pkg-config $(PROTOS) --libs-only-L) +LIBS := $(shell pkg-config $(PROTOS) --libs-only-l) + +# A target using the Google Cloud Storage C++ client library. +main: main.cc + $(CXXLD) $(CXXFLAGS) $(CXXFLAGS) $(CXXLDFLAGS) -o $@ $^ $(LIBS) diff --git a/ci/test-install/pubsub/main.cc b/ci/test-install/pubsub/main.cc new file mode 100644 index 000000000..05549169d --- /dev/null +++ b/ci/test-install/pubsub/main.cc @@ -0,0 +1,22 @@ +// Copyright 2019 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 +// +// http://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 +#include + +int main() { + auto creds = grpc::InsecureChannelCredentials(); + auto channel = grpc::CreateChannel("localhost:12345", creds); + auto stub = google::pubsub::v1::Publisher::NewStub(channel); +} diff --git a/cmake/config.cmake.in b/cmake/config.cmake.in index 90c3d4648..e7b77c33c 100644 --- a/cmake/config.cmake.in +++ b/cmake/config.cmake.in @@ -34,6 +34,7 @@ foreach (_target iam_v1_options iam_v1_policy longrunning_operations + pubsub rpc_error_details rpc_status spanner From 7bf4c67daa42f8cd0afcdc027cb6bcc1697943c6 Mon Sep 17 00:00:00 2001 From: Carlos O'Ryan Date: Thu, 16 Jan 2020 13:00:54 -0500 Subject: [PATCH 29/34] chore: bump version numbers (#32) I need to create a v0.4.x release and the version numbers are at v0.3.0 --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 187a12bf9..bed422508 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,8 +21,8 @@ set(PACKAGE_BUGREPORT "https://github.com/googleapis/google-cloud-cpp/issues") project(googleapis-cpp-protos CXX C) set(GOOGLEAPIS_CPP_PROTOS_VERSION_MAJOR 0) -set(GOOGLEAPIS_CPP_PROTOS_VERSION_MINOR 3) -set(GOOGLEAPIS_CPP_PROTOS_VERSION_PATCH 0) +set(GOOGLEAPIS_CPP_PROTOS_VERSION_MINOR 4) +set(GOOGLEAPIS_CPP_PROTOS_VERSION_PATCH 1) string(CONCAT GOOGLE_APIS_CPP_PROTOS_VERSION "${GOOGLEAPIS_CPP_PROTOS_VERSION_MAJOR}" From 80c043faf913534ac0a97da58e3d50c073f226c1 Mon Sep 17 00:00:00 2001 From: Carlos O'Ryan Date: Thu, 16 Jan 2020 14:01:52 -0500 Subject: [PATCH 30/34] chore: bump release numbers for future releases (#33) --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bed422508..b9c0e7b9c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,8 +21,8 @@ set(PACKAGE_BUGREPORT "https://github.com/googleapis/google-cloud-cpp/issues") project(googleapis-cpp-protos CXX C) set(GOOGLEAPIS_CPP_PROTOS_VERSION_MAJOR 0) -set(GOOGLEAPIS_CPP_PROTOS_VERSION_MINOR 4) -set(GOOGLEAPIS_CPP_PROTOS_VERSION_PATCH 1) +set(GOOGLEAPIS_CPP_PROTOS_VERSION_MINOR 5) +set(GOOGLEAPIS_CPP_PROTOS_VERSION_PATCH 0) string(CONCAT GOOGLE_APIS_CPP_PROTOS_VERSION "${GOOGLEAPIS_CPP_PROTOS_VERSION_MAJOR}" From 1d322760ae4c270dfba6e4ca3203395e89f30b66 Mon Sep 17 00:00:00 2001 From: Bradley White <14679271+devbww@users.noreply.github.com> Date: Sat, 8 Feb 2020 14:51:49 -0500 Subject: [PATCH 31/34] fix: correct value in GOOGLE_CLOUD_CPP_PC_REQUIRES (#34) `googleapis_cpp_bigquery_protos` => `googleapis_cpp_cloud_bigquery_protos`. --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b9c0e7b9c..fe830599b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -420,7 +420,7 @@ set(GOOGLE_CLOUD_CPP_PC_DESCRIPTION # need to add the separator ourselves. string(CONCAT GOOGLE_CLOUD_CPP_PC_REQUIRES "googleapis_cpp_bigtable_protos" - " googleapis_cpp_bigquery_protos" + " googleapis_cpp_cloud_bigquery_protos" " googleapis_cpp_iam_v1_iam_policy_protos" " googleapis_cpp_iam_v1_options_protos" " googleapis_cpp_iam_v1_policy_protos" From 3e4f8c025e7618abee90ae35e64f6577e96c1c2c Mon Sep 17 00:00:00 2001 From: Carlos O'Ryan Date: Mon, 17 Feb 2020 20:17:01 -0500 Subject: [PATCH 32/34] fix: fix dependencies for trace.proto (#35) --- CMakeLists.txt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fe830599b..0667b7756 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -227,7 +227,11 @@ googleapis_cpp_add_library("google/longrunning/operations.proto" api_annotations_protos rpc_status_protos) googleapis_cpp_add_library("google/devtools/cloudtrace/v2/trace.proto" - api_annotations_protos rpc_status_protos) + api_annotations_protos + api_client_protos + api_field_behavior_protos + api_resource_protos + rpc_status_protos) googleapis_cpp_add_library("google/devtools/cloudtrace/v2/tracing.proto" devtools_cloudtrace_v2_trace_protos api_annotations_protos From c1713cb00d5969dcb1a8b0775817d6b3d32886c3 Mon Sep 17 00:00:00 2001 From: Carlos O'Ryan Date: Tue, 25 Feb 2020 13:20:33 -0500 Subject: [PATCH 33/34] feat: update protos to 2020-02-25 version (#37) Update the dependencies based on the new protos. --- CMakeLists.txt | 307 ++++++++++++++++---------------- ci/kokoro/Dockerfile.fedora | 2 +- cmake/CompileProtos.cmake | 124 +++++-------- cmake/FindProtobufTargets.cmake | 71 ++++---- cmake/FindgRPC.cmake | 154 ++++++++-------- cmake/SelectMSVCRuntime.cmake | 13 +- 6 files changed, 306 insertions(+), 365 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0667b7756..7ead2b05c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,12 +24,13 @@ set(GOOGLEAPIS_CPP_PROTOS_VERSION_MAJOR 0) set(GOOGLEAPIS_CPP_PROTOS_VERSION_MINOR 5) set(GOOGLEAPIS_CPP_PROTOS_VERSION_PATCH 0) -string(CONCAT GOOGLE_APIS_CPP_PROTOS_VERSION - "${GOOGLEAPIS_CPP_PROTOS_VERSION_MAJOR}" - "." - "${GOOGLEAPIS_CPP_PROTOS_VERSION_MINOR}" - "." - "${GOOGLEAPIS_CPP_PROTOS_VERSION_PATCH}") +string( + CONCAT GOOGLE_APIS_CPP_PROTOS_VERSION + "${GOOGLEAPIS_CPP_PROTOS_VERSION_MAJOR}" + "." + "${GOOGLEAPIS_CPP_PROTOS_VERSION_MINOR}" + "." + "${GOOGLEAPIS_CPP_PROTOS_VERSION_PATCH}") # Configure the compiler options, we will be using C++11 features. set(CMAKE_CXX_STANDARD 11) @@ -37,12 +38,11 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) # Give application developers a hook to configure the version and hash # downloaded from GitHub. -set( - GOOGLE_CLOUD_CPP_GOOGLEAPIS_URL - "https://github.com/googleapis/googleapis/archive/19c4589a3cb44b3679f7b3fba88365b3d055d5f8.tar.gz" - ) +set(GOOGLE_CLOUD_CPP_GOOGLEAPIS_URL + "https://github.com/googleapis/googleapis/archive/0b1876b35e98f560f9c9ca9797955f020238a092.tar.gz" +) set(GOOGLE_CLOUD_CPP_GOOGLEAPIS_SHA256 - "ef455e46cfb967962aef30248f1a2a69bc78b041e89b04644e24e7844f0215c4") + "4b0db7279ddf0b9ec6a39fd741ef4694b20025fe38f7d98f1ab1ba224c417c2d") set(GOOGLEAPIS_CPP_SOURCE "${CMAKE_BINARY_DIR}/external/googleapis/src/googleapis_download") @@ -104,16 +104,17 @@ foreach (proto ${GOOGLEAPIS_CPP_PROTO_FILES}) endforeach () include(ExternalProject) -ExternalProject_Add(googleapis_download - EXCLUDE_FROM_ALL ON - PREFIX "${CMAKE_BINARY_DIR}/external/googleapis" - URL ${GOOGLE_CLOUD_CPP_GOOGLEAPIS_URL} - URL_HASH SHA256=${GOOGLE_CLOUD_CPP_GOOGLEAPIS_SHA256} - CONFIGURE_COMMAND "" - BUILD_COMMAND "" - INSTALL_COMMAND "" - BUILD_BYPRODUCTS ${GOOGLEAPIS_CPP_BYPRODUCTS} - LOG_DOWNLOAD OFF) +ExternalProject_Add( + googleapis_download + EXCLUDE_FROM_ALL ON + PREFIX "${CMAKE_BINARY_DIR}/external/googleapis" + URL ${GOOGLE_CLOUD_CPP_GOOGLEAPIS_URL} + URL_HASH SHA256=${GOOGLE_CLOUD_CPP_GOOGLEAPIS_SHA256} + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + INSTALL_COMMAND "" + BUILD_BYPRODUCTS ${GOOGLEAPIS_CPP_BYPRODUCTS} + LOG_DOWNLOAD OFF) list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake") find_package(ProtobufTargets REQUIRED) @@ -137,19 +138,12 @@ include(CompileProtos) google_cloud_cpp_add_protos_property() function (googleapis_cpp_short_name var proto) - string(REPLACE "google/" - "" - short_name - "${proto}") - string(REPLACE "/" - "_" - short_name - "${short_name}") - string(REPLACE ".proto" - "_protos" - short_name - "${short_name}") - set("${var}" "${short_name}" PARENT_SCOPE) + string(REPLACE "google/" "" short_name "${proto}") + string(REPLACE "/" "_" short_name "${short_name}") + string(REPLACE ".proto" "_protos" short_name "${short_name}") + set("${var}" + "${short_name}" + PARENT_SCOPE) endfunction () # Create a single source proto library. @@ -158,11 +152,10 @@ endfunction () # * (optional) ARGN: proto libraries the new library depends on. function (googleapis_cpp_add_library proto) googleapis_cpp_short_name(short_name "${proto}") - google_cloud_cpp_grpcpp_library(googleapis_cpp_${short_name} - "${GOOGLEAPIS_CPP_SOURCE}/${proto}" - PROTO_PATH_DIRECTORIES - "${GOOGLEAPIS_CPP_SOURCE}" - "${PROTO_INCLUDE_DIR}") + google_cloud_cpp_grpcpp_library( + googleapis_cpp_${short_name} "${GOOGLEAPIS_CPP_SOURCE}/${proto}" + PROTO_PATH_DIRECTORIES "${GOOGLEAPIS_CPP_SOURCE}" + "${PROTO_INCLUDE_DIR}") googleapis_cpp_set_version_and_alias("${short_name}") @@ -175,34 +168,34 @@ function (googleapis_cpp_add_library proto) target_link_libraries("googleapis_cpp_${short_name}" PRIVATE googleapis_cpp_common_flags) else () - target_link_libraries("googleapis_cpp_${short_name}" - PUBLIC ${public_deps} - PRIVATE googleapis_cpp_common_flags) + target_link_libraries( + "googleapis_cpp_${short_name}" + PUBLIC ${public_deps} + PRIVATE googleapis_cpp_common_flags) endif () endfunction () function (googleapis_cpp_set_version_and_alias short_name) add_dependencies("googleapis_cpp_${short_name}" googleapis_download) - set_target_properties("googleapis_cpp_${short_name}" - PROPERTIES VERSION - "${GOOGLE_APIS_CPP_PROTOS_VERSION}" - SOVERSION - ${GOOGLEAPIS_CPP_PROTOS_VERSION_MAJOR}) + set_target_properties( + "googleapis_cpp_${short_name}" + PROPERTIES VERSION "${GOOGLE_APIS_CPP_PROTOS_VERSION}" + SOVERSION ${GOOGLEAPIS_CPP_PROTOS_VERSION_MAJOR}) add_library("googleapis-c++::${short_name}" ALIAS "googleapis_cpp_${short_name}") endfunction () googleapis_cpp_add_library("google/api/http.proto") +googleapis_cpp_add_library("google/api/metric.proto" api_launch_stage_protos + api_label_protos) +googleapis_cpp_add_library("google/api/monitored_resource.proto" + api_launch_stage_protos api_label_protos) googleapis_cpp_add_library("google/api/annotations.proto" api_http_protos) googleapis_cpp_add_library("google/api/auth.proto" api_annotations_protos) googleapis_cpp_add_library("google/api/client.proto") googleapis_cpp_add_library("google/api/field_behavior.proto") googleapis_cpp_add_library("google/api/label.proto") googleapis_cpp_add_library("google/api/launch_stage.proto") -googleapis_cpp_add_library("google/api/metric.proto" api_launch_stage_protos - api_label_protos) -googleapis_cpp_add_library("google/api/monitored_resource.proto" - api_launch_stage_protos api_label_protos) googleapis_cpp_add_library("google/api/resource.proto") googleapis_cpp_add_library("google/type/expr.proto") @@ -211,31 +204,29 @@ googleapis_cpp_add_library("google/rpc/error_details.proto") googleapis_cpp_add_library("google/rpc/status.proto" rpc_error_details_protos) googleapis_cpp_add_library("google/iam/v1/options.proto" api_annotations_protos) -googleapis_cpp_add_library("google/iam/v1/policy.proto" - api_annotations_protos - api_resource_protos +googleapis_cpp_add_library("google/iam/v1/policy.proto" api_annotations_protos type_expr_protos) -googleapis_cpp_add_library("google/iam/v1/iam_policy.proto" - api_annotations_protos - api_client_protos - api_field_behavior_protos - iam_v1_options_protos - iam_v1_policy_protos) +googleapis_cpp_add_library( + "google/iam/v1/iam_policy.proto" + api_annotations_protos + api_client_protos + api_field_behavior_protos + api_resource_protos + iam_v1_options_protos + iam_v1_policy_protos) -googleapis_cpp_add_library("google/longrunning/operations.proto" - api_annotations_protos rpc_status_protos) +googleapis_cpp_add_library( + "google/longrunning/operations.proto" api_annotations_protos + api_client_protos rpc_status_protos) -googleapis_cpp_add_library("google/devtools/cloudtrace/v2/trace.proto" - api_annotations_protos - api_client_protos - api_field_behavior_protos - api_resource_protos - rpc_status_protos) -googleapis_cpp_add_library("google/devtools/cloudtrace/v2/tracing.proto" - devtools_cloudtrace_v2_trace_protos - api_annotations_protos - rpc_status_protos) +googleapis_cpp_add_library( + "google/devtools/cloudtrace/v2/trace.proto" api_annotations_protos + api_field_behavior_protos api_resource_protos rpc_status_protos) +googleapis_cpp_add_library( + "google/devtools/cloudtrace/v2/tracing.proto" + devtools_cloudtrace_v2_trace_protos api_annotations_protos + api_client_protos api_field_behavior_protos rpc_status_protos) google_cloud_cpp_grpcpp_library( googleapis_cpp_cloud_bigquery_protos @@ -256,14 +247,17 @@ google_cloud_cpp_grpcpp_library( "${GOOGLEAPIS_CPP_SOURCE}" "${PROTO_INCLUDE_DIR}") googleapis_cpp_set_version_and_alias(cloud_bigquery_protos) -target_link_libraries(googleapis_cpp_cloud_bigquery_protos - PUBLIC googleapis-c++::api_annotations_protos - googleapis-c++::api_http_protos - googleapis-c++::api_field_behavior_protos - googleapis-c++::api_client_protos - googleapis-c++::iam_v1_iam_policy_protos - googleapis-c++::rpc_status_protos - PRIVATE googleapis_cpp_common_flags) +target_link_libraries( + googleapis_cpp_cloud_bigquery_protos + PUBLIC googleapis-c++::api_annotations_protos + googleapis-c++::api_client_protos + googleapis-c++::api_field_behavior_protos + googleapis-c++::api_resource_protos + googleapis-c++::iam_v1_iam_policy_protos + googleapis-c++::iam_v1_policy_protos + googleapis-c++::rpc_status_protos + googleapis-c++::api_http_protos + PRIVATE googleapis_cpp_common_flags) google_cloud_cpp_grpcpp_library( googleapis_cpp_bigtable_protos @@ -278,25 +272,31 @@ google_cloud_cpp_grpcpp_library( "${GOOGLEAPIS_CPP_SOURCE}" "${PROTO_INCLUDE_DIR}") googleapis_cpp_set_version_and_alias(bigtable_protos) -target_link_libraries(googleapis_cpp_bigtable_protos - PUBLIC googleapis-c++::api_annotations_protos - googleapis-c++::api_auth_protos - googleapis-c++::longrunning_operations_protos - googleapis-c++::rpc_status_protos - googleapis-c++::iam_v1_iam_policy_protos - PRIVATE googleapis_cpp_common_flags) +target_link_libraries( + googleapis_cpp_bigtable_protos + PUBLIC googleapis-c++::api_annotations_protos + googleapis-c++::api_client_protos + googleapis-c++::api_field_behavior_protos + googleapis-c++::api_resource_protos + googleapis-c++::iam_v1_iam_policy_protos + googleapis-c++::iam_v1_policy_protos + googleapis-c++::longrunning_operations_protos + googleapis-c++::rpc_status_protos + googleapis-c++::api_auth_protos + PRIVATE googleapis_cpp_common_flags) google_cloud_cpp_grpcpp_library( googleapis_cpp_pubsub_protos "${GOOGLEAPIS_CPP_SOURCE}/google/pubsub/v1/pubsub.proto" - PROTO_PATH_DIRECTORIES - "${GOOGLEAPIS_CPP_SOURCE}" - "${PROTO_INCLUDE_DIR}") + PROTO_PATH_DIRECTORIES "${GOOGLEAPIS_CPP_SOURCE}" "${PROTO_INCLUDE_DIR}") googleapis_cpp_set_version_and_alias(pubsub_protos) -target_link_libraries(googleapis_cpp_pubsub_protos - PUBLIC googleapis-c++::api_annotations_protos - googleapis-c++::api_client_protos - PRIVATE googleapis_cpp_common_flags) +target_link_libraries( + googleapis_cpp_pubsub_protos + PUBLIC googleapis-c++::api_annotations_protos + googleapis-c++::api_client_protos + googleapis-c++::api_field_behavior_protos + googleapis-c++::api_resource_protos + PRIVATE googleapis_cpp_common_flags) google_cloud_cpp_grpcpp_library( googleapis_cpp_spanner_protos @@ -313,12 +313,17 @@ google_cloud_cpp_grpcpp_library( "${GOOGLEAPIS_CPP_SOURCE}" "${PROTO_INCLUDE_DIR}") googleapis_cpp_set_version_and_alias(spanner_protos) -target_link_libraries(googleapis_cpp_spanner_protos - PUBLIC googleapis-c++::api_annotations_protos - googleapis-c++::longrunning_operations_protos - googleapis-c++::rpc_status_protos - googleapis-c++::iam_v1_iam_policy_protos - PRIVATE googleapis_cpp_common_flags) +target_link_libraries( + googleapis_cpp_spanner_protos + PUBLIC googleapis-c++::api_annotations_protos + googleapis-c++::api_client_protos + googleapis-c++::api_field_behavior_protos + googleapis-c++::api_resource_protos + googleapis-c++::iam_v1_iam_policy_protos + googleapis-c++::iam_v1_policy_protos + googleapis-c++::longrunning_operations_protos + googleapis-c++::rpc_status_protos + PRIVATE googleapis_cpp_common_flags) # Install the libraries and headers in the locations determined by # GNUInstallDirs @@ -345,12 +350,13 @@ set(googleapis_cpp_installed_libraries_list googleapis_cpp_rpc_status_protos googleapis_cpp_type_expr_protos) -install(TARGETS ${googleapis_cpp_installed_libraries_list} - googleapis_cpp_common_flags - EXPORT googleapis-targets - RUNTIME DESTINATION bin - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) +install( + TARGETS ${googleapis_cpp_installed_libraries_list} + googleapis_cpp_common_flags + EXPORT googleapis-targets + RUNTIME DESTINATION bin + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) foreach (target ${googleapis_cpp_installed_libraries_list}) google_cloud_cpp_install_proto_library_headers("${target}") @@ -372,14 +378,8 @@ set(GOOGLE_CLOUD_CPP_CONFIG_VERSION_PATCH # Use a function to create a scope for the variables. function (googleapis_cpp_install_pc target) - string(REPLACE "googleapis_cpp_" - "" - _short_name - ${target}) - string(REPLACE "_protos" - "" - _short_name - ${_short_name}) + string(REPLACE "googleapis_cpp_" "" _short_name ${target}) + string(REPLACE "_protos" "" _short_name ${_short_name}) set(GOOGLE_CLOUD_CPP_PC_NAME "The Google APIS C++ ${_short_name} Proto Library") set(GOOGLE_CLOUD_CPP_PC_DESCRIPTION "Compiled proto for C++.") @@ -389,21 +389,20 @@ function (googleapis_cpp_install_pc target) get_target_property(_target_deps ${target} LINK_LIBRARIES) foreach (dep ${_target_deps}) if ("${dep}" MATCHES "^googleapis-c\\+\\+::") - string(REPLACE "googleapis-c++::" - "googleapis_cpp_" - dep - "${dep}") + string(REPLACE "googleapis-c++::" "googleapis_cpp_" dep "${dep}") list(APPEND _target_pc_requires " " "${dep}") endif () endforeach () # These dependencies are required for all the googleapis-c++::* libraries. - list(APPEND _target_pc_requires - " grpc++" - " grpc" - " openssl" - " protobuf" - " zlib" - " libcares") + list( + APPEND + _target_pc_requires + " grpc++" + " grpc" + " openssl" + " protobuf" + " zlib" + " libcares") string(CONCAT GOOGLE_CLOUD_CPP_PC_REQUIRES ${_target_pc_requires}) set(GOOGLE_CLOUD_CPP_PC_LIBS "-l${target}") configure_file("cmake/config.pc.in" "${target}.pc" @ONLY) @@ -422,26 +421,27 @@ set(GOOGLE_CLOUD_CPP_PC_DESCRIPTION "Provides C++ APIs to access Google Cloud Platforms.") # Note the use of spaces, `string(JOIN)` is not available in cmake-3.5, so we # need to add the separator ourselves. -string(CONCAT GOOGLE_CLOUD_CPP_PC_REQUIRES - "googleapis_cpp_bigtable_protos" - " googleapis_cpp_cloud_bigquery_protos" - " googleapis_cpp_iam_v1_iam_policy_protos" - " googleapis_cpp_iam_v1_options_protos" - " googleapis_cpp_iam_v1_policy_protos" - " googleapis_cpp_longrunning_operations_protos" - " googleapis_cpp_api_auth_protos" - " googleapis_cpp_api_annotations_protos" - " googleapis_cpp_api_client_protos" - " googleapis_cpp_api_field_behavior_protos" - " googleapis_cpp_api_http_protos" - " googleapis_cpp_rpc_status_protos" - " googleapis_cpp_rpc_error_details_protos" - " grpc++" - " grpc" - " openssl" - " protobuf" - " zlib" - " libcares") +string( + CONCAT GOOGLE_CLOUD_CPP_PC_REQUIRES + "googleapis_cpp_bigtable_protos" + " googleapis_cpp_cloud_bigquery_protos" + " googleapis_cpp_iam_v1_iam_policy_protos" + " googleapis_cpp_iam_v1_options_protos" + " googleapis_cpp_iam_v1_policy_protos" + " googleapis_cpp_longrunning_operations_protos" + " googleapis_cpp_api_auth_protos" + " googleapis_cpp_api_annotations_protos" + " googleapis_cpp_api_client_protos" + " googleapis_cpp_api_field_behavior_protos" + " googleapis_cpp_api_http_protos" + " googleapis_cpp_rpc_status_protos" + " googleapis_cpp_rpc_error_details_protos" + " grpc++" + " grpc" + " openssl" + " protobuf" + " zlib" + " libcares") set(GOOGLE_CLOUD_CPP_PC_LIBS "") configure_file("cmake/config.pc.in" "googleapis.pc" @ONLY) install(FILES "${CMAKE_CURRENT_BINARY_DIR}/googleapis.pc" @@ -449,11 +449,12 @@ install(FILES "${CMAKE_CURRENT_BINARY_DIR}/googleapis.pc" # Create and install the CMake configuration files. configure_file("cmake/config.cmake.in" "googleapis-config.cmake" @ONLY) -configure_file("cmake/config-version.cmake.in" "googleapis-config-version.cmake" - @ONLY) -install(FILES "${CMAKE_CURRENT_BINARY_DIR}/googleapis-config.cmake" - "${CMAKE_CURRENT_BINARY_DIR}/googleapis-config-version.cmake" - "${PROJECT_SOURCE_DIR}/cmake/FindgRPC.cmake" - "${PROJECT_SOURCE_DIR}/cmake/FindProtobufTargets.cmake" - "${PROJECT_SOURCE_DIR}/cmake/CompileProtos.cmake" - DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/googleapis") +configure_file("cmake/config-version.cmake.in" + "googleapis-config-version.cmake" @ONLY) +install( + FILES "${CMAKE_CURRENT_BINARY_DIR}/googleapis-config.cmake" + "${CMAKE_CURRENT_BINARY_DIR}/googleapis-config-version.cmake" + "${PROJECT_SOURCE_DIR}/cmake/FindgRPC.cmake" + "${PROJECT_SOURCE_DIR}/cmake/FindProtobufTargets.cmake" + "${PROJECT_SOURCE_DIR}/cmake/CompileProtos.cmake" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/googleapis") diff --git a/ci/kokoro/Dockerfile.fedora b/ci/kokoro/Dockerfile.fedora index af3aa3803..c56ace3b1 100644 --- a/ci/kokoro/Dockerfile.fedora +++ b/ci/kokoro/Dockerfile.fedora @@ -35,4 +35,4 @@ RUN chmod 755 /usr/bin/buildifier # "latest" version is updated, and we do not want the builds to break just # because some third party changed something. RUN pip install --upgrade pip -RUN pip install numpy cmake_format==0.5.2 +RUN pip install numpy cmake_format==0.6.9 diff --git a/cmake/CompileProtos.cmake b/cmake/CompileProtos.cmake index 37e71040d..788267c8d 100644 --- a/cmake/CompileProtos.cmake +++ b/cmake/CompileProtos.cmake @@ -19,12 +19,11 @@ # We use a function to define the property so it can be called multiple times # without introducing the property over and over. function (google_cloud_cpp_add_protos_property) - set_property(TARGET - PROPERTY PROTO_SOURCES - BRIEF_DOCS - "The list of .proto files for a target." - FULL_DOCS - "List of .proto files specified for a target.") + set_property( + TARGET + PROPERTY PROTO_SOURCES BRIEF_DOCS + "The list of .proto files for a target." FULL_DOCS + "List of .proto files specified for a target.") endfunction () # Generate C++ for .proto files preserving the directory hierarchy @@ -54,11 +53,7 @@ endfunction () # `foo/bar/baz.proto` then the directory containing `foo` must be in the search # path. function (google_cloud_cpp_generate_proto SRCS) - cmake_parse_arguments(_opt - "" - "" - "PROTO_PATH_DIRECTORIES" - ${ARGN}) + cmake_parse_arguments(_opt "" "" "PROTO_PATH_DIRECTORIES" ${ARGN}) if (NOT _opt_UNPARSED_ARGUMENTS) message(SEND_ERROR "Error: google_cloud_cpp_generate_proto() called" " without any proto files") @@ -71,7 +66,7 @@ function (google_cloud_cpp_generate_proto SRCS) foreach (dir ${_opt_PROTO_PATH_DIRECTORIES}) get_filename_component(absolute_path ${dir} ABSOLUTE) list(FIND protobuf_include_path "${absolute_path}" - already_in_search_path) + already_in_search_path) if (${already_in_search_path} EQUAL -1) list(APPEND protobuf_include_path "--proto_path" "${absolute_path}") endif () @@ -89,11 +84,7 @@ function (google_cloud_cpp_generate_proto SRCS) set(D "${file_directory}") if (DEFINED _opt_PROTO_PATH_DIRECTORIES) foreach (P ${_opt_PROTO_PATH_DIRECTORIES}) - string(REGEX - REPLACE "^${P}" - "" - T - "${D}") + string(REGEX REPLACE "^${P}" "" T "${D}") set(D ${T}) endforeach () endif () @@ -102,22 +93,19 @@ function (google_cloud_cpp_generate_proto SRCS) list(APPEND ${SRCS} "${pb_cc}" "${pb_h}") add_custom_command( OUTPUT "${pb_cc}" "${pb_h}" - COMMAND $ - ARGS - --cpp_out - "${CMAKE_CURRENT_BINARY_DIR}" - ${protobuf_include_path} - "${filename}" + COMMAND + $ ARGS --cpp_out + "${CMAKE_CURRENT_BINARY_DIR}" ${protobuf_include_path} + "${filename}" DEPENDS "${filename}" protobuf::protoc COMMENT "Running C++ protocol buffer compiler on ${filename}" VERBATIM) endforeach () - set_source_files_properties(${${SRCS}} - PROPERTIES - GENERATED - TRUE) - set(${SRCS} ${${SRCS}} PARENT_SCOPE) + set_source_files_properties(${${SRCS}} PROPERTIES GENERATED TRUE) + set(${SRCS} + ${${SRCS}} + PARENT_SCOPE) endfunction () # Generate gRPC C++ files from .proto files preserving the directory hierarchy. @@ -147,11 +135,7 @@ endfunction () # `foo/bar/baz.proto` then the directory containing `foo` must be in the search # path. function (google_cloud_cpp_generate_grpcpp SRCS) - cmake_parse_arguments(_opt - "" - "" - "PROTO_PATH_DIRECTORIES" - ${ARGN}) + cmake_parse_arguments(_opt "" "" "PROTO_PATH_DIRECTORIES" ${ARGN}) if (NOT _opt_UNPARSED_ARGUMENTS) message( SEND_ERROR "Error: google_cloud_cpp_generate_grpc() called without" @@ -165,7 +149,7 @@ function (google_cloud_cpp_generate_grpcpp SRCS) foreach (dir ${_opt_PROTO_PATH_DIRECTORIES}) get_filename_component(absolute_path ${dir} ABSOLUTE) list(FIND protobuf_include_path "${absolute_path}" - already_in_search_path) + already_in_search_path) if (${already_in_search_path} EQUAL -1) list(APPEND protobuf_include_path "--proto_path" "${absolute_path}") endif () @@ -183,11 +167,7 @@ function (google_cloud_cpp_generate_grpcpp SRCS) set(D "${file_directory}") if (DEFINED _opt_PROTO_PATH_DIRECTORIES) foreach (P ${_opt_PROTO_PATH_DIRECTORIES}) - string(REGEX - REPLACE "^${P}" - "" - T - "${D}") + string(REGEX REPLACE "^${P}" "" T "${D}") set(D ${T}) endforeach () endif () @@ -198,23 +178,20 @@ function (google_cloud_cpp_generate_grpcpp SRCS) add_custom_command( OUTPUT "${grpc_pb_cc}" "${grpc_pb_h}" COMMAND - $ - ARGS + $ ARGS --plugin=protoc-gen-grpc=$ "--grpc_out=${CMAKE_CURRENT_BINARY_DIR}" - "--cpp_out=${CMAKE_CURRENT_BINARY_DIR}" - ${protobuf_include_path} + "--cpp_out=${CMAKE_CURRENT_BINARY_DIR}" ${protobuf_include_path} "${filename}" DEPENDS "${filename}" protobuf::protoc gRPC::grpc_cpp_plugin COMMENT "Running gRPC C++ protocol buffer compiler on ${filename}" VERBATIM) endforeach () - set_source_files_properties(${${SRCS}} - PROPERTIES - GENERATED - TRUE) - set(${SRCS} ${${SRCS}} PARENT_SCOPE) + set_source_files_properties(${${SRCS}} PROPERTIES GENERATED TRUE) + set(${SRCS} + ${${SRCS}} + PARENT_SCOPE) endfunction () include(GNUInstallDirs) @@ -227,10 +204,7 @@ function (google_cloud_cpp_install_proto_library_headers target) if (NOT "${header}" MATCHES "\\.h$") continue() endif () - string(REPLACE "${CMAKE_CURRENT_BINARY_DIR}/" - "" - relative - "${header}") + string(REPLACE "${CMAKE_CURRENT_BINARY_DIR}/" "" relative "${header}") get_filename_component(dir "${relative}" DIRECTORY) install(FILES "${header}" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${dir}") @@ -245,10 +219,7 @@ function (google_cloud_cpp_install_proto_library_protos target strip_prefix) if (NOT "${proto}" MATCHES "\\.proto$") continue() endif () - string(REPLACE "${strip_prefix}/" - "" - relative - "${proto}") + string(REPLACE "${strip_prefix}/" "" relative "${proto}") get_filename_component(dir "${relative}" DIRECTORY) # This is modeled after the Protobuf library, it installs the basic # protos (think google/protobuf/any.proto) in the include directory for @@ -259,27 +230,22 @@ function (google_cloud_cpp_install_proto_library_protos target strip_prefix) endfunction () function (google_cloud_cpp_proto_library libname) - cmake_parse_arguments(_opt - "" - "" - "PROTO_PATH_DIRECTORIES" - ${ARGN}) + cmake_parse_arguments(_opt "" "" "PROTO_PATH_DIRECTORIES" ${ARGN}) if (NOT _opt_UNPARSED_ARGUMENTS) message(SEND_ERROR "Error: google_cloud_cpp_proto_library() called" " without any proto files") return() endif () - google_cloud_cpp_generate_proto(proto_sources - ${_opt_UNPARSED_ARGUMENTS} - PROTO_PATH_DIRECTORIES - ${_opt_PROTO_PATH_DIRECTORIES}) + google_cloud_cpp_generate_proto( + proto_sources ${_opt_UNPARSED_ARGUMENTS} PROTO_PATH_DIRECTORIES + ${_opt_PROTO_PATH_DIRECTORIES}) add_library(${libname} ${proto_sources}) - set_property(TARGET ${libname} - PROPERTY PROTO_SOURCES ${_opt_UNPARSED_ARGUMENTS}) - target_link_libraries(${libname} - PUBLIC gRPC::grpc++ gRPC::grpc protobuf::libprotobuf) + set_property(TARGET ${libname} PROPERTY PROTO_SOURCES + ${_opt_UNPARSED_ARGUMENTS}) + target_link_libraries(${libname} PUBLIC gRPC::grpc++ gRPC::grpc + protobuf::libprotobuf) target_include_directories( ${libname} PUBLIC $ @@ -288,24 +254,18 @@ function (google_cloud_cpp_proto_library libname) endfunction () function (google_cloud_cpp_grpcpp_library libname) - cmake_parse_arguments(_opt - "" - "" - "PROTO_PATH_DIRECTORIES" - ${ARGN}) + cmake_parse_arguments(_opt "" "" "PROTO_PATH_DIRECTORIES" ${ARGN}) if (NOT _opt_UNPARSED_ARGUMENTS) message(SEND_ERROR "Error: google_cloud_cpp_proto_library() called" " without any proto files") return() endif () - google_cloud_cpp_generate_grpcpp(grpcpp_sources - ${_opt_UNPARSED_ARGUMENTS} - PROTO_PATH_DIRECTORIES - ${_opt_PROTO_PATH_DIRECTORIES}) - google_cloud_cpp_proto_library(${libname} - ${_opt_UNPARSED_ARGUMENTS} - PROTO_PATH_DIRECTORIES - ${_opt_PROTO_PATH_DIRECTORIES}) + google_cloud_cpp_generate_grpcpp( + grpcpp_sources ${_opt_UNPARSED_ARGUMENTS} PROTO_PATH_DIRECTORIES + ${_opt_PROTO_PATH_DIRECTORIES}) + google_cloud_cpp_proto_library( + ${libname} ${_opt_UNPARSED_ARGUMENTS} PROTO_PATH_DIRECTORIES + ${_opt_PROTO_PATH_DIRECTORIES}) target_sources(${libname} PRIVATE ${grpcpp_sources}) endfunction () diff --git a/cmake/FindProtobufTargets.cmake b/cmake/FindProtobufTargets.cmake index 28cb36fca..ab196118d 100644 --- a/cmake/FindProtobufTargets.cmake +++ b/cmake/FindProtobufTargets.cmake @@ -107,35 +107,35 @@ else () if (NOT TARGET protobuf::libprotobuf) add_library(protobuf::libprotobuf IMPORTED INTERFACE) - set_property(TARGET protobuf::libprotobuf - PROPERTY INTERFACE_INCLUDE_DIRECTORIES - ${Protobuf_INCLUDE_DIR}) - set_property(TARGET protobuf::libprotobuf - APPEND - PROPERTY INTERFACE_LINK_LIBRARIES ${Protobuf_LIBRARY} - Threads::Threads) + set_property( + TARGET protobuf::libprotobuf + PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${Protobuf_INCLUDE_DIR}) + set_property( + TARGET protobuf::libprotobuf APPEND + PROPERTY INTERFACE_LINK_LIBRARIES ${Protobuf_LIBRARY} + Threads::Threads) endif () if (NOT TARGET protobuf::libprotobuf-lite) add_library(protobuf::libprotobuf-lite IMPORTED INTERFACE) - set_property(TARGET protobuf::libprotobuf-lite - PROPERTY INTERFACE_INCLUDE_DIRECTORIES - ${Protobuf_INCLUDE_DIR}) - set_property(TARGET protobuf::libprotobuf-lite - APPEND - PROPERTY INTERFACE_LINK_LIBRARIES - ${Protobuf_LITE_LIBRARY} Threads::Threads) + set_property( + TARGET protobuf::libprotobuf-lite + PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${Protobuf_INCLUDE_DIR}) + set_property( + TARGET protobuf::libprotobuf-lite APPEND + PROPERTY INTERFACE_LINK_LIBRARIES ${Protobuf_LITE_LIBRARY} + Threads::Threads) endif () if (NOT TARGET protobuf::libprotoc) add_library(protobuf::libprotoc IMPORTED INTERFACE) - set_property(TARGET protobuf::libprotoc - PROPERTY INTERFACE_INCLUDE_DIRECTORIES - ${Protobuf_INCLUDE_DIR}) - set_property(TARGET protobuf::libprotoc - APPEND - PROPERTY INTERFACE_LINK_LIBRARIES - ${Protobuf_PROTOC_LIBRARY} Threads::Threads) + set_property( + TARGET protobuf::libprotoc + PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${Protobuf_INCLUDE_DIR}) + set_property( + TARGET protobuf::libprotoc APPEND + PROPERTY INTERFACE_LINK_LIBRARIES ${Protobuf_PROTOC_LIBRARY} + Threads::Threads) endif () endif () endif () @@ -152,9 +152,10 @@ if (ProtobufTargets_FOUND AND NOT TARGET protobuf::protoc) add_executable(protobuf::protoc IMPORTED) # Discover the protoc compiler location. - find_program(_protobuf_PROTOC_EXECUTABLE - NAMES protoc - DOC "The Google Protocol Buffers Compiler") + find_program( + _protobuf_PROTOC_EXECUTABLE + NAMES protoc + DOC "The Google Protocol Buffers Compiler") if (protobuf_DEBUG) message( STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " @@ -165,11 +166,11 @@ if (ProtobufTargets_FOUND AND NOT TARGET protobuf::protoc) set_property(TARGET protobuf::protoc PROPERTY IMPORTED_LOCATION ${_protobuf_PROTOC_EXECUTABLE}) set_property( - TARGET protobuf::protoc - PROPERTY IMPORTED_LOCATION_DEBUG ${_protobuf_PROTOC_EXECUTABLE}) - set_property(TARGET protobuf::protoc - PROPERTY IMPORTED_LOCATION_RELEASE - ${_protobuf_PROTOC_EXECUTABLE}) + TARGET protobuf::protoc PROPERTY IMPORTED_LOCATION_DEBUG + ${_protobuf_PROTOC_EXECUTABLE}) + set_property( + TARGET protobuf::protoc PROPERTY IMPORTED_LOCATION_RELEASE + ${_protobuf_PROTOC_EXECUTABLE}) unset(_protobuf_PROTOC_EXECUTABLE) if (protobuf_DEBUG) @@ -186,10 +187,8 @@ if (protobuf_DEBUG) "ProtobufTargets_FOUND = ${ProtobufTargets_FOUND}" " ProtobufTargets_VERSION = ${ProtobufTargets_VERSION}") if (ProtobufTargets_FOUND) - foreach (_target - protobuf::libprotobuf - protobuf::libprotobuf-lite - protobuf::libprotoc) + foreach (_target protobuf::libprotobuf protobuf::libprotobuf-lite + protobuf::libprotoc) if (NOT TARGET ${_target}) message( STATUS @@ -201,7 +200,5 @@ if (protobuf_DEBUG) endif () endif () -find_package_handle_standard_args(ProtobufTargets - REQUIRED_VARS - ProtobufTargets_FOUND - ProtobufTargets_VERSION) +find_package_handle_standard_args(ProtobufTargets REQUIRED_VARS + ProtobufTargets_FOUND ProtobufTargets_VERSION) diff --git a/cmake/FindgRPC.cmake b/cmake/FindgRPC.cmake index 9db315ad4..358285b62 100644 --- a/cmake/FindgRPC.cmake +++ b/cmake/FindgRPC.cmake @@ -92,9 +92,9 @@ function (_grpc_fix_grpc_cpp_plugin_target) DOC "The gRPC C++ plugin for protoc") mark_as_advanced(_gRPC_CPP_PLUGIN_EXECUTABLE) if (_gRPC_CPP_PLUGIN_EXECUTABLE) - set_property(TARGET gRPC::grpc_cpp_plugin - PROPERTY IMPORTED_LOCATION - ${_gRPC_CPP_PLUGIN_EXECUTABLE}) + set_property( + TARGET gRPC::grpc_cpp_plugin + PROPERTY IMPORTED_LOCATION ${_gRPC_CPP_PLUGIN_EXECUTABLE}) else () set(gRPC_FOUND "grpc_cpp_plugin-NOTFOUND") endif () @@ -106,11 +106,9 @@ endfunction () function (_grpc_fix_grpc_target_definitions) # Including gRPC headers without this definition results in a build error. if (WIN32) - set_property(TARGET gRPC::grpc - APPEND + set_property(TARGET gRPC::grpc APPEND PROPERTY INTERFACE_COMPILE_DEFINITIONS _WIN32_WINNT=0x600) - set_property(TARGET gRPC::grpc++ - APPEND + set_property(TARGET gRPC::grpc++ APPEND PROPERTY INTERFACE_COMPILE_DEFINITIONS _WIN32_WINNT=0x600) endif () endfunction () @@ -155,10 +153,12 @@ function (_gRPC_find_library name filename) "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " "${name} ${filename} RELEASE=${${name}_LIBRARY}" " DEBUG=${${name}_LIBRARY_DEBUG} DEFAULT=${${name}_LIBRARY}" - ) + ) endif () - set(${name}_LIBRARY "${${name}_LIBRARY}" PARENT_SCOPE) + set(${name}_LIBRARY + "${${name}_LIBRARY}" + PARENT_SCOPE) endif () endfunction () @@ -196,85 +196,75 @@ endif () if (_gRPC_grpc_LIBRARY) if (NOT TARGET gRPC::grpc) add_library(gRPC::grpc IMPORTED UNKNOWN) - set_target_properties(gRPC::grpc - PROPERTIES INTERFACE_INCLUDE_DIRECTORIES - "${_gRPC_INCLUDE_DIR}") + set_target_properties( + gRPC::grpc PROPERTIES INTERFACE_INCLUDE_DIRECTORIES + "${_gRPC_INCLUDE_DIR}") if (EXISTS "${_gRPC_grpc_LIBRARY}") - set_target_properties(gRPC::grpc - PROPERTIES IMPORTED_LOCATION - "${_gRPC_grpc_LIBRARY}") + set_target_properties(gRPC::grpc PROPERTIES IMPORTED_LOCATION + "${_gRPC_grpc_LIBRARY}") endif () if (EXISTS "${_gRPC_grpc_LIBRARY_RELEASE}") - set_property(TARGET gRPC::grpc - APPEND + set_property(TARGET gRPC::grpc APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE) - set_target_properties(gRPC::grpc - PROPERTIES IMPORTED_LOCATION_RELEASE - "${_gRPC_grpc_LIBRARY_RELEASE}") + set_target_properties( + gRPC::grpc PROPERTIES IMPORTED_LOCATION_RELEASE + "${_gRPC_grpc_LIBRARY_RELEASE}") endif () if (EXISTS "${_gRPC_grpc_LIBRARY_DEBUG}") - set_property(TARGET gRPC::grpc - APPEND + set_property(TARGET gRPC::grpc APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG) - set_target_properties(gRPC::grpc - PROPERTIES IMPORTED_LOCATION_DEBUG - "${_gRPC_grpc_LIBRARY_DEBUG}") + set_target_properties( + gRPC::grpc PROPERTIES IMPORTED_LOCATION_DEBUG + "${_gRPC_grpc_LIBRARY_DEBUG}") endif () - set_property(TARGET gRPC::grpc - APPEND - PROPERTY INTERFACE_LINK_LIBRARIES protobuf::libprotobuf - Threads::Threads) + set_property( + TARGET gRPC::grpc APPEND + PROPERTY INTERFACE_LINK_LIBRARIES protobuf::libprotobuf + Threads::Threads) endif () endif () if (_gRPC_grpc++_LIBRARY) if (NOT TARGET gRPC::grpc++) add_library(gRPC::grpc++ IMPORTED UNKNOWN) - set_target_properties(gRPC::grpc++ - PROPERTIES INTERFACE_INCLUDE_DIRECTORIES - "${_gRPC++_INCLUDE_DIR}") + set_target_properties( + gRPC::grpc++ PROPERTIES INTERFACE_INCLUDE_DIRECTORIES + "${_gRPC++_INCLUDE_DIR}") if (EXISTS "${_gRPC_grpc++_LIBRARY}") - set_target_properties(gRPC::grpc++ - PROPERTIES IMPORTED_LOCATION - "${_gRPC_grpc++_LIBRARY}") + set_target_properties( + gRPC::grpc++ PROPERTIES IMPORTED_LOCATION + "${_gRPC_grpc++_LIBRARY}") endif () if (EXISTS "${_gRPC_grpc++_LIBRARY_RELEASE}") - set_property(TARGET gRPC::grpc++ - APPEND + set_property(TARGET gRPC::grpc++ APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE) - set_target_properties(gRPC::grpc++ - PROPERTIES IMPORTED_LOCATION_RELEASE - "${_gRPC_grpc++_LIBRARY_RELEASE}") + set_target_properties( + gRPC::grpc++ PROPERTIES IMPORTED_LOCATION_RELEASE + "${_gRPC_grpc++_LIBRARY_RELEASE}") endif () if (EXISTS "${_gRPC_grpc++_LIBRARY_DEBUG}") - set_property(TARGET gRPC::grpc++ - APPEND + set_property(TARGET gRPC::grpc++ APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG) - set_target_properties(gRPC::grpc++ - PROPERTIES IMPORTED_LOCATION_DEBUG - "${_gRPC_grpc++_LIBRARY_DEBUG}") + set_target_properties( + gRPC::grpc++ PROPERTIES IMPORTED_LOCATION_DEBUG + "${_gRPC_grpc++_LIBRARY_DEBUG}") endif () - set_property(TARGET gRPC::grpc++ - APPEND - PROPERTY INTERFACE_LINK_LIBRARIES - gRPC::grpc - protobuf::libprotobuf - Threads::Threads) + set_property( + TARGET gRPC::grpc++ APPEND + PROPERTY INTERFACE_LINK_LIBRARIES gRPC::grpc protobuf::libprotobuf + Threads::Threads) if (CMAKE_VERSION VERSION_GREATER 3.8) # gRPC++ requires C++11, but only CMake-3.8 introduced a target # compiler feature to meet that requirement. - set_property(TARGET gRPC::grpc++ - APPEND + set_property(TARGET gRPC::grpc++ APPEND PROPERTY INTERFACE_COMPILE_FEATURES cxx_std_11) elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") # CMake 3.5 is still alive and kicking in some older distros, use # the compiler-specific versions in these cases. - set_property(TARGET gRPC::grpc++ - APPEND + set_property(TARGET gRPC::grpc++ APPEND PROPERTY INTERFACE_COMPILE_OPTIONS "-std=c++11") elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") - set_property(TARGET gRPC::grpc++ - APPEND + set_property(TARGET gRPC::grpc++ APPEND PROPERTY INTERFACE_COMPILE_OPTIONS "-std=c++11") else () message( @@ -294,7 +284,9 @@ if (_gRPC_USE_STATIC_LIBS) set(CMAKE_FIND_LIBRARY_PREFIXES "${_gRPC_ORIG_FIND_LIBRARY_PREFIXES}") endif () -file(WRITE "${CMAKE_BINARY_DIR}/get_gRPC_version.cc" [====[ +file( + WRITE "${CMAKE_BINARY_DIR}/get_gRPC_version.cc" + [====[ #include #include int main() { @@ -303,30 +295,32 @@ int main() { } ]====]) -try_run(_gRPC_GET_VERSION_STATUS - _gRPC_GET_VERSION_COMPILE_STATUS - "${CMAKE_BINARY_DIR}" - "${CMAKE_BINARY_DIR}/get_gRPC_version.cc" - LINK_LIBRARIES - gRPC::grpc++ - gRPC::grpc - COMPILE_OUTPUT_VARIABLE _gRPC_GET_VERSION_COMPILE_OUTPUT - RUN_OUTPUT_VARIABLE gRPC_VERSION) +try_run( + _gRPC_GET_VERSION_STATUS + _gRPC_GET_VERSION_COMPILE_STATUS + "${CMAKE_BINARY_DIR}" + "${CMAKE_BINARY_DIR}/get_gRPC_version.cc" + LINK_LIBRARIES + gRPC::grpc++ + gRPC::grpc + COMPILE_OUTPUT_VARIABLE _gRPC_GET_VERSION_COMPILE_OUTPUT + RUN_OUTPUT_VARIABLE gRPC_VERSION) file(REMOVE "${CMAKE_BINARY_DIR}/get_gRPC_version.cc") _grpc_fix_grpc_cpp_plugin_target() if (gRPC_DEBUG) - foreach (_var - _gRPC_CPP_PLUGIN_EXECUTABLE - _gRPC_VERSION_RAW - _gRPC_GET_VERSION_STATUS - _gRPC_GET_VERSION_COMPILE_STATUS - _gRPC_GET_VERSION_COMPILE_OUTPUT - _gRPC_grpc_LIBRARY - _gRPC_grpc++_LIBRARY - _gRPC_INCLUDE_DIR) + foreach ( + _var + _gRPC_CPP_PLUGIN_EXECUTABLE + _gRPC_VERSION_RAW + _gRPC_GET_VERSION_STATUS + _gRPC_GET_VERSION_COMPILE_STATUS + _gRPC_GET_VERSION_COMPILE_OUTPUT + _gRPC_grpc_LIBRARY + _gRPC_grpc++_LIBRARY + _gRPC_INCLUDE_DIR) message( STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " "${_var} = ${${_var}}") @@ -335,9 +329,5 @@ if (gRPC_DEBUG) endif () include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(gRPC - REQUIRED_VARS - _gRPC_grpc_LIBRARY - _gRPC_INCLUDE_DIR - VERSION_VAR - gRPC_VERSION) +find_package_handle_standard_args(gRPC REQUIRED_VARS _gRPC_grpc_LIBRARY + _gRPC_INCLUDE_DIR VERSION_VAR gRPC_VERSION) diff --git a/cmake/SelectMSVCRuntime.cmake b/cmake/SelectMSVCRuntime.cmake index eb7f8f9e9..feb2fe46c 100644 --- a/cmake/SelectMSVCRuntime.cmake +++ b/cmake/SelectMSVCRuntime.cmake @@ -29,17 +29,10 @@ # if (MSVC AND VCPKG_TARGET_TRIPLET MATCHES "-static$") foreach (flag_var - CMAKE_CXX_FLAGS - CMAKE_CXX_FLAGS_DEBUG - CMAKE_CXX_FLAGS_RELEASE - CMAKE_CXX_FLAGS_MINSIZEREL - CMAKE_CXX_FLAGS_RELWITHDEBINFO) + CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE + CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO) if (${flag_var} MATCHES "/MD") - string(REGEX - REPLACE "/MD" - "/MT" - ${flag_var} - "${${flag_var}}") + string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}") endif () endforeach (flag_var) unset(flag_var) From c873fd3aa14fb0d8696588117b5f79693381ba3c Mon Sep 17 00:00:00 2001 From: Carlos O'Ryan Date: Tue, 25 Feb 2020 14:35:22 -0500 Subject: [PATCH 34/34] feat: add storage protos (#39) --- CMakeLists.txt | 24 +++++++++++++++++++++++- cmake/config.cmake.in | 1 + 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7ead2b05c..f755def48 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -96,7 +96,9 @@ set(GOOGLEAPIS_CPP_PROTO_FILES "google/spanner/v1/result_set.proto" "google/spanner/v1/spanner.proto" "google/spanner/v1/transaction.proto" - "google/spanner/v1/type.proto") + "google/spanner/v1/type.proto" + "google/storage/v1/storage.proto" + "google/storage/v1/storage_resources.proto") set(GOOGLEAPIS_CPP_BYPRODUCTS) foreach (proto ${GOOGLEAPIS_CPP_PROTO_FILES}) @@ -325,6 +327,23 @@ target_link_libraries( googleapis-c++::rpc_status_protos PRIVATE googleapis_cpp_common_flags) +google_cloud_cpp_grpcpp_library( + googleapis_cpp_storage_protos + "${GOOGLEAPIS_CPP_SOURCE}/google/storage/v1/storage.proto" + "${GOOGLEAPIS_CPP_SOURCE}/google/storage/v1/storage_resources.proto" + PROTO_PATH_DIRECTORIES + "${GOOGLEAPIS_CPP_SOURCE}" + "${PROTO_INCLUDE_DIR}") +googleapis_cpp_set_version_and_alias(storage_protos) +target_link_libraries( + googleapis_cpp_storage_protos + PUBLIC googleapis-c++::api_annotations_protos + googleapis-c++::api_client_protos + googleapis-c++::api_field_behavior_protos + googleapis-c++::iam_v1_iam_policy_protos + googleapis-c++::iam_v1_policy_protos + PRIVATE googleapis_cpp_common_flags) + # Install the libraries and headers in the locations determined by # GNUInstallDirs include(GNUInstallDirs) @@ -334,6 +353,7 @@ set(googleapis_cpp_installed_libraries_list googleapis_cpp_cloud_bigquery_protos googleapis_cpp_pubsub_protos googleapis_cpp_spanner_protos + googleapis_cpp_storage_protos googleapis_cpp_longrunning_operations_protos googleapis_cpp_api_http_protos googleapis_cpp_api_annotations_protos @@ -425,6 +445,8 @@ string( CONCAT GOOGLE_CLOUD_CPP_PC_REQUIRES "googleapis_cpp_bigtable_protos" " googleapis_cpp_cloud_bigquery_protos" + " googleapis_pubsub_protos" + " googleapis_cpp_storage_protos" " googleapis_cpp_iam_v1_iam_policy_protos" " googleapis_cpp_iam_v1_options_protos" " googleapis_cpp_iam_v1_policy_protos" diff --git a/cmake/config.cmake.in b/cmake/config.cmake.in index e7b77c33c..02169ef85 100644 --- a/cmake/config.cmake.in +++ b/cmake/config.cmake.in @@ -38,6 +38,7 @@ foreach (_target rpc_error_details rpc_status spanner + storage type_expr) set(scoped_name "googleapis-c++::${_target}_protos") set(imported_name "googleapis_cpp_${_target}_protos")