Austin Schuh | 889ac43 | 2018-10-29 22:57:02 -0700 | [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 | # |
Austin Schuh | 889ac43 | 2018-10-29 22:57:02 -0700 | [diff] [blame] | 31 | # Bazel Build for Google C++ Testing Framework(Google Test) |
| 32 | |
James Kuszmaul | e2f1529 | 2021-05-10 22:37:32 -0700 | [diff] [blame] | 33 | load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test") |
| 34 | |
Austin Schuh | 889ac43 | 2018-10-29 22:57:02 -0700 | [diff] [blame] | 35 | package(default_visibility = ["//visibility:public"]) |
| 36 | |
| 37 | licenses(["notice"]) |
| 38 | |
James Kuszmaul | e2f1529 | 2021-05-10 22:37:32 -0700 | [diff] [blame] | 39 | exports_files(["LICENSE"]) |
| 40 | |
Austin Schuh | 889ac43 | 2018-10-29 22:57:02 -0700 | [diff] [blame] | 41 | config_setting( |
| 42 | name = "windows", |
James Kuszmaul | e2f1529 | 2021-05-10 22:37:32 -0700 | [diff] [blame] | 43 | constraint_values = ["@platforms//os:windows"], |
Austin Schuh | 889ac43 | 2018-10-29 22:57:02 -0700 | [diff] [blame] | 44 | ) |
| 45 | |
| 46 | config_setting( |
James Kuszmaul | e2f1529 | 2021-05-10 22:37:32 -0700 | [diff] [blame] | 47 | name = "msvc_compiler", |
| 48 | flag_values = { |
| 49 | "@bazel_tools//tools/cpp:compiler": "msvc-cl", |
| 50 | }, |
| 51 | visibility = [":__subpackages__"], |
Austin Schuh | 889ac43 | 2018-10-29 22:57:02 -0700 | [diff] [blame] | 52 | ) |
| 53 | |
| 54 | config_setting( |
| 55 | name = "has_absl", |
| 56 | values = {"define": "absl=1"}, |
| 57 | ) |
| 58 | |
James Kuszmaul | e2f1529 | 2021-05-10 22:37:32 -0700 | [diff] [blame] | 59 | config_setting( |
| 60 | name = "ios", |
| 61 | values = {"apple_platform_type": "ios"}, |
| 62 | visibility = [":__subpackages__"], |
| 63 | ) |
| 64 | |
| 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 | |
Austin Schuh | 889ac43 | 2018-10-29 22:57:02 -0700 | [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 | ]), |
James Kuszmaul | e2f1529 | 2021-05-10 22:37:32 -0700 | [diff] [blame] | 94 | copts = select({ |
| 95 | ":ios": [ |
| 96 | "-xobjective-c++", |
James Kuszmaul | e2f1529 | 2021-05-10 22:37:32 -0700 | [diff] [blame] | 97 | ], |
| 98 | ":windows": [], |
James Kuszmaul | f4bf9fe | 2021-05-10 22:58:24 -0700 | [diff] [blame] | 99 | "//conditions:default": [], |
James Kuszmaul | e2f1529 | 2021-05-10 22:37:32 -0700 | [diff] [blame] | 100 | }), |
| 101 | defines = select({ |
| 102 | ":has_absl": ["GTEST_HAS_ABSL=1"], |
| 103 | "//conditions:default": [], |
| 104 | }), |
| 105 | features = select({ |
| 106 | ":windows": ["windows_export_all_symbols"], |
| 107 | "//conditions:default": [], |
| 108 | }), |
Austin Schuh | 889ac43 | 2018-10-29 22:57:02 -0700 | [diff] [blame] | 109 | includes = [ |
| 110 | "googlemock", |
| 111 | "googlemock/include", |
| 112 | "googletest", |
| 113 | "googletest/include", |
| 114 | ], |
| 115 | linkopts = select({ |
| 116 | ":windows": [], |
James Kuszmaul | f4bf9fe | 2021-05-10 22:58:24 -0700 | [diff] [blame] | 117 | "//conditions:default": [], |
Austin Schuh | 889ac43 | 2018-10-29 22:57:02 -0700 | [diff] [blame] | 118 | }), |
James Kuszmaul | e2f1529 | 2021-05-10 22:37:32 -0700 | [diff] [blame] | 119 | deps = select({ |
| 120 | ":has_absl": [ |
| 121 | "@com_google_absl//absl/debugging:failure_signal_handler", |
| 122 | "@com_google_absl//absl/debugging:stacktrace", |
| 123 | "@com_google_absl//absl/debugging:symbolize", |
| 124 | "@com_google_absl//absl/strings", |
| 125 | "@com_google_absl//absl/types:any", |
| 126 | "@com_google_absl//absl/types:optional", |
| 127 | "@com_google_absl//absl/types:variant", |
| 128 | ], |
| 129 | "//conditions:default": [], |
| 130 | }), |
Austin Schuh | 889ac43 | 2018-10-29 22:57:02 -0700 | [diff] [blame] | 131 | ) |
| 132 | |
| 133 | cc_library( |
| 134 | name = "gtest_main", |
James Kuszmaul | e2f1529 | 2021-05-10 22:37:32 -0700 | [diff] [blame] | 135 | srcs = ["googlemock/src/gmock_main.cc"], |
| 136 | features = select({ |
| 137 | ":windows": ["windows_export_all_symbols"], |
| 138 | "//conditions:default": [], |
| 139 | }), |
Austin Schuh | 889ac43 | 2018-10-29 22:57:02 -0700 | [diff] [blame] | 140 | deps = [":gtest"], |
| 141 | ) |
| 142 | |
| 143 | # The following rules build samples of how to use gTest. |
| 144 | cc_library( |
| 145 | name = "gtest_sample_lib", |
| 146 | srcs = [ |
| 147 | "googletest/samples/sample1.cc", |
| 148 | "googletest/samples/sample2.cc", |
| 149 | "googletest/samples/sample4.cc", |
| 150 | ], |
| 151 | hdrs = [ |
| 152 | "googletest/samples/prime_tables.h", |
| 153 | "googletest/samples/sample1.h", |
| 154 | "googletest/samples/sample2.h", |
| 155 | "googletest/samples/sample3-inl.h", |
| 156 | "googletest/samples/sample4.h", |
| 157 | ], |
James Kuszmaul | e2f1529 | 2021-05-10 22:37:32 -0700 | [diff] [blame] | 158 | features = select({ |
| 159 | ":windows": ["windows_export_all_symbols"], |
| 160 | "//conditions:default": [], |
| 161 | }), |
Austin Schuh | 889ac43 | 2018-10-29 22:57:02 -0700 | [diff] [blame] | 162 | ) |
| 163 | |
| 164 | cc_test( |
| 165 | name = "gtest_samples", |
| 166 | size = "small", |
James Kuszmaul | e2f1529 | 2021-05-10 22:37:32 -0700 | [diff] [blame] | 167 | # All Samples except: |
| 168 | # sample9 (main) |
| 169 | # sample10 (main and takes a command line option and needs to be separate) |
Austin Schuh | 889ac43 | 2018-10-29 22:57:02 -0700 | [diff] [blame] | 170 | srcs = [ |
| 171 | "googletest/samples/sample1_unittest.cc", |
| 172 | "googletest/samples/sample2_unittest.cc", |
| 173 | "googletest/samples/sample3_unittest.cc", |
| 174 | "googletest/samples/sample4_unittest.cc", |
| 175 | "googletest/samples/sample5_unittest.cc", |
| 176 | "googletest/samples/sample6_unittest.cc", |
| 177 | "googletest/samples/sample7_unittest.cc", |
| 178 | "googletest/samples/sample8_unittest.cc", |
| 179 | ], |
James Kuszmaul | e2f1529 | 2021-05-10 22:37:32 -0700 | [diff] [blame] | 180 | linkstatic = 0, |
Austin Schuh | 889ac43 | 2018-10-29 22:57:02 -0700 | [diff] [blame] | 181 | deps = [ |
| 182 | "gtest_sample_lib", |
| 183 | ":gtest_main", |
| 184 | ], |
| 185 | ) |
| 186 | |
| 187 | cc_test( |
| 188 | name = "sample9_unittest", |
| 189 | size = "small", |
| 190 | srcs = ["googletest/samples/sample9_unittest.cc"], |
| 191 | deps = [":gtest"], |
| 192 | ) |
| 193 | |
| 194 | cc_test( |
| 195 | name = "sample10_unittest", |
| 196 | size = "small", |
| 197 | srcs = ["googletest/samples/sample10_unittest.cc"], |
James Kuszmaul | e2f1529 | 2021-05-10 22:37:32 -0700 | [diff] [blame] | 198 | deps = [":gtest"], |
Austin Schuh | 889ac43 | 2018-10-29 22:57:02 -0700 | [diff] [blame] | 199 | ) |