Remove make_build macro
[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 load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test")
34
35 package(default_visibility = ["//visibility:public"])
36
37 licenses(["notice"])
38
39 config_setting(
40     name = "windows",
41     constraint_values = ["@bazel_tools//platforms:windows"],
42 )
43
44 config_setting(
45     name = "has_absl",
46     values = {"define": "absl=1"},
47 )
48
49 # Library that defines the FRIEND_TEST macro.
50 cc_library(
51     name = "gtest_prod",
52     hdrs = ["googletest/include/gtest/gtest_prod.h"],
53     includes = ["googletest/include"],
54 )
55
56 # Google Test including Google Mock
57 cc_library(
58     name = "gtest",
59     srcs = glob(
60         include = [
61             "googletest/src/*.cc",
62             "googletest/src/*.h",
63             "googletest/include/gtest/**/*.h",
64             "googlemock/src/*.cc",
65             "googlemock/include/gmock/**/*.h",
66         ],
67         exclude = [
68             "googletest/src/gtest-all.cc",
69             "googletest/src/gtest_main.cc",
70             "googlemock/src/gmock-all.cc",
71             "googlemock/src/gmock_main.cc",
72         ],
73     ),
74     hdrs = glob([
75         "googletest/include/gtest/*.h",
76         "googlemock/include/gmock/*.h",
77     ]),
78     copts = select({
79         ":windows": [],
80         "//conditions:default": ["-pthread"],
81     }),
82     defines = select({
83         ":has_absl": ["GTEST_HAS_ABSL=1"],
84         "//conditions:default": [],
85     }),
86     features = select({
87         ":windows": ["windows_export_all_symbols"],
88         "//conditions:default": [],
89     }),
90     includes = [
91         "googlemock",
92         "googlemock/include",
93         "googletest",
94         "googletest/include",
95     ],
96     linkopts = select({
97         ":windows": [],
98         "//conditions:default": ["-pthread"],
99     }),
100     deps = select({
101         ":has_absl": [
102             "@com_google_absl//absl/debugging:failure_signal_handler",
103             "@com_google_absl//absl/debugging:stacktrace",
104             "@com_google_absl//absl/debugging:symbolize",
105             "@com_google_absl//absl/strings",
106             "@com_google_absl//absl/types:optional",
107             "@com_google_absl//absl/types:variant",
108         ],
109         "//conditions:default": [],
110     }),
111 )
112
113 cc_library(
114     name = "gtest_main",
115     srcs = ["googlemock/src/gmock_main.cc"],
116     features = select({
117         ":windows": ["windows_export_all_symbols"],
118         "//conditions:default": [],
119     }),
120     deps = [":gtest"],
121 )
122
123 # The following rules build samples of how to use gTest.
124 cc_library(
125     name = "gtest_sample_lib",
126     srcs = [
127         "googletest/samples/sample1.cc",
128         "googletest/samples/sample2.cc",
129         "googletest/samples/sample4.cc",
130     ],
131     hdrs = [
132         "googletest/samples/prime_tables.h",
133         "googletest/samples/sample1.h",
134         "googletest/samples/sample2.h",
135         "googletest/samples/sample3-inl.h",
136         "googletest/samples/sample4.h",
137     ],
138     features = select({
139         ":windows": ["windows_export_all_symbols"],
140         "//conditions:default": [],
141     }),
142 )
143
144 cc_test(
145     name = "gtest_samples",
146     size = "small",
147     # All Samples except:
148     #   sample9 (main)
149     #   sample10 (main and takes a command line option and needs to be separate)
150     srcs = [
151         "googletest/samples/sample1_unittest.cc",
152         "googletest/samples/sample2_unittest.cc",
153         "googletest/samples/sample3_unittest.cc",
154         "googletest/samples/sample4_unittest.cc",
155         "googletest/samples/sample5_unittest.cc",
156         "googletest/samples/sample6_unittest.cc",
157         "googletest/samples/sample7_unittest.cc",
158         "googletest/samples/sample8_unittest.cc",
159     ],
160     linkstatic = 0,
161     deps = [
162         "gtest_sample_lib",
163         ":gtest_main",
164     ],
165 )
166
167 cc_test(
168     name = "sample9_unittest",
169     size = "small",
170     srcs = ["googletest/samples/sample9_unittest.cc"],
171     deps = [":gtest"],
172 )
173
174 cc_test(
175     name = "sample10_unittest",
176     size = "small",
177     srcs = ["googletest/samples/sample10_unittest.cc"],
178     deps = [":gtest"],
179 )