blob: ccc2435619ef1a3354579d07f644833c7bbdee55 [file] [log] [blame]
Austin Schuh889ac432018-10-29 22:57:02 -07001# 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 Schuh889ac432018-10-29 22:57:02 -070031# Bazel Build for Google C++ Testing Framework(Google Test)
32
James Kuszmaule2f15292021-05-10 22:37:32 -070033load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test")
34
Austin Schuh889ac432018-10-29 22:57:02 -070035package(default_visibility = ["//visibility:public"])
36
37licenses(["notice"])
38
James Kuszmaule2f15292021-05-10 22:37:32 -070039exports_files(["LICENSE"])
40
Austin Schuh889ac432018-10-29 22:57:02 -070041config_setting(
42 name = "windows",
James Kuszmaule2f15292021-05-10 22:37:32 -070043 constraint_values = ["@platforms//os:windows"],
Austin Schuh889ac432018-10-29 22:57:02 -070044)
45
46config_setting(
James Kuszmaule2f15292021-05-10 22:37:32 -070047 name = "msvc_compiler",
48 flag_values = {
49 "@bazel_tools//tools/cpp:compiler": "msvc-cl",
50 },
51 visibility = [":__subpackages__"],
Austin Schuh889ac432018-10-29 22:57:02 -070052)
53
54config_setting(
55 name = "has_absl",
56 values = {"define": "absl=1"},
57)
58
James Kuszmaule2f15292021-05-10 22:37:32 -070059config_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
Austin Schuh889ac432018-10-29 22:57:02 -070072# 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 ]),
James Kuszmaule2f15292021-05-10 22:37:32 -070094 copts = select({
95 ":ios": [
96 "-xobjective-c++",
James Kuszmaule2f15292021-05-10 22:37:32 -070097 ],
98 ":windows": [],
James Kuszmaulf4bf9fe2021-05-10 22:58:24 -070099 "//conditions:default": [],
James Kuszmaule2f15292021-05-10 22:37:32 -0700100 }),
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 Schuh889ac432018-10-29 22:57:02 -0700109 includes = [
110 "googlemock",
111 "googlemock/include",
112 "googletest",
113 "googletest/include",
114 ],
115 linkopts = select({
116 ":windows": [],
James Kuszmaulf4bf9fe2021-05-10 22:58:24 -0700117 "//conditions:default": [],
Austin Schuh889ac432018-10-29 22:57:02 -0700118 }),
James Kuszmaule2f15292021-05-10 22:37:32 -0700119 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 Schuh889ac432018-10-29 22:57:02 -0700131)
132
133cc_library(
134 name = "gtest_main",
James Kuszmaule2f15292021-05-10 22:37:32 -0700135 srcs = ["googlemock/src/gmock_main.cc"],
136 features = select({
137 ":windows": ["windows_export_all_symbols"],
138 "//conditions:default": [],
139 }),
Austin Schuh889ac432018-10-29 22:57:02 -0700140 deps = [":gtest"],
141)
142
143# The following rules build samples of how to use gTest.
144cc_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 Kuszmaule2f15292021-05-10 22:37:32 -0700158 features = select({
159 ":windows": ["windows_export_all_symbols"],
160 "//conditions:default": [],
161 }),
Austin Schuh889ac432018-10-29 22:57:02 -0700162)
163
164cc_test(
165 name = "gtest_samples",
166 size = "small",
James Kuszmaule2f15292021-05-10 22:37:32 -0700167 # All Samples except:
168 # sample9 (main)
169 # sample10 (main and takes a command line option and needs to be separate)
Austin Schuh889ac432018-10-29 22:57:02 -0700170 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 Kuszmaule2f15292021-05-10 22:37:32 -0700180 linkstatic = 0,
Austin Schuh889ac432018-10-29 22:57:02 -0700181 deps = [
182 "gtest_sample_lib",
183 ":gtest_main",
184 ],
185)
186
187cc_test(
188 name = "sample9_unittest",
189 size = "small",
190 srcs = ["googletest/samples/sample9_unittest.cc"],
191 deps = [":gtest"],
192)
193
194cc_test(
195 name = "sample10_unittest",
196 size = "small",
197 srcs = ["googletest/samples/sample10_unittest.cc"],
James Kuszmaule2f15292021-05-10 22:37:32 -0700198 deps = [":gtest"],
Austin Schuh889ac432018-10-29 22:57:02 -0700199)