BUILD.bazel 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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/debugging:failure_signal_handler",
  125. "@com_google_absl//absl/debugging:stacktrace",
  126. "@com_google_absl//absl/debugging:symbolize",
  127. "@com_google_absl//absl/flags:flag",
  128. "@com_google_absl//absl/flags:parse",
  129. "@com_google_absl//absl/flags:reflection",
  130. "@com_google_absl//absl/flags:usage",
  131. "@com_google_absl//absl/strings",
  132. "@com_google_absl//absl/types:any",
  133. "@com_google_absl//absl/types:optional",
  134. "@com_google_absl//absl/types:variant",
  135. "@com_googlesource_code_re2//:re2",
  136. ],
  137. "//conditions:default": [],
  138. }),
  139. )
  140. cc_library(
  141. name = "gtest_main",
  142. srcs = ["googlemock/src/gmock_main.cc"],
  143. features = select({
  144. ":windows": ["windows_export_all_symbols"],
  145. "//conditions:default": [],
  146. }),
  147. deps = [":gtest"],
  148. )
  149. # The following rules build samples of how to use gTest.
  150. cc_library(
  151. name = "gtest_sample_lib",
  152. srcs = [
  153. "googletest/samples/sample1.cc",
  154. "googletest/samples/sample2.cc",
  155. "googletest/samples/sample4.cc",
  156. ],
  157. hdrs = [
  158. "googletest/samples/prime_tables.h",
  159. "googletest/samples/sample1.h",
  160. "googletest/samples/sample2.h",
  161. "googletest/samples/sample3-inl.h",
  162. "googletest/samples/sample4.h",
  163. ],
  164. features = select({
  165. ":windows": ["windows_export_all_symbols"],
  166. "//conditions:default": [],
  167. }),
  168. )
  169. cc_test(
  170. name = "gtest_samples",
  171. size = "small",
  172. # All Samples except:
  173. # sample9 (main)
  174. # sample10 (main and takes a command line option and needs to be separate)
  175. srcs = [
  176. "googletest/samples/sample1_unittest.cc",
  177. "googletest/samples/sample2_unittest.cc",
  178. "googletest/samples/sample3_unittest.cc",
  179. "googletest/samples/sample4_unittest.cc",
  180. "googletest/samples/sample5_unittest.cc",
  181. "googletest/samples/sample6_unittest.cc",
  182. "googletest/samples/sample7_unittest.cc",
  183. "googletest/samples/sample8_unittest.cc",
  184. ],
  185. linkstatic = 0,
  186. deps = [
  187. "gtest_sample_lib",
  188. ":gtest_main",
  189. ],
  190. )
  191. cc_test(
  192. name = "sample9_unittest",
  193. size = "small",
  194. srcs = ["googletest/samples/sample9_unittest.cc"],
  195. deps = [":gtest"],
  196. )
  197. cc_test(
  198. name = "sample10_unittest",
  199. size = "small",
  200. srcs = ["googletest/samples/sample10_unittest.cc"],
  201. deps = [":gtest"],
  202. )