|
| 1 | +# ~~~ |
| 2 | +# Copyright 2022 Google LLC |
| 3 | +# |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +# you may not use this file except in compliance with the License. |
| 6 | +# You may obtain a copy of the License at |
| 7 | +# |
| 8 | +# https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# |
| 10 | +# Unless required by applicable law or agreed to in writing, software |
| 11 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +# See the License for the specific language governing permissions and |
| 14 | +# limitations under the License. |
| 15 | +# ~~~ |
| 16 | + |
| 17 | +include(GoogleapisConfig) |
| 18 | +set(DOXYGEN_PROJECT_NAME "Cloud Optimization API C++ Client") |
| 19 | +set(DOXYGEN_PROJECT_BRIEF "A C++ Client Library for the Cloud Optimization API") |
| 20 | +set(DOXYGEN_PROJECT_NUMBER "${PROJECT_VERSION} (Experimental)") |
| 21 | +set(DOXYGEN_EXCLUDE_SYMBOLS "internal" "optimization_internal" |
| 22 | + "optimization_testing" "examples") |
| 23 | +set(DOXYGEN_EXAMPLE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/quickstart) |
| 24 | + |
| 25 | +# Creates the proto headers needed by doxygen. |
| 26 | +set(GOOGLE_CLOUD_CPP_DOXYGEN_DEPS google-cloud-cpp::optimization_protos) |
| 27 | + |
| 28 | +include(GoogleCloudCppCommon) |
| 29 | + |
| 30 | +set(EXTERNAL_GOOGLEAPIS_SOURCE |
| 31 | + "${PROJECT_BINARY_DIR}/external/googleapis/src/googleapis_download") |
| 32 | +find_path(PROTO_INCLUDE_DIR google/protobuf/descriptor.proto) |
| 33 | +if (PROTO_INCLUDE_DIR) |
| 34 | + list(INSERT PROTOBUF_IMPORT_DIRS 0 "${PROTO_INCLUDE_DIR}") |
| 35 | +endif () |
| 36 | + |
| 37 | +include(CompileProtos) |
| 38 | +google_cloud_cpp_load_protolist( |
| 39 | + proto_list |
| 40 | + "${PROJECT_SOURCE_DIR}/external/googleapis/protolists/optimization.list") |
| 41 | +google_cloud_cpp_load_protodeps( |
| 42 | + proto_deps |
| 43 | + "${PROJECT_SOURCE_DIR}/external/googleapis/protodeps/optimization.deps") |
| 44 | +google_cloud_cpp_grpcpp_library( |
| 45 | + google_cloud_cpp_optimization_protos # cmake-format: sort |
| 46 | + ${proto_list} PROTO_PATH_DIRECTORIES "${EXTERNAL_GOOGLEAPIS_SOURCE}" |
| 47 | + "${PROTO_INCLUDE_DIR}") |
| 48 | +external_googleapis_set_version_and_alias(optimization_protos) |
| 49 | +target_link_libraries(google_cloud_cpp_optimization_protos PUBLIC ${proto_deps}) |
| 50 | + |
| 51 | +file( |
| 52 | + GLOB source_files |
| 53 | + RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" |
| 54 | + "*.h" "*.cc" "internal/*.h" "internal/*.cc") |
| 55 | +list(SORT source_files) |
| 56 | +add_library(google_cloud_cpp_optimization ${source_files}) |
| 57 | +target_include_directories( |
| 58 | + google_cloud_cpp_optimization |
| 59 | + PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}> |
| 60 | + $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}> |
| 61 | + $<INSTALL_INTERFACE:include>) |
| 62 | +target_link_libraries( |
| 63 | + google_cloud_cpp_optimization |
| 64 | + PUBLIC google-cloud-cpp::grpc_utils google-cloud-cpp::common |
| 65 | + google-cloud-cpp::optimization_protos) |
| 66 | +google_cloud_cpp_add_common_options(google_cloud_cpp_optimization) |
| 67 | +set_target_properties( |
| 68 | + google_cloud_cpp_optimization |
| 69 | + PROPERTIES EXPORT_NAME google-cloud-cpp::experimental-optimization |
| 70 | + VERSION "${PROJECT_VERSION}" |
| 71 | + SOVERSION "${PROJECT_VERSION_MAJOR}") |
| 72 | +target_compile_options(google_cloud_cpp_optimization |
| 73 | + PUBLIC ${GOOGLE_CLOUD_CPP_EXCEPTIONS_FLAG}) |
| 74 | + |
| 75 | +add_library(google-cloud-cpp::experimental-optimization ALIAS |
| 76 | + google_cloud_cpp_optimization) |
| 77 | + |
| 78 | +# Create a header-only library for the mocks. We use a CMake `INTERFACE` library |
| 79 | +# for these, a regular library would not work on macOS (where the library needs |
| 80 | +# at least one .o file). Unfortunately INTERFACE libraries are a bit weird in |
| 81 | +# that they need absolute paths for their sources. |
| 82 | +file( |
| 83 | + GLOB relative_mock_files |
| 84 | + RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" |
| 85 | + "mocks/*.h") |
| 86 | +list(SORT relative_mock_files) |
| 87 | +set(mock_files) |
| 88 | +foreach (file IN LISTS relative_mock_files) |
| 89 | + list(APPEND mock_files "${CMAKE_CURRENT_SOURCE_DIR}/${file}") |
| 90 | +endforeach () |
| 91 | +add_library(google_cloud_cpp_optimization_mocks INTERFACE) |
| 92 | +target_sources(google_cloud_cpp_optimization_mocks INTERFACE ${mock_files}) |
| 93 | +target_link_libraries( |
| 94 | + google_cloud_cpp_optimization_mocks |
| 95 | + INTERFACE google-cloud-cpp::experimental-optimization GTest::gmock_main |
| 96 | + GTest::gmock GTest::gtest) |
| 97 | +set_target_properties( |
| 98 | + google_cloud_cpp_optimization_mocks |
| 99 | + PROPERTIES EXPORT_NAME google-cloud-cpp::experimental-optimization_mocks) |
| 100 | +target_include_directories( |
| 101 | + google_cloud_cpp_optimization_mocks |
| 102 | + INTERFACE $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}> |
| 103 | + $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}> |
| 104 | + $<INSTALL_INTERFACE:include>) |
| 105 | +target_compile_options(google_cloud_cpp_optimization_mocks |
| 106 | + INTERFACE ${GOOGLE_CLOUD_CPP_EXCEPTIONS_FLAG}) |
| 107 | + |
| 108 | +include(CTest) |
| 109 | +if (BUILD_TESTING) |
| 110 | + add_executable(optimization_quickstart "quickstart/quickstart.cc") |
| 111 | + target_link_libraries(optimization_quickstart |
| 112 | + PRIVATE google-cloud-cpp::experimental-optimization) |
| 113 | + google_cloud_cpp_add_common_options(optimization_quickstart) |
| 114 | + add_test( |
| 115 | + NAME optimization_quickstart |
| 116 | + COMMAND |
| 117 | + cmake -P "${PROJECT_SOURCE_DIR}/cmake/quickstart-runner.cmake" |
| 118 | + $<TARGET_FILE:optimization_quickstart> GOOGLE_CLOUD_PROJECT |
| 119 | + GOOGLE_CLOUD_CPP_STORAGE_TEST_BUCKET_NAME) |
| 120 | + set_tests_properties(optimization_quickstart |
| 121 | + PROPERTIES LABELS "integration-test;quickstart") |
| 122 | +endif () |
| 123 | + |
| 124 | +# Get the destination directories based on the GNU recommendations. |
| 125 | +include(GNUInstallDirs) |
| 126 | + |
| 127 | +# Export the CMake targets to make it easy to create configuration files. |
| 128 | +install( |
| 129 | + EXPORT google_cloud_cpp_optimization-targets |
| 130 | + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/google_cloud_cpp_optimization" |
| 131 | + COMPONENT google_cloud_cpp_development) |
| 132 | + |
| 133 | +# Install the libraries and headers in the locations determined by |
| 134 | +# GNUInstallDirs |
| 135 | +install( |
| 136 | + TARGETS google_cloud_cpp_optimization google_cloud_cpp_optimization_protos |
| 137 | + EXPORT google_cloud_cpp_optimization-targets |
| 138 | + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} |
| 139 | + COMPONENT google_cloud_cpp_runtime |
| 140 | + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 141 | + COMPONENT google_cloud_cpp_runtime |
| 142 | + NAMELINK_SKIP |
| 143 | + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 144 | + COMPONENT google_cloud_cpp_development) |
| 145 | +# With CMake-3.12 and higher we could avoid this separate command (and the |
| 146 | +# duplication). |
| 147 | +install( |
| 148 | + TARGETS google_cloud_cpp_optimization google_cloud_cpp_optimization_protos |
| 149 | + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 150 | + COMPONENT google_cloud_cpp_development |
| 151 | + NAMELINK_ONLY |
| 152 | + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 153 | + COMPONENT google_cloud_cpp_development) |
| 154 | + |
| 155 | +google_cloud_cpp_install_proto_library_protos( |
| 156 | + "google_cloud_cpp_optimization_protos" "${EXTERNAL_GOOGLEAPIS_SOURCE}") |
| 157 | +google_cloud_cpp_install_proto_library_headers( |
| 158 | + "google_cloud_cpp_optimization_protos") |
| 159 | +google_cloud_cpp_install_headers("google_cloud_cpp_optimization" |
| 160 | + "include/google/cloud/optimization") |
| 161 | +google_cloud_cpp_install_headers("google_cloud_cpp_optimization_mocks" |
| 162 | + "include/google/cloud/optimization") |
| 163 | + |
| 164 | +google_cloud_cpp_add_pkgconfig( |
| 165 | + optimization |
| 166 | + "The Cloud Optimization API C++ Client Library" |
| 167 | + "Provides C++ APIs to use the Cloud Optimization API." |
| 168 | + "google_cloud_cpp_grpc_utils" |
| 169 | + " google_cloud_cpp_common" |
| 170 | + " google_cloud_cpp_optimization_protos") |
| 171 | + |
| 172 | +# Create and install the CMake configuration files. |
| 173 | +include(CMakePackageConfigHelpers) |
| 174 | +configure_file("config.cmake.in" "google_cloud_cpp_optimization-config.cmake" |
| 175 | + @ONLY) |
| 176 | +write_basic_package_version_file( |
| 177 | + "google_cloud_cpp_optimization-config-version.cmake" |
| 178 | + VERSION ${PROJECT_VERSION} |
| 179 | + COMPATIBILITY ExactVersion) |
| 180 | + |
| 181 | +install( |
| 182 | + FILES |
| 183 | + "${CMAKE_CURRENT_BINARY_DIR}/google_cloud_cpp_optimization-config.cmake" |
| 184 | + "${CMAKE_CURRENT_BINARY_DIR}/google_cloud_cpp_optimization-config-version.cmake" |
| 185 | + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/google_cloud_cpp_optimization" |
| 186 | + COMPONENT google_cloud_cpp_development) |
| 187 | + |
| 188 | +external_googleapis_install_pc("google_cloud_cpp_optimization_protos" |
| 189 | + "${PROJECT_SOURCE_DIR}/external/googleapis") |
0 commit comments