|
| 1 | +# ~~~ |
| 2 | +# Copyright 2023 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 | +add_library( |
| 18 | + google_cloud_cpp_bigquery_rest # cmake-format: sort |
| 19 | + v2/minimal/internal/bigquery_http_response.cc |
| 20 | + v2/minimal/internal/bigquery_http_response.h |
| 21 | + v2/minimal/internal/job_idempotency_policy.cc |
| 22 | + v2/minimal/internal/job_idempotency_policy.h |
| 23 | + v2/minimal/internal/job_logging.cc |
| 24 | + v2/minimal/internal/job_logging.h |
| 25 | + v2/minimal/internal/job_metadata.cc |
| 26 | + v2/minimal/internal/job_metadata.h |
| 27 | + v2/minimal/internal/job_options.cc |
| 28 | + v2/minimal/internal/job_options.h |
| 29 | + v2/minimal/internal/job_rest_connection_impl.cc |
| 30 | + v2/minimal/internal/job_rest_connection_impl.h |
| 31 | + v2/minimal/internal/job_rest_stub.cc |
| 32 | + v2/minimal/internal/job_rest_stub.h |
| 33 | + v2/minimal/internal/job_rest_stub_factory.cc |
| 34 | + v2/minimal/internal/job_rest_stub_factory.h |
| 35 | + v2/minimal/internal/job_retry_policy.h) |
| 36 | +target_include_directories( |
| 37 | + google_cloud_cpp_bigquery_rest |
| 38 | + PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}> |
| 39 | + $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}> |
| 40 | + $<INSTALL_INTERFACE:include>) |
| 41 | +target_link_libraries( |
| 42 | + google_cloud_cpp_bigquery_rest PUBLIC google-cloud-cpp::rest_internal |
| 43 | + google-cloud-cpp::common) |
| 44 | +google_cloud_cpp_add_common_options(google_cloud_cpp_bigquery_rest) |
| 45 | +set_target_properties( |
| 46 | + google_cloud_cpp_bigquery_rest |
| 47 | + PROPERTIES EXPORT_NAME google-cloud-cpp::experimental-bigquery_rest |
| 48 | + VERSION "${PROJECT_VERSION}" |
| 49 | + SOVERSION "${PROJECT_VERSION_MAJOR}") |
| 50 | +target_compile_options(google_cloud_cpp_bigquery_rest |
| 51 | + PUBLIC ${GOOGLE_CLOUD_CPP_EXCEPTIONS_FLAG}) |
| 52 | + |
| 53 | +add_library(google-cloud-cpp::experimental-bigquery_rest ALIAS |
| 54 | + google_cloud_cpp_bigquery_rest) |
| 55 | + |
| 56 | +# To avoid maintaining the list of files for the library, export them to a .bzl |
| 57 | +# file. |
| 58 | +include(CreateBazelConfig) |
| 59 | +create_bazel_config(google_cloud_cpp_bigquery_rest YEAR "2023") |
| 60 | + |
| 61 | +# Define the tests in a function so we have a new scope for variable names. |
| 62 | +function (bigquery_rest_define_tests) |
| 63 | + # The tests require googletest to be installed. Force CMake to use the |
| 64 | + # config file for googletest (that is, the CMake file installed by |
| 65 | + # googletest itself), because the generic `FindGTest` module does not define |
| 66 | + # the GTest::gmock target, and the target names are also weird. |
| 67 | + find_package(GTest CONFIG REQUIRED) |
| 68 | + |
| 69 | + set(bigquery_rest_unit_tests |
| 70 | + # cmake-format: sort |
| 71 | + v2/minimal/internal/bigquery_http_response_test.cc) |
| 72 | + |
| 73 | + # Export the list of unit tests to a .bzl file so we do not need to maintain |
| 74 | + # the list in two places. |
| 75 | + export_list_to_bazel("bigquery_rest_unit_tests.bzl" |
| 76 | + "bigquery_rest_unit_tests" YEAR "2023") |
| 77 | + |
| 78 | + # Create a custom target so we can say "build all the tests" |
| 79 | + add_custom_target(bigquery_rest-tests) |
| 80 | + |
| 81 | + # Generate a target for each unit test. |
| 82 | + foreach (fname ${bigquery_rest_unit_tests}) |
| 83 | + google_cloud_cpp_add_executable(target "bigquery" "${fname}") |
| 84 | + target_link_libraries( |
| 85 | + ${target} |
| 86 | + PRIVATE google_cloud_cpp_testing |
| 87 | + google-cloud-cpp::experimental-bigquery_rest |
| 88 | + GTest::gmock_main GTest::gmock GTest::gtest) |
| 89 | + google_cloud_cpp_add_common_options(${target}) |
| 90 | + |
| 91 | + # With googletest it is relatively easy to exceed the default number of |
| 92 | + # sections (~65,000) in a single .obj file. Add the /bigobj option to |
| 93 | + # all the tests, even if it is not needed. |
| 94 | + if (MSVC) |
| 95 | + target_compile_options(${target} PRIVATE "/bigobj") |
| 96 | + endif () |
| 97 | + add_test(NAME ${target} COMMAND ${target}) |
| 98 | + add_dependencies(bigquery_rest-tests ${target}) |
| 99 | + endforeach () |
| 100 | +endfunction () |
| 101 | + |
| 102 | +if (BUILD_TESTING) |
| 103 | + bigquery_rest_define_tests() |
| 104 | +endif () |
0 commit comments