BUILD.bazel 6.3 KB

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