|
| 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 Profiler API C++ Client") |
| 19 | +set(DOXYGEN_PROJECT_BRIEF "A C++ Client Library for the Cloud Profiler API") |
| 20 | +set(DOXYGEN_PROJECT_NUMBER "${PROJECT_VERSION} (Experimental)") |
| 21 | +set(DOXYGEN_EXCLUDE_SYMBOLS "internal" "profiler_internal" "profiler_testing" |
| 22 | + "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::profiler_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_grpcpp_library( |
| 39 | + google_cloud_cpp_profiler_protos |
| 40 | + # cmake-format: sort |
| 41 | + ${EXTERNAL_GOOGLEAPIS_SOURCE}/google/devtools/cloudprofiler/v2/profiler.proto |
| 42 | + PROTO_PATH_DIRECTORIES |
| 43 | + "${EXTERNAL_GOOGLEAPIS_SOURCE}" |
| 44 | + "${PROTO_INCLUDE_DIR}") |
| 45 | +external_googleapis_set_version_and_alias(profiler_protos) |
| 46 | +target_link_libraries( |
| 47 | + google_cloud_cpp_profiler_protos |
| 48 | + PUBLIC # |
| 49 | + google-cloud-cpp::api_annotations_protos |
| 50 | + google-cloud-cpp::api_client_protos |
| 51 | + google-cloud-cpp::api_http_protos) |
| 52 | + |
| 53 | +file( |
| 54 | + GLOB source_files |
| 55 | + RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" |
| 56 | + "*.h" "*.cc" "internal/*.h" "internal/*.cc") |
| 57 | +list(SORT source_files) |
| 58 | +add_library(google_cloud_cpp_profiler ${source_files}) |
| 59 | +target_include_directories( |
| 60 | + google_cloud_cpp_profiler |
| 61 | + PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}> |
| 62 | + $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}> |
| 63 | + $<INSTALL_INTERFACE:include>) |
| 64 | +target_link_libraries( |
| 65 | + google_cloud_cpp_profiler |
| 66 | + PUBLIC google-cloud-cpp::grpc_utils google-cloud-cpp::common |
| 67 | + google-cloud-cpp::profiler_protos) |
| 68 | +google_cloud_cpp_add_common_options(google_cloud_cpp_profiler) |
| 69 | +set_target_properties( |
| 70 | + google_cloud_cpp_profiler |
| 71 | + PROPERTIES EXPORT_NAME google-cloud-cpp::experimental-profiler |
| 72 | + VERSION "${PROJECT_VERSION}" SOVERSION |
| 73 | + "${PROJECT_VERSION_MAJOR}") |
| 74 | +target_compile_options(google_cloud_cpp_profiler |
| 75 | + PUBLIC ${GOOGLE_CLOUD_CPP_EXCEPTIONS_FLAG}) |
| 76 | + |
| 77 | +add_library(google-cloud-cpp::experimental-profiler ALIAS |
| 78 | + google_cloud_cpp_profiler) |
| 79 | + |
| 80 | +# Create a header-only library for the mocks. We use a CMake `INTERFACE` library |
| 81 | +# for these, a regular library would not work on macOS (where the library needs |
| 82 | +# at least one .o file). Unfortunately INTERFACE libraries are a bit weird in |
| 83 | +# that they need absolute paths for their sources. |
| 84 | +file( |
| 85 | + GLOB relative_mock_files |
| 86 | + RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" |
| 87 | + "mocks/*.h") |
| 88 | +list(SORT relative_mock_files) |
| 89 | +set(mock_files) |
| 90 | +foreach (file IN LISTS relative_mock_files) |
| 91 | + list(APPEND mock_files "${CMAKE_CURRENT_SOURCE_DIR}/${file}") |
| 92 | +endforeach () |
| 93 | +add_library(google_cloud_cpp_profiler_mocks INTERFACE) |
| 94 | +target_sources(google_cloud_cpp_profiler_mocks INTERFACE ${mock_files}) |
| 95 | +target_link_libraries( |
| 96 | + google_cloud_cpp_profiler_mocks |
| 97 | + INTERFACE google-cloud-cpp::experimental-profiler GTest::gmock_main |
| 98 | + GTest::gmock GTest::gtest) |
| 99 | +set_target_properties( |
| 100 | + google_cloud_cpp_profiler_mocks |
| 101 | + PROPERTIES EXPORT_NAME google-cloud-cpp::experimental-profiler_mocks) |
| 102 | +target_include_directories( |
| 103 | + google_cloud_cpp_profiler_mocks |
| 104 | + INTERFACE $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}> |
| 105 | + $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}> |
| 106 | + $<INSTALL_INTERFACE:include>) |
| 107 | +target_compile_options(google_cloud_cpp_profiler_mocks |
| 108 | + INTERFACE ${GOOGLE_CLOUD_CPP_EXCEPTIONS_FLAG}) |
| 109 | + |
| 110 | +include(CTest) |
| 111 | +if (BUILD_TESTING) |
| 112 | + add_executable(profiler_quickstart "quickstart/quickstart.cc") |
| 113 | + target_link_libraries(profiler_quickstart |
| 114 | + PRIVATE google-cloud-cpp::experimental-profiler) |
| 115 | + google_cloud_cpp_add_common_options(profiler_quickstart) |
| 116 | + add_test( |
| 117 | + NAME profiler_quickstart |
| 118 | + COMMAND cmake -P "${PROJECT_SOURCE_DIR}/cmake/quickstart-runner.cmake" |
| 119 | + $<TARGET_FILE:profiler_quickstart> GOOGLE_CLOUD_PROJECT) |
| 120 | + set_tests_properties(profiler_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_profiler-targets |
| 130 | + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/google_cloud_cpp_profiler" |
| 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_profiler google_cloud_cpp_profiler_protos |
| 137 | + EXPORT google_cloud_cpp_profiler-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_profiler google_cloud_cpp_profiler_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("google_cloud_cpp_profiler_protos" |
| 156 | + "${EXTERNAL_GOOGLEAPIS_SOURCE}") |
| 157 | +google_cloud_cpp_install_proto_library_headers( |
| 158 | + "google_cloud_cpp_profiler_protos") |
| 159 | +google_cloud_cpp_install_headers("google_cloud_cpp_profiler" |
| 160 | + "include/google/cloud/profiler") |
| 161 | +google_cloud_cpp_install_headers("google_cloud_cpp_profiler_mocks" |
| 162 | + "include/google/cloud/profiler") |
| 163 | + |
| 164 | +# Setup global variables used in the following *.in files. |
| 165 | +set(GOOGLE_CLOUD_CONFIG_VERSION_MAJOR ${PROJECT_VERSION_MAJOR}) |
| 166 | +set(GOOGLE_CLOUD_CONFIG_VERSION_MINOR ${PROJECT_VERSION_MINOR}) |
| 167 | +set(GOOGLE_CLOUD_CONFIG_VERSION_PATCH ${PROJECT_VERSION_PATCH}) |
| 168 | +set(GOOGLE_CLOUD_PC_NAME "The Cloud Profiler API C++ Client Library") |
| 169 | +set(GOOGLE_CLOUD_PC_DESCRIPTION |
| 170 | + "Provides C++ APIs to use the Cloud Profiler API.") |
| 171 | +set(GOOGLE_CLOUD_PC_LIBS "-lgoogle_cloud_cpp_profiler") |
| 172 | +string(CONCAT GOOGLE_CLOUD_PC_REQUIRES "google_cloud_cpp_grpc_utils" |
| 173 | + " google_cloud_cpp_common" " google_cloud_cpp_profiler_protos") |
| 174 | + |
| 175 | +# Create and install the pkg-config files. |
| 176 | +configure_file("${PROJECT_SOURCE_DIR}/google/cloud/profiler/config.pc.in" |
| 177 | + "google_cloud_cpp_profiler.pc" @ONLY) |
| 178 | +install( |
| 179 | + FILES "${CMAKE_CURRENT_BINARY_DIR}/google_cloud_cpp_profiler.pc" |
| 180 | + DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig" |
| 181 | + COMPONENT google_cloud_cpp_development) |
| 182 | + |
| 183 | +# Create and install the CMake configuration files. |
| 184 | +include(CMakePackageConfigHelpers) |
| 185 | +configure_file("config.cmake.in" "google_cloud_cpp_profiler-config.cmake" @ONLY) |
| 186 | +write_basic_package_version_file( |
| 187 | + "google_cloud_cpp_profiler-config-version.cmake" |
| 188 | + VERSION ${PROJECT_VERSION} |
| 189 | + COMPATIBILITY ExactVersion) |
| 190 | + |
| 191 | +install( |
| 192 | + FILES |
| 193 | + "${CMAKE_CURRENT_BINARY_DIR}/google_cloud_cpp_profiler-config.cmake" |
| 194 | + "${CMAKE_CURRENT_BINARY_DIR}/google_cloud_cpp_profiler-config-version.cmake" |
| 195 | + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/google_cloud_cpp_profiler" |
| 196 | + COMPONENT google_cloud_cpp_development) |
| 197 | + |
| 198 | +external_googleapis_install_pc("google_cloud_cpp_profiler_protos" |
| 199 | + "${PROJECT_SOURCE_DIR}/external/googleapis") |
0 commit comments