blob: f6dccd3802ad4b36df9a9c61a43afbb5471c24a6 [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",
Derek Mauro6c7878a2018-07-12 13:46:50 -040041 values = {"cpu": "x64_windows"},
Loo Rong Jiecbd15d42018-01-07 22:52:52 +080042)
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
Zhongming Qu95386872017-07-04 17:50:00 -040054# Google Test including Google Mock
mistergf63e2a12017-08-01 14:36:29 -040055cc_library(
56 name = "gtest",
57 srcs = glob(
58 include = [
59 "googletest/src/*.cc",
60 "googletest/src/*.h",
61 "googletest/include/gtest/**/*.h",
mistergac885f32017-08-09 11:47:54 -040062 "googlemock/src/*.cc",
63 "googlemock/include/gmock/**/*.h",
mistergf63e2a12017-08-01 14:36:29 -040064 ],
65 exclude = [
66 "googletest/src/gtest-all.cc",
67 "googletest/src/gtest_main.cc",
mistergac885f32017-08-09 11:47:54 -040068 "googlemock/src/gmock-all.cc",
misterg66a03692017-08-09 14:37:58 -040069 "googlemock/src/gmock_main.cc",
mistergf63e2a12017-08-01 14:36:29 -040070 ],
71 ),
Derek Mauro6c7878a2018-07-12 13:46:50 -040072 hdrs = glob([
misterg66a03692017-08-09 14:37:58 -040073 "googletest/include/gtest/*.h",
74 "googlemock/include/gmock/*.h",
75 ]),
mistergf63e2a12017-08-01 14:36:29 -040076 copts = select(
77 {
Loo Rong Jiecbd15d42018-01-07 22:52:52 +080078 ":windows": [],
79 ":windows_msvc": [],
mistergf63e2a12017-08-01 14:36:29 -040080 "//conditions:default": ["-pthread"],
81 },
82 ),
Derek Mauro6c7878a2018-07-12 13:46:50 -040083 defines = select(
84 {
85 ":has_absl": [
86 "GTEST_HAS_ABSL=1",
87 ],
88 "//conditions:default": [],
89 },
90 ),
mistergf63e2a12017-08-01 14:36:29 -040091 includes = [
mistergac885f32017-08-09 11:47:54 -040092 "googlemock",
93 "googlemock/include",
misterg88150872017-08-08 15:17:56 -040094 "googletest",
95 "googletest/include",
96 ],
97 linkopts = select({
Loo Rong Jiecbd15d42018-01-07 22:52:52 +080098 ":windows": [],
99 ":windows_msvc": [],
misterg88150872017-08-08 15:17:56 -0400100 "//conditions:default": [
101 "-pthread",
102 ],
103 }),
Derek Mauro6c7878a2018-07-12 13:46:50 -0400104 deps = select(
105 {
106 ":has_absl": [
107 "@com_google_absl//absl/types:optional",
108 "@com_google_absl//absl/types:variant",
109 "@com_google_absl//absl/strings",
110 ],
111 "//conditions:default": [],
112 },
Gennadiy Civil2a468302018-01-30 11:42:03 -0500113 ),
misterg88150872017-08-08 15:17:56 -0400114)
115
mistergf63e2a12017-08-01 14:36:29 -0400116cc_library(
117 name = "gtest_main",
mistergac885f32017-08-09 11:47:54 -0400118 srcs = [
mistergc3f65332017-08-10 15:33:09 -0400119 "googlemock/src/gmock_main.cc",
mistergf63e2a12017-08-01 14:36:29 -0400120 ],
Zhongming Qu99d0ef32017-08-18 03:59:05 -0700121 deps = [":gtest"],
mistergf63e2a12017-08-01 14:36:29 -0400122)
123
misterg6615f7d2017-08-02 14:36:39 -0400124# The following rules build samples of how to use gTest.
mistergf63e2a12017-08-01 14:36:29 -0400125cc_library(
mistergb3edada2017-08-01 14:50:59 -0400126 name = "gtest_sample_lib",
mistergf63e2a12017-08-01 14:36:29 -0400127 srcs = [
128 "googletest/samples/sample1.cc",
129 "googletest/samples/sample2.cc",
130 "googletest/samples/sample4.cc",
131 ],
132 hdrs = [
133 "googletest/samples/prime_tables.h",
134 "googletest/samples/sample1.h",
135 "googletest/samples/sample2.h",
136 "googletest/samples/sample3-inl.h",
137 "googletest/samples/sample4.h",
138 ],
mistergf63e2a12017-08-01 14:36:29 -0400139)
140
141cc_test(
mistergb3edada2017-08-01 14:50:59 -0400142 name = "gtest_samples",
mistergf63e2a12017-08-01 14:36:29 -0400143 size = "small",
misterg88150872017-08-08 15:17:56 -0400144 #All Samples except:
145 #sample9 ( main )
146 #sample10 (main and takes a command line option and needs to be separate)
147 srcs = [
148 "googletest/samples/sample1_unittest.cc",
149 "googletest/samples/sample2_unittest.cc",
150 "googletest/samples/sample3_unittest.cc",
151 "googletest/samples/sample4_unittest.cc",
152 "googletest/samples/sample5_unittest.cc",
153 "googletest/samples/sample6_unittest.cc",
154 "googletest/samples/sample7_unittest.cc",
155 "googletest/samples/sample8_unittest.cc",
156 ],
mistergf63e2a12017-08-01 14:36:29 -0400157 deps = [
mistergaa31cb62017-08-02 15:40:14 -0400158 "gtest_sample_lib",
mistergb3edada2017-08-01 14:50:59 -0400159 ":gtest_main",
mistergf63e2a12017-08-01 14:36:29 -0400160 ],
161)
162
163cc_test(
mistergaa31cb62017-08-02 15:40:14 -0400164 name = "sample9_unittest",
mistergf63e2a12017-08-01 14:36:29 -0400165 size = "small",
mistergaa31cb62017-08-02 15:40:14 -0400166 srcs = ["googletest/samples/sample9_unittest.cc"],
misterg88150872017-08-08 15:17:56 -0400167 deps = [":gtest"],
mistergaa31cb62017-08-02 15:40:14 -0400168)
169
170cc_test(
171 name = "sample10_unittest",
172 size = "small",
173 srcs = ["googletest/samples/sample10_unittest.cc"],
mistergf63e2a12017-08-01 14:36:29 -0400174 deps = [
misterg88150872017-08-08 15:17:56 -0400175 ":gtest",
mistergf63e2a12017-08-01 14:36:29 -0400176 ],
mistergb98e30b2017-08-10 11:54:46 -0400177)