|
| 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 Document AI API C++ Client") |
| 19 | +set(DOXYGEN_PROJECT_BRIEF "A C++ Client Library for the Cloud Document AI API") |
| 20 | +set(DOXYGEN_PROJECT_NUMBER "${PROJECT_VERSION} (Experimental)") |
| 21 | +set(DOXYGEN_EXCLUDE_SYMBOLS "internal" "documentai_internal" |
| 22 | + "documentai_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::documentai_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_documentai_protos |
| 40 | + # cmake-format: sort |
| 41 | + ${EXTERNAL_GOOGLEAPIS_SOURCE}/google/cloud/documentai/v1/document.proto |
| 42 | + ${EXTERNAL_GOOGLEAPIS_SOURCE}/google/cloud/documentai/v1/document_io.proto |
| 43 | + ${EXTERNAL_GOOGLEAPIS_SOURCE}/google/cloud/documentai/v1/document_processor_service.proto |
| 44 | + ${EXTERNAL_GOOGLEAPIS_SOURCE}/google/cloud/documentai/v1/geometry.proto |
| 45 | + ${EXTERNAL_GOOGLEAPIS_SOURCE}/google/cloud/documentai/v1/operation_metadata.proto |
| 46 | + PROTO_PATH_DIRECTORIES |
| 47 | + "${EXTERNAL_GOOGLEAPIS_SOURCE}" |
| 48 | + "${PROTO_INCLUDE_DIR}") |
| 49 | +external_googleapis_set_version_and_alias(documentai_protos) |
| 50 | +target_link_libraries( |
| 51 | + google_cloud_cpp_documentai_protos |
| 52 | + PUBLIC # |
| 53 | + google-cloud-cpp::api_annotations_protos |
| 54 | + google-cloud-cpp::api_client_protos |
| 55 | + google-cloud-cpp::api_field_behavior_protos |
| 56 | + google-cloud-cpp::api_http_protos |
| 57 | + google-cloud-cpp::api_resource_protos |
| 58 | + google-cloud-cpp::longrunning_operations_protos |
| 59 | + google-cloud-cpp::rpc_status_protos |
| 60 | + google-cloud-cpp::type_color_protos |
| 61 | + google-cloud-cpp::type_date_protos |
| 62 | + google-cloud-cpp::type_datetime_protos |
| 63 | + google-cloud-cpp::type_money_protos |
| 64 | + google-cloud-cpp::type_postal_address_protos) |
| 65 | + |
| 66 | +file( |
| 67 | + GLOB source_files |
| 68 | + RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" |
| 69 | + "*.h" "*.cc" "internal/*.h" "internal/*.cc") |
| 70 | +list(SORT source_files) |
| 71 | +add_library(google_cloud_cpp_documentai ${source_files}) |
| 72 | +target_include_directories( |
| 73 | + google_cloud_cpp_documentai |
| 74 | + PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}> |
| 75 | + $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}> |
| 76 | + $<INSTALL_INTERFACE:include>) |
| 77 | +target_link_libraries( |
| 78 | + google_cloud_cpp_documentai |
| 79 | + PUBLIC google-cloud-cpp::grpc_utils google-cloud-cpp::common |
| 80 | + google-cloud-cpp::documentai_protos) |
| 81 | +google_cloud_cpp_add_common_options(google_cloud_cpp_documentai) |
| 82 | +set_target_properties( |
| 83 | + google_cloud_cpp_documentai |
| 84 | + PROPERTIES EXPORT_NAME google-cloud-cpp::experimental-documentai |
| 85 | + VERSION "${PROJECT_VERSION}" SOVERSION |
| 86 | + "${PROJECT_VERSION_MAJOR}") |
| 87 | +target_compile_options(google_cloud_cpp_documentai |
| 88 | + PUBLIC ${GOOGLE_CLOUD_CPP_EXCEPTIONS_FLAG}) |
| 89 | + |
| 90 | +add_library(google-cloud-cpp::experimental-documentai ALIAS |
| 91 | + google_cloud_cpp_documentai) |
| 92 | + |
| 93 | +# Create a header-only library for the mocks. We use a CMake `INTERFACE` library |
| 94 | +# for these, a regular library would not work on macOS (where the library needs |
| 95 | +# at least one .o file). Unfortunately INTERFACE libraries are a bit weird in |
| 96 | +# that they need absolute paths for their sources. |
| 97 | +file( |
| 98 | + GLOB relative_mock_files |
| 99 | + RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" |
| 100 | + "mocks/*.h") |
| 101 | +list(SORT relative_mock_files) |
| 102 | +set(mock_files) |
| 103 | +foreach (file IN LISTS relative_mock_files) |
| 104 | + list(APPEND mock_files "${CMAKE_CURRENT_SOURCE_DIR}/${file}") |
| 105 | +endforeach () |
| 106 | +add_library(google_cloud_cpp_documentai_mocks INTERFACE) |
| 107 | +target_sources(google_cloud_cpp_documentai_mocks INTERFACE ${mock_files}) |
| 108 | +target_link_libraries( |
| 109 | + google_cloud_cpp_documentai_mocks |
| 110 | + INTERFACE google-cloud-cpp::experimental-documentai GTest::gmock_main |
| 111 | + GTest::gmock GTest::gtest) |
| 112 | +set_target_properties( |
| 113 | + google_cloud_cpp_documentai_mocks |
| 114 | + PROPERTIES EXPORT_NAME google-cloud-cpp::experimental-documentai_mocks) |
| 115 | +target_include_directories( |
| 116 | + google_cloud_cpp_documentai_mocks |
| 117 | + INTERFACE $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}> |
| 118 | + $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}> |
| 119 | + $<INSTALL_INTERFACE:include>) |
| 120 | +target_compile_options(google_cloud_cpp_documentai_mocks |
| 121 | + INTERFACE ${GOOGLE_CLOUD_CPP_EXCEPTIONS_FLAG}) |
| 122 | + |
| 123 | +include(CTest) |
| 124 | +if (BUILD_TESTING) |
| 125 | + add_executable(documentai_quickstart "quickstart/quickstart.cc") |
| 126 | + target_link_libraries(documentai_quickstart |
| 127 | + PRIVATE google-cloud-cpp::experimental-documentai) |
| 128 | + google_cloud_cpp_add_common_options(documentai_quickstart) |
| 129 | + add_test( |
| 130 | + NAME documentai_quickstart |
| 131 | + COMMAND |
| 132 | + cmake -P "${PROJECT_SOURCE_DIR}/cmake/quickstart-runner.cmake" |
| 133 | + $<TARGET_FILE:documentai_quickstart> GOOGLE_CLOUD_PROJECT |
| 134 | + # TODO(#7976): Enable this quickstart and make it run. |
| 135 | + ) |
| 136 | + set_tests_properties( |
| 137 | + documentai_quickstart PROPERTIES DISABLED true LABELS |
| 138 | + "integration-test;quickstart") |
| 139 | +endif () |
| 140 | + |
| 141 | +# Get the destination directories based on the GNU recommendations. |
| 142 | +include(GNUInstallDirs) |
| 143 | + |
| 144 | +# Export the CMake targets to make it easy to create configuration files. |
| 145 | +install( |
| 146 | + EXPORT google_cloud_cpp_documentai-targets |
| 147 | + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/google_cloud_cpp_documentai" |
| 148 | + COMPONENT google_cloud_cpp_development) |
| 149 | + |
| 150 | +# Install the libraries and headers in the locations determined by |
| 151 | +# GNUInstallDirs |
| 152 | +install( |
| 153 | + TARGETS google_cloud_cpp_documentai google_cloud_cpp_documentai_protos |
| 154 | + EXPORT google_cloud_cpp_documentai-targets |
| 155 | + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} |
| 156 | + COMPONENT google_cloud_cpp_runtime |
| 157 | + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 158 | + COMPONENT google_cloud_cpp_runtime |
| 159 | + NAMELINK_SKIP |
| 160 | + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 161 | + COMPONENT google_cloud_cpp_development) |
| 162 | +# With CMake-3.12 and higher we could avoid this separate command (and the |
| 163 | +# duplication). |
| 164 | +install( |
| 165 | + TARGETS google_cloud_cpp_documentai google_cloud_cpp_documentai_protos |
| 166 | + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 167 | + COMPONENT google_cloud_cpp_development |
| 168 | + NAMELINK_ONLY |
| 169 | + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 170 | + COMPONENT google_cloud_cpp_development) |
| 171 | + |
| 172 | +google_cloud_cpp_install_proto_library_protos( |
| 173 | + "google_cloud_cpp_documentai_protos" "${EXTERNAL_GOOGLEAPIS_SOURCE}") |
| 174 | +google_cloud_cpp_install_proto_library_headers( |
| 175 | + "google_cloud_cpp_documentai_protos") |
| 176 | +google_cloud_cpp_install_headers("google_cloud_cpp_documentai" |
| 177 | + "include/google/cloud/documentai") |
| 178 | +google_cloud_cpp_install_headers("google_cloud_cpp_documentai_mocks" |
| 179 | + "include/google/cloud/documentai") |
| 180 | + |
| 181 | +# Setup global variables used in the following *.in files. |
| 182 | +set(GOOGLE_CLOUD_CONFIG_VERSION_MAJOR ${PROJECT_VERSION_MAJOR}) |
| 183 | +set(GOOGLE_CLOUD_CONFIG_VERSION_MINOR ${PROJECT_VERSION_MINOR}) |
| 184 | +set(GOOGLE_CLOUD_CONFIG_VERSION_PATCH ${PROJECT_VERSION_PATCH}) |
| 185 | +set(GOOGLE_CLOUD_PC_NAME "The Cloud Document AI API C++ Client Library") |
| 186 | +set(GOOGLE_CLOUD_PC_DESCRIPTION |
| 187 | + "Provides C++ APIs to use the Cloud Document AI API.") |
| 188 | +set(GOOGLE_CLOUD_PC_LIBS "-lgoogle_cloud_cpp_documentai") |
| 189 | +string(CONCAT GOOGLE_CLOUD_PC_REQUIRES "google_cloud_cpp_grpc_utils" |
| 190 | + " google_cloud_cpp_common" " google_cloud_cpp_documentai_protos") |
| 191 | + |
| 192 | +# Create and install the pkg-config files. |
| 193 | +configure_file("${PROJECT_SOURCE_DIR}/google/cloud/documentai/config.pc.in" |
| 194 | + "google_cloud_cpp_documentai.pc" @ONLY) |
| 195 | +install( |
| 196 | + FILES "${CMAKE_CURRENT_BINARY_DIR}/google_cloud_cpp_documentai.pc" |
| 197 | + DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig" |
| 198 | + COMPONENT google_cloud_cpp_development) |
| 199 | + |
| 200 | +# Create and install the CMake configuration files. |
| 201 | +include(CMakePackageConfigHelpers) |
| 202 | +configure_file("config.cmake.in" "google_cloud_cpp_documentai-config.cmake" |
| 203 | + @ONLY) |
| 204 | +write_basic_package_version_file( |
| 205 | + "google_cloud_cpp_documentai-config-version.cmake" |
| 206 | + VERSION ${PROJECT_VERSION} |
| 207 | + COMPATIBILITY ExactVersion) |
| 208 | + |
| 209 | +install( |
| 210 | + FILES |
| 211 | + "${CMAKE_CURRENT_BINARY_DIR}/google_cloud_cpp_documentai-config.cmake" |
| 212 | + "${CMAKE_CURRENT_BINARY_DIR}/google_cloud_cpp_documentai-config-version.cmake" |
| 213 | + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/google_cloud_cpp_documentai" |
| 214 | + COMPONENT google_cloud_cpp_development) |
| 215 | + |
| 216 | +external_googleapis_install_pc("google_cloud_cpp_documentai_protos" |
| 217 | + "${PROJECT_SOURCE_DIR}/external/googleapis") |
0 commit comments