BUILD.bazel 6.0 KB

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