about summary refs log tree commit diff
path: root/CMakeLists.txt
blob: 0914a89bb8d71ad3de6ba983ceeab108352099b8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
# ~~~
# 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")

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 ""
    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)
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}"
                                                  "${GOOGLEAPIS_CPP_SOURCE}")
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")