|
| 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 Natural Language API C++ Client") |
| 19 | +set(DOXYGEN_PROJECT_BRIEF |
| 20 | + "A C++ Client Library for the Cloud Natural Language API") |
| 21 | +set(DOXYGEN_PROJECT_NUMBER "${PROJECT_VERSION} (Experimental)") |
| 22 | +set(DOXYGEN_EXCLUDE_SYMBOLS "internal" "language_internal" "language_testing" |
| 23 | + "examples") |
| 24 | +set(DOXYGEN_EXAMPLE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/quickstart) |
| 25 | + |
| 26 | +# Creates the proto headers needed by doxygen. |
| 27 | +set(GOOGLE_CLOUD_CPP_DOXYGEN_DEPS google-cloud-cpp::language_protos) |
| 28 | + |
| 29 | +find_package(gRPC REQUIRED) |
| 30 | +find_package(ProtobufWithTargets REQUIRED) |
| 31 | +find_package(absl CONFIG REQUIRED) |
| 32 | + |
| 33 | +include(GoogleCloudCppCommon) |
| 34 | + |
| 35 | +set(EXTERNAL_GOOGLEAPIS_SOURCE |
| 36 | + "${PROJECT_BINARY_DIR}/external/googleapis/src/googleapis_download") |
| 37 | +find_path(PROTO_INCLUDE_DIR google/protobuf/descriptor.proto) |
| 38 | +if (PROTO_INCLUDE_DIR) |
| 39 | + list(INSERT PROTOBUF_IMPORT_DIRS 0 "${PROTO_INCLUDE_DIR}") |
| 40 | +endif () |
| 41 | + |
| 42 | +include(CompileProtos) |
| 43 | +google_cloud_cpp_grpcpp_library( |
| 44 | + google_cloud_cpp_language_protos |
| 45 | + # cmake-format: sort |
| 46 | + ${EXTERNAL_GOOGLEAPIS_SOURCE}/google/cloud/language/v1/language_service.proto |
| 47 | + PROTO_PATH_DIRECTORIES |
| 48 | + "${EXTERNAL_GOOGLEAPIS_SOURCE}" |
| 49 | + "${PROTO_INCLUDE_DIR}") |
| 50 | +external_googleapis_set_version_and_alias(language_protos) |
| 51 | +target_link_libraries( |
| 52 | + google_cloud_cpp_language_protos |
| 53 | + PUBLIC # |
| 54 | + google-cloud-cpp::api_annotations_protos |
| 55 | + google-cloud-cpp::api_client_protos |
| 56 | + google-cloud-cpp::api_field_behavior_protos |
| 57 | + google-cloud-cpp::api_http_protos) |
| 58 | + |
| 59 | +file( |
| 60 | + GLOB source_files |
| 61 | + RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" |
| 62 | + "*.h" "*.cc" "internal/*.h" "internal/*.cc") |
| 63 | +list(SORT source_files) |
| 64 | +add_library(google_cloud_cpp_language ${source_files}) |
| 65 | +target_include_directories( |
| 66 | + google_cloud_cpp_language |
| 67 | + PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}> |
| 68 | + $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}> |
| 69 | + $<INSTALL_INTERFACE:include>) |
| 70 | +target_link_libraries( |
| 71 | + google_cloud_cpp_language |
| 72 | + PUBLIC google-cloud-cpp::grpc_utils google-cloud-cpp::common |
| 73 | + google-cloud-cpp::language_protos) |
| 74 | +google_cloud_cpp_add_common_options(google_cloud_cpp_language) |
| 75 | +set_target_properties( |
| 76 | + google_cloud_cpp_language |
| 77 | + PROPERTIES EXPORT_NAME google-cloud-cpp::experimental-language |
| 78 | + VERSION "${PROJECT_VERSION}" SOVERSION |
| 79 | + "${PROJECT_VERSION_MAJOR}") |
| 80 | +target_compile_options(google_cloud_cpp_language |
| 81 | + PUBLIC ${GOOGLE_CLOUD_CPP_EXCEPTIONS_FLAG}) |
| 82 | + |
| 83 | +add_library(google-cloud-cpp::experimental-language ALIAS |
| 84 | + google_cloud_cpp_language) |
| 85 | + |
| 86 | +# Create a header-only library for the mocks. We use a CMake `INTERFACE` library |
| 87 | +# for these, a regular library would not work on macOS (where the library needs |
| 88 | +# at least one .o file). Unfortunately INTERFACE libraries are a bit weird in |
| 89 | +# that they need absolute paths for their sources. |
| 90 | +file( |
| 91 | + GLOB relative_mock_files |
| 92 | + RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" |
| 93 | + "mocks/*.h") |
| 94 | +list(SORT relative_mock_files) |
| 95 | +set(mock_files) |
| 96 | +foreach (file IN LISTS relative_mock_files) |
| 97 | + list(APPEND mock_files "${CMAKE_CURRENT_SOURCE_DIR}/${file}") |
| 98 | +endforeach () |
| 99 | +add_library(google_cloud_cpp_language_mocks INTERFACE) |
| 100 | +target_sources(google_cloud_cpp_language_mocks INTERFACE ${mock_files}) |
| 101 | +target_link_libraries( |
| 102 | + google_cloud_cpp_language_mocks |
| 103 | + INTERFACE google-cloud-cpp::experimental-language GTest::gmock_main |
| 104 | + GTest::gmock GTest::gtest) |
| 105 | +set_target_properties( |
| 106 | + google_cloud_cpp_language_mocks |
| 107 | + PROPERTIES EXPORT_NAME google-cloud-cpp::experimental-language_mocks) |
| 108 | +target_include_directories( |
| 109 | + google_cloud_cpp_language_mocks |
| 110 | + INTERFACE $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}> |
| 111 | + $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}> |
| 112 | + $<INSTALL_INTERFACE:include>) |
| 113 | +target_compile_options(google_cloud_cpp_language_mocks |
| 114 | + INTERFACE ${GOOGLE_CLOUD_CPP_EXCEPTIONS_FLAG}) |
| 115 | + |
| 116 | +# Get the destination directories based on the GNU recommendations. |
| 117 | +include(GNUInstallDirs) |
| 118 | + |
| 119 | +# Export the CMake targets to make it easy to create configuration files. |
| 120 | +install( |
| 121 | + EXPORT google_cloud_cpp_language-targets |
| 122 | + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/google_cloud_cpp_language" |
| 123 | + COMPONENT google_cloud_cpp_development) |
| 124 | + |
| 125 | +# Install the libraries and headers in the locations determined by |
| 126 | +# GNUInstallDirs |
| 127 | +install( |
| 128 | + TARGETS google_cloud_cpp_language google_cloud_cpp_language_protos |
| 129 | + EXPORT google_cloud_cpp_language-targets |
| 130 | + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} |
| 131 | + COMPONENT google_cloud_cpp_runtime |
| 132 | + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 133 | + COMPONENT google_cloud_cpp_runtime |
| 134 | + NAMELINK_SKIP |
| 135 | + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 136 | + COMPONENT google_cloud_cpp_development) |
| 137 | +# With CMake-3.12 and higher we could avoid this separate command (and the |
| 138 | +# duplication). |
| 139 | +install( |
| 140 | + TARGETS google_cloud_cpp_language google_cloud_cpp_language_protos |
| 141 | + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 142 | + COMPONENT google_cloud_cpp_development |
| 143 | + NAMELINK_ONLY |
| 144 | + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 145 | + COMPONENT google_cloud_cpp_development) |
| 146 | + |
| 147 | +google_cloud_cpp_install_proto_library_protos("google_cloud_cpp_language_protos" |
| 148 | + "${EXTERNAL_GOOGLEAPIS_SOURCE}") |
| 149 | +google_cloud_cpp_install_proto_library_headers( |
| 150 | + "google_cloud_cpp_language_protos") |
| 151 | +google_cloud_cpp_install_headers("google_cloud_cpp_language" |
| 152 | + "include/google/cloud/language") |
| 153 | +google_cloud_cpp_install_headers("google_cloud_cpp_language_mocks" |
| 154 | + "include/google/cloud/language") |
| 155 | + |
| 156 | +# Setup global variables used in the following *.in files. |
| 157 | +set(GOOGLE_CLOUD_CONFIG_VERSION_MAJOR ${PROJECT_VERSION_MAJOR}) |
| 158 | +set(GOOGLE_CLOUD_CONFIG_VERSION_MINOR ${PROJECT_VERSION_MINOR}) |
| 159 | +set(GOOGLE_CLOUD_CONFIG_VERSION_PATCH ${PROJECT_VERSION_PATCH}) |
| 160 | +set(GOOGLE_CLOUD_PC_NAME "The Cloud Natural Language API C++ Client Library") |
| 161 | +set(GOOGLE_CLOUD_PC_DESCRIPTION |
| 162 | + "Provides C++ APIs to use the Cloud Natural Language API.") |
| 163 | +set(GOOGLE_CLOUD_PC_LIBS "-lgoogle_cloud_cpp_language") |
| 164 | +string(CONCAT GOOGLE_CLOUD_PC_REQUIRES "google_cloud_cpp_grpc_utils" |
| 165 | + " google_cloud_cpp_common" " google_cloud_cpp_language_protos") |
| 166 | + |
| 167 | +# Create and install the pkg-config files. |
| 168 | +configure_file("${PROJECT_SOURCE_DIR}/google/cloud/language/config.pc.in" |
| 169 | + "google_cloud_cpp_language.pc" @ONLY) |
| 170 | +install( |
| 171 | + FILES "${CMAKE_CURRENT_BINARY_DIR}/google_cloud_cpp_language.pc" |
| 172 | + DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig" |
| 173 | + COMPONENT google_cloud_cpp_development) |
| 174 | + |
| 175 | +# Create and install the CMake configuration files. |
| 176 | +include(CMakePackageConfigHelpers) |
| 177 | +configure_file("config.cmake.in" "google_cloud_cpp_language-config.cmake" @ONLY) |
| 178 | +write_basic_package_version_file( |
| 179 | + "google_cloud_cpp_language-config-version.cmake" |
| 180 | + VERSION ${PROJECT_VERSION} |
| 181 | + COMPATIBILITY ExactVersion) |
| 182 | + |
| 183 | +install( |
| 184 | + FILES |
| 185 | + "${CMAKE_CURRENT_BINARY_DIR}/google_cloud_cpp_language-config.cmake" |
| 186 | + "${CMAKE_CURRENT_BINARY_DIR}/google_cloud_cpp_language-config-version.cmake" |
| 187 | + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/google_cloud_cpp_language" |
| 188 | + COMPONENT google_cloud_cpp_development) |
| 189 | + |
| 190 | +external_googleapis_install_pc("google_cloud_cpp_language_protos" |
| 191 | + "${PROJECT_SOURCE_DIR}/external/googleapis") |
0 commit comments