xref: /freebsd/contrib/googletest/BUILD.bazel (revision d0b2dbfa0ecf2bbc9709efc5e20baf8e4b44bbbf)
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
33package(default_visibility = ["//visibility:public"])
34
35licenses(["notice"])
36
37exports_files(["LICENSE"])
38
39config_setting(
40    name = "qnx",
41    constraint_values = ["@platforms//os:qnx"],
42)
43
44config_setting(
45    name = "windows",
46    constraint_values = ["@platforms//os:windows"],
47)
48
49config_setting(
50    name = "freebsd",
51    constraint_values = ["@platforms//os:freebsd"],
52)
53
54config_setting(
55    name = "openbsd",
56    constraint_values = ["@platforms//os:openbsd"],
57)
58
59config_setting(
60    name = "msvc_compiler",
61    flag_values = {
62        "@bazel_tools//tools/cpp:compiler": "msvc-cl",
63    },
64    visibility = [":__subpackages__"],
65)
66
67config_setting(
68    name = "has_absl",
69    values = {"define": "absl=1"},
70)
71
72# Library that defines the FRIEND_TEST macro.
73cc_library(
74    name = "gtest_prod",
75    hdrs = ["googletest/include/gtest/gtest_prod.h"],
76    includes = ["googletest/include"],
77)
78
79# Google Test including Google Mock
80cc_library(
81    name = "gtest",
82    srcs = glob(
83        include = [
84            "googletest/src/*.cc",
85            "googletest/src/*.h",
86            "googletest/include/gtest/**/*.h",
87            "googlemock/src/*.cc",
88            "googlemock/include/gmock/**/*.h",
89        ],
90        exclude = [
91            "googletest/src/gtest-all.cc",
92            "googletest/src/gtest_main.cc",
93            "googlemock/src/gmock-all.cc",
94            "googlemock/src/gmock_main.cc",
95        ],
96    ),
97    hdrs = glob([
98        "googletest/include/gtest/*.h",
99        "googlemock/include/gmock/*.h",
100    ]),
101    copts = select({
102        ":qnx": [],
103        ":windows": [],
104        "//conditions:default": ["-pthread"],
105    }),
106    defines = select({
107        ":has_absl": ["GTEST_HAS_ABSL=1"],
108        "//conditions:default": [],
109    }),
110    features = select({
111        ":windows": ["windows_export_all_symbols"],
112        "//conditions:default": [],
113    }),
114    includes = [
115        "googlemock",
116        "googlemock/include",
117        "googletest",
118        "googletest/include",
119    ],
120    linkopts = select({
121        ":qnx": ["-lregex"],
122        ":windows": [],
123        ":freebsd": [
124            "-lm",
125            "-pthread",
126        ],
127        ":openbsd": [
128            "-lm",
129            "-pthread",
130        ],
131        "//conditions:default": ["-pthread"],
132    }),
133    deps = select({
134        ":has_absl": [
135            "@com_google_absl//absl/container:flat_hash_set",
136            "@com_google_absl//absl/debugging:failure_signal_handler",
137            "@com_google_absl//absl/debugging:stacktrace",
138            "@com_google_absl//absl/debugging:symbolize",
139            "@com_google_absl//absl/flags:flag",
140            "@com_google_absl//absl/flags:parse",
141            "@com_google_absl//absl/flags:reflection",
142            "@com_google_absl//absl/flags:usage",
143            "@com_google_absl//absl/strings",
144            "@com_google_absl//absl/types:any",
145            "@com_google_absl//absl/types:optional",
146            "@com_google_absl//absl/types:variant",
147            "@com_googlesource_code_re2//:re2",
148        ],
149        "//conditions:default": [],
150    }),
151)
152
153cc_library(
154    name = "gtest_main",
155    srcs = ["googlemock/src/gmock_main.cc"],
156    features = select({
157        ":windows": ["windows_export_all_symbols"],
158        "//conditions:default": [],
159    }),
160    deps = [":gtest"],
161)
162
163# The following rules build samples of how to use gTest.
164cc_library(
165    name = "gtest_sample_lib",
166    srcs = [
167        "googletest/samples/sample1.cc",
168        "googletest/samples/sample2.cc",
169        "googletest/samples/sample4.cc",
170    ],
171    hdrs = [
172        "googletest/samples/prime_tables.h",
173        "googletest/samples/sample1.h",
174        "googletest/samples/sample2.h",
175        "googletest/samples/sample3-inl.h",
176        "googletest/samples/sample4.h",
177    ],
178    features = select({
179        ":windows": ["windows_export_all_symbols"],
180        "//conditions:default": [],
181    }),
182)
183
184cc_test(
185    name = "gtest_samples",
186    size = "small",
187    # All Samples except:
188    #   sample9 (main)
189    #   sample10 (main and takes a command line option and needs to be separate)
190    srcs = [
191        "googletest/samples/sample1_unittest.cc",
192        "googletest/samples/sample2_unittest.cc",
193        "googletest/samples/sample3_unittest.cc",
194        "googletest/samples/sample4_unittest.cc",
195        "googletest/samples/sample5_unittest.cc",
196        "googletest/samples/sample6_unittest.cc",
197        "googletest/samples/sample7_unittest.cc",
198        "googletest/samples/sample8_unittest.cc",
199    ],
200    linkstatic = 0,
201    deps = [
202        "gtest_sample_lib",
203        ":gtest_main",
204    ],
205)
206
207cc_test(
208    name = "sample9_unittest",
209    size = "small",
210    srcs = ["googletest/samples/sample9_unittest.cc"],
211    deps = [":gtest"],
212)
213
214cc_test(
215    name = "sample10_unittest",
216    size = "small",
217    srcs = ["googletest/samples/sample10_unittest.cc"],
218    deps = [":gtest"],
219)
220