misterg | a7b21c9 | 2018-10-01 13:26:47 -0400 | [diff] [blame] | 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 | # |
misterg | a7b21c9 | 2018-10-01 13:26:47 -0400 | [diff] [blame] | 31 | # Bazel Build for Google C++ Testing Framework(Google Test) |
| 32 | |
Yannic Bonenberger | 6fd262e | 2019-08-07 17:04:29 +0200 | [diff] [blame] | 33 | load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test") |
| 34 | |
misterg | a7b21c9 | 2018-10-01 13:26:47 -0400 | [diff] [blame] | 35 | package(default_visibility = ["//visibility:public"]) |
| 36 | |
| 37 | licenses(["notice"]) |
| 38 | |
Rob Earhart | 025e1a4 | 2020-08-12 16:10:57 -0700 | [diff] [blame] | 39 | exports_files(["LICENSE"]) |
| 40 | |
misterg | a7b21c9 | 2018-10-01 13:26:47 -0400 | [diff] [blame] | 41 | config_setting( |
| 42 | name = "windows", |
Ezekiel Warren | 5c08f92 | 2021-03-14 18:41:28 -0700 | [diff] [blame] | 43 | constraint_values = ["@platforms//os:windows"], |
misterg | a7b21c9 | 2018-10-01 13:26:47 -0400 | [diff] [blame] | 44 | ) |
| 45 | |
| 46 | config_setting( |
Abseil Team | 1a8ecf1 | 2021-03-20 01:24:27 -0400 | [diff] [blame] | 47 | name = "msvc_compiler", |
| 48 | flag_values = { |
| 49 | "@bazel_tools//tools/cpp:compiler": "msvc-cl", |
| 50 | }, |
| 51 | visibility = [":__subpackages__"], |
| 52 | ) |
| 53 | |
| 54 | config_setting( |
misterg | a7b21c9 | 2018-10-01 13:26:47 -0400 | [diff] [blame] | 55 | name = "has_absl", |
| 56 | values = {"define": "absl=1"}, |
| 57 | ) |
| 58 | |
Abseil Team | 252ce9c | 2021-04-26 13:09:24 -0400 | [diff] [blame] | 59 | config_setting( |
| 60 | name = "ios", |
| 61 | values = {"apple_platform_type": "ios"}, |
| 62 | visibility = [":__subpackages__"], |
| 63 | ) |
| 64 | |
krzysio | 105579a | 2018-11-06 10:37:19 -0500 | [diff] [blame] | 65 | # Library that defines the FRIEND_TEST macro. |
| 66 | cc_library( |
| 67 | name = "gtest_prod", |
| 68 | hdrs = ["googletest/include/gtest/gtest_prod.h"], |
| 69 | includes = ["googletest/include"], |
| 70 | ) |
| 71 | |
misterg | a7b21c9 | 2018-10-01 13:26:47 -0400 | [diff] [blame] | 72 | # Google Test including Google Mock |
| 73 | cc_library( |
| 74 | name = "gtest", |
| 75 | srcs = glob( |
| 76 | include = [ |
| 77 | "googletest/src/*.cc", |
| 78 | "googletest/src/*.h", |
| 79 | "googletest/include/gtest/**/*.h", |
| 80 | "googlemock/src/*.cc", |
| 81 | "googlemock/include/gmock/**/*.h", |
| 82 | ], |
| 83 | exclude = [ |
| 84 | "googletest/src/gtest-all.cc", |
| 85 | "googletest/src/gtest_main.cc", |
| 86 | "googlemock/src/gmock-all.cc", |
| 87 | "googlemock/src/gmock_main.cc", |
| 88 | ], |
| 89 | ), |
| 90 | hdrs = glob([ |
| 91 | "googletest/include/gtest/*.h", |
| 92 | "googlemock/include/gmock/*.h", |
| 93 | ]), |
krzysio | 105579a | 2018-11-06 10:37:19 -0500 | [diff] [blame] | 94 | copts = select({ |
Abseil Team | 252ce9c | 2021-04-26 13:09:24 -0400 | [diff] [blame] | 95 | ":ios": [ |
| 96 | "-xobjective-c++", |
| 97 | "-pthread", |
| 98 | ], |
krzysio | 105579a | 2018-11-06 10:37:19 -0500 | [diff] [blame] | 99 | ":windows": [], |
| 100 | "//conditions:default": ["-pthread"], |
| 101 | }), |
| 102 | defines = select({ |
| 103 | ":has_absl": ["GTEST_HAS_ABSL=1"], |
| 104 | "//conditions:default": [], |
| 105 | }), |
Yannic Bonenberger | 6fd262e | 2019-08-07 17:04:29 +0200 | [diff] [blame] | 106 | features = select({ |
| 107 | ":windows": ["windows_export_all_symbols"], |
| 108 | "//conditions:default": [], |
| 109 | }), |
misterg | a7b21c9 | 2018-10-01 13:26:47 -0400 | [diff] [blame] | 110 | includes = [ |
| 111 | "googlemock", |
| 112 | "googlemock/include", |
| 113 | "googletest", |
| 114 | "googletest/include", |
| 115 | ], |
| 116 | linkopts = select({ |
| 117 | ":windows": [], |
krzysio | 105579a | 2018-11-06 10:37:19 -0500 | [diff] [blame] | 118 | "//conditions:default": ["-pthread"], |
misterg | a7b21c9 | 2018-10-01 13:26:47 -0400 | [diff] [blame] | 119 | }), |
krzysio | 105579a | 2018-11-06 10:37:19 -0500 | [diff] [blame] | 120 | deps = select({ |
| 121 | ":has_absl": [ |
| 122 | "@com_google_absl//absl/debugging:failure_signal_handler", |
| 123 | "@com_google_absl//absl/debugging:stacktrace", |
| 124 | "@com_google_absl//absl/debugging:symbolize", |
| 125 | "@com_google_absl//absl/strings", |
Krystian Kuzniarek | 843267f | 2020-03-07 17:03:50 +0100 | [diff] [blame] | 126 | "@com_google_absl//absl/types:any", |
krzysio | 105579a | 2018-11-06 10:37:19 -0500 | [diff] [blame] | 127 | "@com_google_absl//absl/types:optional", |
| 128 | "@com_google_absl//absl/types:variant", |
| 129 | ], |
| 130 | "//conditions:default": [], |
| 131 | }), |
misterg | a7b21c9 | 2018-10-01 13:26:47 -0400 | [diff] [blame] | 132 | ) |
| 133 | |
| 134 | cc_library( |
| 135 | name = "gtest_main", |
krzysio | 105579a | 2018-11-06 10:37:19 -0500 | [diff] [blame] | 136 | srcs = ["googlemock/src/gmock_main.cc"], |
Pavel Samolysov | c868da1 | 2019-01-14 15:42:36 +0300 | [diff] [blame] | 137 | features = select({ |
| 138 | ":windows": ["windows_export_all_symbols"], |
| 139 | "//conditions:default": [], |
Yannic Bonenberger | 6fd262e | 2019-08-07 17:04:29 +0200 | [diff] [blame] | 140 | }), |
| 141 | deps = [":gtest"], |
misterg | a7b21c9 | 2018-10-01 13:26:47 -0400 | [diff] [blame] | 142 | ) |
| 143 | |
| 144 | # The following rules build samples of how to use gTest. |
| 145 | cc_library( |
| 146 | name = "gtest_sample_lib", |
| 147 | srcs = [ |
| 148 | "googletest/samples/sample1.cc", |
| 149 | "googletest/samples/sample2.cc", |
| 150 | "googletest/samples/sample4.cc", |
| 151 | ], |
| 152 | hdrs = [ |
| 153 | "googletest/samples/prime_tables.h", |
| 154 | "googletest/samples/sample1.h", |
| 155 | "googletest/samples/sample2.h", |
| 156 | "googletest/samples/sample3-inl.h", |
| 157 | "googletest/samples/sample4.h", |
| 158 | ], |
Pavel Samolysov | 91bfc08 | 2019-01-22 10:46:59 +0300 | [diff] [blame] | 159 | features = select({ |
| 160 | ":windows": ["windows_export_all_symbols"], |
| 161 | "//conditions:default": [], |
Yannic Bonenberger | 6fd262e | 2019-08-07 17:04:29 +0200 | [diff] [blame] | 162 | }), |
misterg | a7b21c9 | 2018-10-01 13:26:47 -0400 | [diff] [blame] | 163 | ) |
| 164 | |
| 165 | cc_test( |
| 166 | name = "gtest_samples", |
| 167 | size = "small", |
| 168 | # All Samples except: |
| 169 | # sample9 (main) |
| 170 | # sample10 (main and takes a command line option and needs to be separate) |
| 171 | srcs = [ |
| 172 | "googletest/samples/sample1_unittest.cc", |
| 173 | "googletest/samples/sample2_unittest.cc", |
| 174 | "googletest/samples/sample3_unittest.cc", |
| 175 | "googletest/samples/sample4_unittest.cc", |
| 176 | "googletest/samples/sample5_unittest.cc", |
| 177 | "googletest/samples/sample6_unittest.cc", |
| 178 | "googletest/samples/sample7_unittest.cc", |
| 179 | "googletest/samples/sample8_unittest.cc", |
| 180 | ], |
Yannic Bonenberger | 6fd262e | 2019-08-07 17:04:29 +0200 | [diff] [blame] | 181 | linkstatic = 0, |
misterg | a7b21c9 | 2018-10-01 13:26:47 -0400 | [diff] [blame] | 182 | deps = [ |
| 183 | "gtest_sample_lib", |
| 184 | ":gtest_main", |
| 185 | ], |
| 186 | ) |
| 187 | |
| 188 | cc_test( |
| 189 | name = "sample9_unittest", |
| 190 | size = "small", |
| 191 | srcs = ["googletest/samples/sample9_unittest.cc"], |
| 192 | deps = [":gtest"], |
| 193 | ) |
| 194 | |
| 195 | cc_test( |
| 196 | name = "sample10_unittest", |
| 197 | size = "small", |
| 198 | srcs = ["googletest/samples/sample10_unittest.cc"], |
krzysio | 105579a | 2018-11-06 10:37:19 -0500 | [diff] [blame] | 199 | deps = [":gtest"], |
misterg | a7b21c9 | 2018-10-01 13:26:47 -0400 | [diff] [blame] | 200 | ) |