blob: 14661b6a463bff004a6f640fbe839390080d1b12 [file] [log] [blame]
misterga7b21c92018-10-01 13:26:47 -04001# 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#
misterga7b21c92018-10-01 13:26:47 -040031# Bazel Build for Google C++ Testing Framework(Google Test)
32
Yannic Bonenberger6fd262e2019-08-07 17:04:29 +020033load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test")
34
misterga7b21c92018-10-01 13:26:47 -040035package(default_visibility = ["//visibility:public"])
36
37licenses(["notice"])
38
Rob Earhart025e1a42020-08-12 16:10:57 -070039exports_files(["LICENSE"])
40
misterga7b21c92018-10-01 13:26:47 -040041config_setting(
42 name = "windows",
Ezekiel Warren5c08f922021-03-14 18:41:28 -070043 constraint_values = ["@platforms//os:windows"],
misterga7b21c92018-10-01 13:26:47 -040044)
45
46config_setting(
Abseil Team1a8ecf12021-03-20 01:24:27 -040047 name = "msvc_compiler",
48 flag_values = {
49 "@bazel_tools//tools/cpp:compiler": "msvc-cl",
50 },
51 visibility = [":__subpackages__"],
52)
53
54config_setting(
misterga7b21c92018-10-01 13:26:47 -040055 name = "has_absl",
56 values = {"define": "absl=1"},
57)
58
Abseil Team252ce9c2021-04-26 13:09:24 -040059config_setting(
60 name = "ios",
61 values = {"apple_platform_type": "ios"},
62 visibility = [":__subpackages__"],
63)
64
krzysio105579a2018-11-06 10:37:19 -050065# 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
misterga7b21c92018-10-01 13:26:47 -040072# 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 ]),
krzysio105579a2018-11-06 10:37:19 -050094 copts = select({
Abseil Team252ce9c2021-04-26 13:09:24 -040095 ":ios": [
96 "-xobjective-c++",
97 "-pthread",
98 ],
krzysio105579a2018-11-06 10:37:19 -050099 ":windows": [],
100 "//conditions:default": ["-pthread"],
101 }),
102 defines = select({
103 ":has_absl": ["GTEST_HAS_ABSL=1"],
104 "//conditions:default": [],
105 }),
Yannic Bonenberger6fd262e2019-08-07 17:04:29 +0200106 features = select({
107 ":windows": ["windows_export_all_symbols"],
108 "//conditions:default": [],
109 }),
misterga7b21c92018-10-01 13:26:47 -0400110 includes = [
111 "googlemock",
112 "googlemock/include",
113 "googletest",
114 "googletest/include",
115 ],
116 linkopts = select({
117 ":windows": [],
krzysio105579a2018-11-06 10:37:19 -0500118 "//conditions:default": ["-pthread"],
misterga7b21c92018-10-01 13:26:47 -0400119 }),
krzysio105579a2018-11-06 10:37:19 -0500120 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 Kuzniarek843267f2020-03-07 17:03:50 +0100126 "@com_google_absl//absl/types:any",
krzysio105579a2018-11-06 10:37:19 -0500127 "@com_google_absl//absl/types:optional",
128 "@com_google_absl//absl/types:variant",
129 ],
130 "//conditions:default": [],
131 }),
misterga7b21c92018-10-01 13:26:47 -0400132)
133
134cc_library(
135 name = "gtest_main",
krzysio105579a2018-11-06 10:37:19 -0500136 srcs = ["googlemock/src/gmock_main.cc"],
Pavel Samolysovc868da12019-01-14 15:42:36 +0300137 features = select({
138 ":windows": ["windows_export_all_symbols"],
139 "//conditions:default": [],
Yannic Bonenberger6fd262e2019-08-07 17:04:29 +0200140 }),
141 deps = [":gtest"],
misterga7b21c92018-10-01 13:26:47 -0400142)
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 ],
Pavel Samolysov91bfc082019-01-22 10:46:59 +0300159 features = select({
160 ":windows": ["windows_export_all_symbols"],
161 "//conditions:default": [],
Yannic Bonenberger6fd262e2019-08-07 17:04:29 +0200162 }),
misterga7b21c92018-10-01 13:26:47 -0400163)
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 ],
Yannic Bonenberger6fd262e2019-08-07 17:04:29 +0200181 linkstatic = 0,
misterga7b21c92018-10-01 13:26:47 -0400182 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"],
krzysio105579a2018-11-06 10:37:19 -0500199 deps = [":gtest"],
misterga7b21c92018-10-01 13:26:47 -0400200)