|
| 1 | +# Copyright 2017 Google Inc. |
| 2 | +# All Rights Reserved. |
| 3 | +# |
| 4 | +# |
| 5 | +# Redistribution and use in source and binary forms, with or without |
| 6 | +# modification, are permitted provided that the following conditions are |
| 7 | +# met: |
| 8 | +# |
| 9 | +# * Redistributions of source code must retain the above copyright |
| 10 | +# notice, this list of conditions and the following disclaimer. |
| 11 | +# * Redistributions in binary form must reproduce the above |
| 12 | +# copyright notice, this list of conditions and the following disclaimer |
| 13 | +# in the documentation and/or other materials provided with the |
| 14 | +# distribution. |
| 15 | +# * Neither the name of Google Inc. nor the names of its |
| 16 | +# contributors may be used to endorse or promote products derived from |
| 17 | +# this software without specific prior written permission. |
| 18 | +# |
| 19 | +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 20 | +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 21 | +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 22 | +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 23 | +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 24 | +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 25 | +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 26 | +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 27 | +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 28 | +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 29 | +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 | +# |
| 31 | +# Bazel Build for Google C++ Testing Framework(Google Test) |
| 32 | + |
| 33 | +load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test") |
| 34 | + |
| 35 | +package(default_visibility = ["//visibility:public"]) |
| 36 | + |
| 37 | +licenses(["notice"]) |
| 38 | + |
| 39 | +exports_files(["LICENSE"]) |
| 40 | + |
| 41 | +config_setting( |
| 42 | + name = "windows", |
| 43 | + constraint_values = ["@platforms//os:windows"], |
| 44 | +) |
| 45 | + |
| 46 | +config_setting( |
| 47 | + name = "msvc_compiler", |
| 48 | + flag_values = { |
| 49 | + "@bazel_tools//tools/cpp:compiler": "msvc-cl", |
| 50 | + }, |
| 51 | + visibility = [":__subpackages__"], |
| 52 | +) |
| 53 | + |
| 54 | +config_setting( |
| 55 | + name = "has_absl", |
| 56 | + values = {"define": "absl=1"}, |
| 57 | +) |
| 58 | + |
| 59 | +# Library that defines the FRIEND_TEST macro. |
| 60 | +cc_library( |
| 61 | + name = "gtest_prod", |
| 62 | + hdrs = ["googletest/include/gtest/gtest_prod.h"], |
| 63 | + includes = ["googletest/include"], |
| 64 | +) |
| 65 | + |
| 66 | +# Google Test including Google Mock |
| 67 | +cc_library( |
| 68 | + name = "gtest", |
| 69 | + srcs = glob( |
| 70 | + include = [ |
| 71 | + "googletest/src/*.cc", |
| 72 | + "googletest/src/*.h", |
| 73 | + "googletest/include/gtest/**/*.h", |
| 74 | + "googlemock/src/*.cc", |
| 75 | + "googlemock/include/gmock/**/*.h", |
| 76 | + ], |
| 77 | + exclude = [ |
| 78 | + "googletest/src/gtest-all.cc", |
| 79 | + "googletest/src/gtest_main.cc", |
| 80 | + "googlemock/src/gmock-all.cc", |
| 81 | + "googlemock/src/gmock_main.cc", |
| 82 | + ], |
| 83 | + ), |
| 84 | + hdrs = glob([ |
| 85 | + "googletest/include/gtest/*.h", |
| 86 | + "googlemock/include/gmock/*.h", |
| 87 | + ]), |
| 88 | + copts = select({ |
| 89 | + ":windows": [], |
| 90 | + "//conditions:default": ["-pthread"], |
| 91 | + }), |
| 92 | + defines = select({ |
| 93 | + ":has_absl": ["GTEST_HAS_ABSL=1"], |
| 94 | + "//conditions:default": [], |
| 95 | + }), |
| 96 | + features = select({ |
| 97 | + ":windows": ["windows_export_all_symbols"], |
| 98 | + "//conditions:default": [], |
| 99 | + }), |
| 100 | + includes = [ |
| 101 | + "googlemock", |
| 102 | + "googlemock/include", |
| 103 | + "googletest", |
| 104 | + "googletest/include", |
| 105 | + ], |
| 106 | + linkopts = select({ |
| 107 | + ":windows": [], |
| 108 | + "//conditions:default": ["-pthread"], |
| 109 | + }), |
| 110 | + deps = select({ |
| 111 | + ":has_absl": [ |
| 112 | + "@com_google_absl//absl/debugging:failure_signal_handler", |
| 113 | + "@com_google_absl//absl/debugging:stacktrace", |
| 114 | + "@com_google_absl//absl/debugging:symbolize", |
| 115 | + "@com_google_absl//absl/strings", |
| 116 | + "@com_google_absl//absl/types:any", |
| 117 | + "@com_google_absl//absl/types:optional", |
| 118 | + "@com_google_absl//absl/types:variant", |
| 119 | + ], |
| 120 | + "//conditions:default": [], |
| 121 | + }), |
| 122 | +) |
| 123 | + |
| 124 | +cc_library( |
| 125 | + name = "gtest_main", |
| 126 | + srcs = ["googlemock/src/gmock_main.cc"], |
| 127 | + features = select({ |
| 128 | + ":windows": ["windows_export_all_symbols"], |
| 129 | + "//conditions:default": [], |
| 130 | + }), |
| 131 | + deps = [":gtest"], |
| 132 | +) |
| 133 | + |
| 134 | +# The following rules build samples of how to use gTest. |
| 135 | +cc_library( |
| 136 | + name = "gtest_sample_lib", |
| 137 | + srcs = [ |
| 138 | + "googletest/samples/sample1.cc", |
| 139 | + "googletest/samples/sample2.cc", |
| 140 | + "googletest/samples/sample4.cc", |
| 141 | + ], |
| 142 | + hdrs = [ |
| 143 | + "googletest/samples/prime_tables.h", |
| 144 | + "googletest/samples/sample1.h", |
| 145 | + "googletest/samples/sample2.h", |
| 146 | + "googletest/samples/sample3-inl.h", |
| 147 | + "googletest/samples/sample4.h", |
| 148 | + ], |
| 149 | + features = select({ |
| 150 | + ":windows": ["windows_export_all_symbols"], |
| 151 | + "//conditions:default": [], |
| 152 | + }), |
| 153 | +) |
| 154 | + |
| 155 | +cc_test( |
| 156 | + name = "gtest_samples", |
| 157 | + size = "small", |
| 158 | + # All Samples except: |
| 159 | + # sample9 (main) |
| 160 | + # sample10 (main and takes a command line option and needs to be separate) |
| 161 | + srcs = [ |
| 162 | + "googletest/samples/sample1_unittest.cc", |
| 163 | + "googletest/samples/sample2_unittest.cc", |
| 164 | + "googletest/samples/sample3_unittest.cc", |
| 165 | + "googletest/samples/sample4_unittest.cc", |
| 166 | + "googletest/samples/sample5_unittest.cc", |
| 167 | + "googletest/samples/sample6_unittest.cc", |
| 168 | + "googletest/samples/sample7_unittest.cc", |
| 169 | + "googletest/samples/sample8_unittest.cc", |
| 170 | + ], |
| 171 | + linkstatic = 0, |
| 172 | + deps = [ |
| 173 | + "gtest_sample_lib", |
| 174 | + ":gtest_main", |
| 175 | + ], |
| 176 | +) |
| 177 | + |
| 178 | +cc_test( |
| 179 | + name = "sample9_unittest", |
| 180 | + size = "small", |
| 181 | + srcs = ["googletest/samples/sample9_unittest.cc"], |
| 182 | + deps = [":gtest"], |
| 183 | +) |
| 184 | + |
| 185 | +cc_test( |
| 186 | + name = "sample10_unittest", |
| 187 | + size = "small", |
| 188 | + srcs = ["googletest/samples/sample10_unittest.cc"], |
| 189 | + deps = [":gtest"], |
| 190 | +) |
0 commit comments