blob: 7d2e9d2b30401b546bffec74d584fff91b451eb3 [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
Zhongming Qu95386872017-07-04 17:50:00 -040049# Google Test including Google Mock
mistergf63e2a12017-08-01 14:36:29 -040050cc_library(
51 name = "gtest",
52 srcs = glob(
53 include = [
54 "googletest/src/*.cc",
55 "googletest/src/*.h",
56 "googletest/include/gtest/**/*.h",
mistergac885f32017-08-09 11:47:54 -040057 "googlemock/src/*.cc",
58 "googlemock/include/gmock/**/*.h",
mistergf63e2a12017-08-01 14:36:29 -040059 ],
60 exclude = [
61 "googletest/src/gtest-all.cc",
62 "googletest/src/gtest_main.cc",
mistergac885f32017-08-09 11:47:54 -040063 "googlemock/src/gmock-all.cc",
misterg66a03692017-08-09 14:37:58 -040064 "googlemock/src/gmock_main.cc",
mistergf63e2a12017-08-01 14:36:29 -040065 ],
66 ),
misterg66a03692017-08-09 14:37:58 -040067 hdrs =glob([
68 "googletest/include/gtest/*.h",
69 "googlemock/include/gmock/*.h",
70 ]),
mistergf63e2a12017-08-01 14:36:29 -040071 copts = select(
72 {
Loo Rong Jiecbd15d42018-01-07 22:52:52 +080073 ":windows": [],
74 ":windows_msvc": [],
mistergf63e2a12017-08-01 14:36:29 -040075 "//conditions:default": ["-pthread"],
76 },
77 ),
78 includes = [
mistergac885f32017-08-09 11:47:54 -040079 "googlemock",
80 "googlemock/include",
misterg88150872017-08-08 15:17:56 -040081 "googletest",
82 "googletest/include",
83 ],
84 linkopts = select({
Loo Rong Jiecbd15d42018-01-07 22:52:52 +080085 ":windows": [],
86 ":windows_msvc": [],
misterg88150872017-08-08 15:17:56 -040087 "//conditions:default": [
88 "-pthread",
89 ],
90 }),
91)
92
mistergf63e2a12017-08-01 14:36:29 -040093cc_library(
94 name = "gtest_main",
mistergac885f32017-08-09 11:47:54 -040095 srcs = [
mistergc3f65332017-08-10 15:33:09 -040096 "googlemock/src/gmock_main.cc",
mistergf63e2a12017-08-01 14:36:29 -040097 ],
Zhongming Qu99d0ef32017-08-18 03:59:05 -070098 deps = [":gtest"],
mistergf63e2a12017-08-01 14:36:29 -040099)
100
misterg6615f7d2017-08-02 14:36:39 -0400101# The following rules build samples of how to use gTest.
mistergf63e2a12017-08-01 14:36:29 -0400102cc_library(
mistergb3edada2017-08-01 14:50:59 -0400103 name = "gtest_sample_lib",
mistergf63e2a12017-08-01 14:36:29 -0400104 srcs = [
105 "googletest/samples/sample1.cc",
106 "googletest/samples/sample2.cc",
107 "googletest/samples/sample4.cc",
108 ],
109 hdrs = [
110 "googletest/samples/prime_tables.h",
111 "googletest/samples/sample1.h",
112 "googletest/samples/sample2.h",
113 "googletest/samples/sample3-inl.h",
114 "googletest/samples/sample4.h",
115 ],
mistergf63e2a12017-08-01 14:36:29 -0400116)
117
118cc_test(
mistergb3edada2017-08-01 14:50:59 -0400119 name = "gtest_samples",
mistergf63e2a12017-08-01 14:36:29 -0400120 size = "small",
misterg88150872017-08-08 15:17:56 -0400121 #All Samples except:
122 #sample9 ( main )
123 #sample10 (main and takes a command line option and needs to be separate)
124 srcs = [
125 "googletest/samples/sample1_unittest.cc",
126 "googletest/samples/sample2_unittest.cc",
127 "googletest/samples/sample3_unittest.cc",
128 "googletest/samples/sample4_unittest.cc",
129 "googletest/samples/sample5_unittest.cc",
130 "googletest/samples/sample6_unittest.cc",
131 "googletest/samples/sample7_unittest.cc",
132 "googletest/samples/sample8_unittest.cc",
133 ],
mistergf63e2a12017-08-01 14:36:29 -0400134 deps = [
mistergaa31cb62017-08-02 15:40:14 -0400135 "gtest_sample_lib",
mistergb3edada2017-08-01 14:50:59 -0400136 ":gtest_main",
mistergf63e2a12017-08-01 14:36:29 -0400137 ],
138)
139
140cc_test(
mistergaa31cb62017-08-02 15:40:14 -0400141 name = "sample9_unittest",
mistergf63e2a12017-08-01 14:36:29 -0400142 size = "small",
mistergaa31cb62017-08-02 15:40:14 -0400143 srcs = ["googletest/samples/sample9_unittest.cc"],
misterg88150872017-08-08 15:17:56 -0400144 deps = [":gtest"],
mistergaa31cb62017-08-02 15:40:14 -0400145)
146
147cc_test(
148 name = "sample10_unittest",
149 size = "small",
150 srcs = ["googletest/samples/sample10_unittest.cc"],
mistergf63e2a12017-08-01 14:36:29 -0400151 deps = [
misterg88150872017-08-08 15:17:56 -0400152 ":gtest",
mistergf63e2a12017-08-01 14:36:29 -0400153 ],
mistergb98e30b2017-08-10 11:54:46 -0400154)