Bump to 1.12.1
[platform/upstream/gtest.git] / BUILD.bazel
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
33 package(default_visibility = ["//visibility:public"])
34
35 licenses(["notice"])
36
37 exports_files(["LICENSE"])
38
39 config_setting(
40     name = "qnx",
41     constraint_values = ["@platforms//os:qnx"],
42 )
43
44 config_setting(
45     name = "windows",
46     constraint_values = ["@platforms//os:windows"],
47 )
48
49 config_setting(
50     name = "freebsd",
51     constraint_values = ["@platforms//os:freebsd"],
52 )
53
54 config_setting(
55     name = "openbsd",
56     constraint_values = ["@platforms//os:openbsd"],
57 )
58
59 config_setting(
60     name = "msvc_compiler",
61     flag_values = {
62         "@bazel_tools//tools/cpp:compiler": "msvc-cl",
63     },
64     visibility = [":__subpackages__"],
65 )
66
67 config_setting(
68     name = "has_absl",
69     values = {"define": "absl=1"},
70 )
71
72 # Library that defines the FRIEND_TEST macro.
73 cc_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
80 cc_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/debugging:failure_signal_handler",
136             "@com_google_absl//absl/debugging:stacktrace",
137             "@com_google_absl//absl/debugging:symbolize",
138             "@com_google_absl//absl/flags:flag",
139             "@com_google_absl//absl/flags:parse",
140             "@com_google_absl//absl/flags:reflection",
141             "@com_google_absl//absl/flags:usage",
142             "@com_google_absl//absl/strings",
143             "@com_google_absl//absl/types:any",
144             "@com_google_absl//absl/types:optional",
145             "@com_google_absl//absl/types:variant",
146             "@com_googlesource_code_re2//:re2",
147         ],
148         "//conditions:default": [],
149     }),
150 )
151
152 cc_library(
153     name = "gtest_main",
154     srcs = ["googlemock/src/gmock_main.cc"],
155     features = select({
156         ":windows": ["windows_export_all_symbols"],
157         "//conditions:default": [],
158     }),
159     deps = [":gtest"],
160 )
161
162 # The following rules build samples of how to use gTest.
163 cc_library(
164     name = "gtest_sample_lib",
165     srcs = [
166         "googletest/samples/sample1.cc",
167         "googletest/samples/sample2.cc",
168         "googletest/samples/sample4.cc",
169     ],
170     hdrs = [
171         "googletest/samples/prime_tables.h",
172         "googletest/samples/sample1.h",
173         "googletest/samples/sample2.h",
174         "googletest/samples/sample3-inl.h",
175         "googletest/samples/sample4.h",
176     ],
177     features = select({
178         ":windows": ["windows_export_all_symbols"],
179         "//conditions:default": [],
180     }),
181 )
182
183 cc_test(
184     name = "gtest_samples",
185     size = "small",
186     # All Samples except:
187     #   sample9 (main)
188     #   sample10 (main and takes a command line option and needs to be separate)
189     srcs = [
190         "googletest/samples/sample1_unittest.cc",
191         "googletest/samples/sample2_unittest.cc",
192         "googletest/samples/sample3_unittest.cc",
193         "googletest/samples/sample4_unittest.cc",
194         "googletest/samples/sample5_unittest.cc",
195         "googletest/samples/sample6_unittest.cc",
196         "googletest/samples/sample7_unittest.cc",
197         "googletest/samples/sample8_unittest.cc",
198     ],
199     linkstatic = 0,
200     deps = [
201         "gtest_sample_lib",
202         ":gtest_main",
203     ],
204 )
205
206 cc_test(
207     name = "sample9_unittest",
208     size = "small",
209     srcs = ["googletest/samples/sample9_unittest.cc"],
210     deps = [":gtest"],
211 )
212
213 cc_test(
214     name = "sample10_unittest",
215     size = "small",
216     srcs = ["googletest/samples/sample10_unittest.cc"],
217     deps = [":gtest"],
218 )