|
| 1 | +# ~~~ |
| 2 | +# Copyright 2025 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 | +cmake_minimum_required(VERSION 3.13...3.24) |
| 18 | + |
| 19 | +# Define the project name and where to report bugs. |
| 20 | +set(PACKAGE_BUGREPORT "https://github.com/googleapis/google-cloud-cpp/issues") |
| 21 | + |
| 22 | +project( |
| 23 | + bigtable-emulator |
| 24 | + VERSION 1.0.0 |
| 25 | + LANGUAGES CXX) |
| 26 | +set(PROJECT_VERSION_PRE_RELEASE "rc") |
| 27 | + |
| 28 | +if (NOT "${PROJECT_VERSION_PRE_RELEASE}" STREQUAL "") |
| 29 | + set(PROJECT_VERSION "${PROJECT_VERSION}-${PROJECT_VERSION_PRE_RELEASE}") |
| 30 | +endif () |
| 31 | + |
| 32 | +# Automatically update the version(s) in the `MODULE.bazel` file. |
| 33 | +file(READ "MODULE.bazel" module_contents) |
| 34 | +string( |
| 35 | + REGEX |
| 36 | + REPLACE "version = \".*\", # Updated by CMake" |
| 37 | + "version = \"${PROJECT_VERSION}\", # Updated by CMake" |
| 38 | + updated_contents "${module_contents}") |
| 39 | +string( |
| 40 | + REGEX |
| 41 | + REPLACE |
| 42 | + "compatibility_level = .*, # Updated by CMake" |
| 43 | + "compatibility_level = ${PROJECT_VERSION_MAJOR}, # Updated by CMake" |
| 44 | + updated_contents "${updated_contents}") |
| 45 | +if (NOT ("${updated_contents}" STREQUAL "${module_contents}")) |
| 46 | + # Rewrite the file *only* if it was updated. |
| 47 | + file(WRITE "MODULE.bazel" "${updated_contents}") |
| 48 | +endif () |
| 49 | + |
| 50 | +if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") |
| 51 | + if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.5) |
| 52 | + message( |
| 53 | + WARNING "The `google-cloud-cpp` library is tested with GCC >= 7.5." |
| 54 | + " We will consider patches for older versions.") |
| 55 | + endif () |
| 56 | +elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") |
| 57 | + if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 6.0) |
| 58 | + message( |
| 59 | + WARNING |
| 60 | + "The `google-cloud-cpp` library is tested with Clang >= 6.0." |
| 61 | + " We will consider patches for older versions.") |
| 62 | + endif () |
| 63 | +elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") |
| 64 | + if (CMAKE_VERSION VERSION_LESS 3.15) |
| 65 | + message( |
| 66 | + FATAL_ERROR |
| 67 | + "MSVC builds require CMake >= 3.15." |
| 68 | + " Previous versions of CMake lack a standard mechanism to" |
| 69 | + " select the runtime C++ library.") |
| 70 | + endif () |
| 71 | +endif () |
| 72 | + |
| 73 | +list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake) |
| 74 | + |
| 75 | +include(FetchContent) |
| 76 | + |
| 77 | +FetchContent_Declare( |
| 78 | + google-cloud-cpp |
| 79 | + URL https://github.com/googleapis/google-cloud-cpp/archive/refs/tags/v2.39.0.tar.gz |
| 80 | +) |
| 81 | + |
| 82 | +FetchContent_MakeAvailable(google-cloud-cpp) |
| 83 | + |
| 84 | +add_library( |
| 85 | + bigtable_emulator_common # cmake-format: sort |
| 86 | + cell_view.h |
| 87 | + cluster.cc |
| 88 | + cluster.h |
| 89 | + column_family.cc |
| 90 | + column_family.h |
| 91 | + filter.cc |
| 92 | + filter.h |
| 93 | + filtered_map.h |
| 94 | + bigtable_limits.h |
| 95 | + range_set.cc |
| 96 | + range_set.h |
| 97 | + row_streamer.cc |
| 98 | + row_streamer.h |
| 99 | + server.cc |
| 100 | + server.h |
| 101 | + table.cc |
| 102 | + table.h |
| 103 | + test_util.cc |
| 104 | + test_util.h |
| 105 | + to_grpc_status.cc |
| 106 | + to_grpc_status.h) |
| 107 | + |
| 108 | +target_link_libraries( |
| 109 | + bigtable_emulator_common |
| 110 | + google-cloud-cpp::bigtable |
| 111 | + google-cloud-cpp::bigtable_protos |
| 112 | + google-cloud-cpp::common |
| 113 | + google-cloud-cpp::grpc_utils) |
| 114 | + |
| 115 | +google_cloud_cpp_add_common_options(bigtable_emulator_common) |
| 116 | + |
| 117 | +include(CreateBazelConfig) |
| 118 | +create_bazel_config(bigtable_emulator_common YEAR 2024) |
| 119 | + |
| 120 | +include(CTest) |
| 121 | + |
| 122 | +if (BUILD_TESTING) |
| 123 | + # List the unit tests, then setup the targets and dependencies. |
| 124 | + set(bigtable_emulator_unit_tests |
| 125 | + # cmake-format: sort |
| 126 | + column_family_test.cc |
| 127 | + conditional_mutations_test.cc |
| 128 | + drop_row_range_test.cc |
| 129 | + filter_test.cc |
| 130 | + filtered_map_test.cc |
| 131 | + mutations_test.cc |
| 132 | + range_set_test.cc |
| 133 | + server_test.cc |
| 134 | + table_test.cc) |
| 135 | + export_list_to_bazel("bigtable_emulator_unit_tests.bzl" |
| 136 | + "bigtable_emulator_unit_tests" YEAR "2024") |
| 137 | + |
| 138 | + foreach (fname ${bigtable_emulator_unit_tests}) |
| 139 | + google_cloud_cpp_add_executable(target "bigtable_emulator" "${fname}") |
| 140 | + target_link_libraries( |
| 141 | + ${target} |
| 142 | + PRIVATE bigtable_emulator_common |
| 143 | + bigtable_client_testing |
| 144 | + google_cloud_cpp_testing |
| 145 | + google_cloud_cpp_testing_grpc |
| 146 | + google-cloud-cpp::bigtable |
| 147 | + google-cloud-cpp::bigtable_protos |
| 148 | + google-cloud-cpp::common |
| 149 | + google-cloud-cpp::grpc_utils) |
| 150 | + google_cloud_cpp_add_common_options(${target}) |
| 151 | + add_test(NAME ${target} COMMAND ${target}) |
| 152 | + endforeach () |
| 153 | +endif () |
| 154 | + |
| 155 | +find_package(absl CONFIG REQUIRED) |
| 156 | + |
| 157 | +set(bigtable_emulator_programs # cmake-format: sort |
| 158 | + emulator.cc) |
| 159 | +export_list_to_bazel("bigtable_emulator_programs.bzl" |
| 160 | + "bigtable_emulator_programs" YEAR "2024") |
| 161 | + |
| 162 | +foreach (fname ${bigtable_emulator_programs}) |
| 163 | + google_cloud_cpp_add_executable(target "bigtable" "${fname}") |
| 164 | + target_link_libraries( |
| 165 | + ${target} |
| 166 | + PRIVATE bigtable_emulator_common |
| 167 | + absl::flags |
| 168 | + absl::flags_parse |
| 169 | + google-cloud-cpp::bigtable |
| 170 | + google-cloud-cpp::bigtable_protos |
| 171 | + google-cloud-cpp::common |
| 172 | + google-cloud-cpp::grpc_utils |
| 173 | + google_cloud_cpp_testing) |
| 174 | + google_cloud_cpp_add_common_options(${target}) |
| 175 | +endforeach () |
0 commit comments