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 33load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test") 34 35package(default_visibility = ["//visibility:public"]) 36 37licenses(["notice"]) 38 39exports_files(["LICENSE"]) 40 41config_setting( 42 name = "windows", 43 constraint_values = ["@platforms//os:windows"], 44) 45 46config_setting( 47 name = "msvc_compiler", 48 flag_values = { 49 "@bazel_tools//tools/cpp:compiler": "msvc-cl", 50 }, 51 visibility = [":__subpackages__"], 52) 53 54config_setting( 55 name = "has_absl", 56 values = {"define": "absl=1"}, 57) 58 59config_setting( 60 name = "ios", 61 values = {"apple_platform_type": "ios"}, 62 visibility = [":__subpackages__"], 63) 64 65# Library that defines the FRIEND_TEST macro. 66cc_library( 67 name = "gtest_prod", 68 hdrs = ["googletest/include/gtest/gtest_prod.h"], 69 includes = ["googletest/include"], 70) 71 72# Google Test including Google Mock 73cc_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 ]), 94 copts = select({ 95 ":ios": [ 96 "-xobjective-c++", 97 "-pthread", 98 ], 99 ":windows": [], 100 "//conditions:default": ["-pthread"], 101 }), 102 defines = select({ 103 ":has_absl": ["GTEST_HAS_ABSL=1"], 104 "//conditions:default": [], 105 }), 106 features = select({ 107 ":windows": ["windows_export_all_symbols"], 108 "//conditions:default": [], 109 }), 110 includes = [ 111 "googlemock", 112 "googlemock/include", 113 "googletest", 114 "googletest/include", 115 ], 116 linkopts = select({ 117 ":windows": [], 118 "//conditions:default": ["-pthread"], 119 }), 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", 126 "@com_google_absl//absl/types:any", 127 "@com_google_absl//absl/types:optional", 128 "@com_google_absl//absl/types:variant", 129 ], 130 "//conditions:default": [], 131 }), 132) 133 134cc_library( 135 name = "gtest_main", 136 srcs = ["googlemock/src/gmock_main.cc"], 137 features = select({ 138 ":windows": ["windows_export_all_symbols"], 139 "//conditions:default": [], 140 }), 141 deps = [":gtest"], 142) 143 144# The following rules build samples of how to use gTest. 145cc_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 ], 159 features = select({ 160 ":windows": ["windows_export_all_symbols"], 161 "//conditions:default": [], 162 }), 163) 164 165cc_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 ], 181 linkstatic = 0, 182 deps = [ 183 "gtest_sample_lib", 184 ":gtest_main", 185 ], 186) 187 188cc_test( 189 name = "sample9_unittest", 190 size = "small", 191 srcs = ["googletest/samples/sample9_unittest.cc"], 192 deps = [":gtest"], 193) 194 195cc_test( 196 name = "sample10_unittest", 197 size = "small", 198 srcs = ["googletest/samples/sample10_unittest.cc"], 199 deps = [":gtest"], 200) 201