blob: 91dd3b7437df2a36aa50781c174e77cfcb93a37d [file] [log] [blame]
Zhongming Qu95386872017-07-04 17:50:00 -04001# Copyright 2017 Google Inc.
mistergcb5b0542017-08-10 12:03:27 -04002# 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#
misterg88150872017-08-08 15:17:56 -040031# Author: misterg@google.com (Gennadiy Civil)
32#
mistergcb5b0542017-08-10 12:03:27 -040033# Bazel Build for Google C++ Testing Framework(Google Test)
34
mistergf63e2a12017-08-01 14:36:29 -040035package(default_visibility = ["//visibility:public"])
36
37licenses(["notice"])
38
misterg88150872017-08-08 15:17:56 -040039config_setting(
Loo Rong Jiecbd15d42018-01-07 22:52:52 +080040 name = "windows",
41 values = { "cpu": "x64_windows" },
42)
43
44config_setting(
45 name = "windows_msvc",
misterg88150872017-08-08 15:17:56 -040046 values = {"cpu": "x64_windows_msvc"},
47)
48
Gennadiy Civil2a468302018-01-30 11:42:03 -050049config_setting(
50 name = "has_absl",
51 values = {"define": "absl=1"},
52)
53
54
Zhongming Qu95386872017-07-04 17:50:00 -040055# Google Test including Google Mock
mistergf63e2a12017-08-01 14:36:29 -040056cc_library(
57 name = "gtest",
58 srcs = glob(
59 include = [
60 "googletest/src/*.cc",
61 "googletest/src/*.h",
62 "googletest/include/gtest/**/*.h",
mistergac885f32017-08-09 11:47:54 -040063 "googlemock/src/*.cc",
64 "googlemock/include/gmock/**/*.h",
mistergf63e2a12017-08-01 14:36:29 -040065 ],
66 exclude = [
67 "googletest/src/gtest-all.cc",
68 "googletest/src/gtest_main.cc",
mistergac885f32017-08-09 11:47:54 -040069 "googlemock/src/gmock-all.cc",
misterg66a03692017-08-09 14:37:58 -040070 "googlemock/src/gmock_main.cc",
mistergf63e2a12017-08-01 14:36:29 -040071 ],
72 ),
misterg66a03692017-08-09 14:37:58 -040073 hdrs =glob([
74 "googletest/include/gtest/*.h",
75 "googlemock/include/gmock/*.h",
76 ]),
mistergf63e2a12017-08-01 14:36:29 -040077 copts = select(
78 {
Loo Rong Jiecbd15d42018-01-07 22:52:52 +080079 ":windows": [],
80 ":windows_msvc": [],
mistergf63e2a12017-08-01 14:36:29 -040081 "//conditions:default": ["-pthread"],
82 },
83 ),
84 includes = [
mistergac885f32017-08-09 11:47:54 -040085 "googlemock",
86 "googlemock/include",
misterg88150872017-08-08 15:17:56 -040087 "googletest",
88 "googletest/include",
89 ],
90 linkopts = select({
Loo Rong Jiecbd15d42018-01-07 22:52:52 +080091 ":windows": [],
92 ":windows_msvc": [],
misterg88150872017-08-08 15:17:56 -040093 "//conditions:default": [
94 "-pthread",
95 ],
96 }),
Gennadiy Civil2a468302018-01-30 11:42:03 -050097 defines = select ({
98 ":has_absl": [
99 "GTEST_HAS_ABSL=1",
100 ],
101 "//conditions:default": [],
102 }
103 ),
104 deps = select ({
105 ":has_absl": [
106 "@com_google_absl//absl/types:optional",
107 ],
108 "//conditions:default": [],
109 }
110 )
misterg88150872017-08-08 15:17:56 -0400111)
112
mistergf63e2a12017-08-01 14:36:29 -0400113cc_library(
114 name = "gtest_main",
mistergac885f32017-08-09 11:47:54 -0400115 srcs = [
mistergc3f65332017-08-10 15:33:09 -0400116 "googlemock/src/gmock_main.cc",
mistergf63e2a12017-08-01 14:36:29 -0400117 ],
Zhongming Qu99d0ef32017-08-18 03:59:05 -0700118 deps = [":gtest"],
mistergf63e2a12017-08-01 14:36:29 -0400119)
120
misterg6615f7d2017-08-02 14:36:39 -0400121# The following rules build samples of how to use gTest.
mistergf63e2a12017-08-01 14:36:29 -0400122cc_library(
mistergb3edada2017-08-01 14:50:59 -0400123 name = "gtest_sample_lib",
mistergf63e2a12017-08-01 14:36:29 -0400124 srcs = [
125 "googletest/samples/sample1.cc",
126 "googletest/samples/sample2.cc",
127 "googletest/samples/sample4.cc",
128 ],
129 hdrs = [
130 "googletest/samples/prime_tables.h",
131 "googletest/samples/sample1.h",
132 "googletest/samples/sample2.h",
133 "googletest/samples/sample3-inl.h",
134 "googletest/samples/sample4.h",
135 ],
mistergf63e2a12017-08-01 14:36:29 -0400136)
137
138cc_test(
mistergb3edada2017-08-01 14:50:59 -0400139 name = "gtest_samples",
mistergf63e2a12017-08-01 14:36:29 -0400140 size = "small",
misterg88150872017-08-08 15:17:56 -0400141 #All Samples except:
142 #sample9 ( main )
143 #sample10 (main and takes a command line option and needs to be separate)
144 srcs = [
145 "googletest/samples/sample1_unittest.cc",
146 "googletest/samples/sample2_unittest.cc",
147 "googletest/samples/sample3_unittest.cc",
148 "googletest/samples/sample4_unittest.cc",
149 "googletest/samples/sample5_unittest.cc",
150 "googletest/samples/sample6_unittest.cc",
151 "googletest/samples/sample7_unittest.cc",
152 "googletest/samples/sample8_unittest.cc",
153 ],
mistergf63e2a12017-08-01 14:36:29 -0400154 deps = [
mistergaa31cb62017-08-02 15:40:14 -0400155 "gtest_sample_lib",
mistergb3edada2017-08-01 14:50:59 -0400156 ":gtest_main",
mistergf63e2a12017-08-01 14:36:29 -0400157 ],
158)
159
160cc_test(
mistergaa31cb62017-08-02 15:40:14 -0400161 name = "sample9_unittest",
mistergf63e2a12017-08-01 14:36:29 -0400162 size = "small",
mistergaa31cb62017-08-02 15:40:14 -0400163 srcs = ["googletest/samples/sample9_unittest.cc"],
misterg88150872017-08-08 15:17:56 -0400164 deps = [":gtest"],
mistergaa31cb62017-08-02 15:40:14 -0400165)
166
167cc_test(
168 name = "sample10_unittest",
169 size = "small",
170 srcs = ["googletest/samples/sample10_unittest.cc"],
mistergf63e2a12017-08-01 14:36:29 -0400171 deps = [
misterg88150872017-08-08 15:17:56 -0400172 ":gtest",
mistergf63e2a12017-08-01 14:36:29 -0400173 ],
mistergb98e30b2017-08-10 11:54:46 -0400174)