BUILD.bazel 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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. load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test")
  33. package(default_visibility = ["//visibility:public"])
  34. licenses(["notice"])
  35. config_setting(
  36. name = "windows",
  37. constraint_values = ["@bazel_tools//platforms:windows"],
  38. )
  39. config_setting(
  40. name = "has_absl",
  41. values = {"define": "absl=1"},
  42. )
  43. # Library that defines the FRIEND_TEST macro.
  44. cc_library(
  45. name = "gtest_prod",
  46. hdrs = ["googletest/include/gtest/gtest_prod.h"],
  47. includes = ["googletest/include"],
  48. )
  49. # Google Test including Google Mock
  50. cc_library(
  51. name = "gtest",
  52. srcs = glob(
  53. include = [
  54. "googletest/src/*.cc",
  55. "googletest/src/*.h",
  56. "googletest/include/gtest/**/*.h",
  57. "googlemock/src/*.cc",
  58. "googlemock/include/gmock/**/*.h",
  59. ],
  60. exclude = [
  61. "googletest/src/gtest-all.cc",
  62. "googletest/src/gtest_main.cc",
  63. "googlemock/src/gmock-all.cc",
  64. "googlemock/src/gmock_main.cc",
  65. ],
  66. ),
  67. hdrs = glob([
  68. "googletest/include/gtest/*.h",
  69. "googlemock/include/gmock/*.h",
  70. ]),
  71. copts = select({
  72. ":windows": [],
  73. "//conditions:default": ["-pthread"],
  74. }),
  75. defines = select({
  76. ":has_absl": ["GTEST_HAS_ABSL=1"],
  77. "//conditions:default": [],
  78. }),
  79. features = select({
  80. ":windows": ["windows_export_all_symbols"],
  81. "//conditions:default": [],
  82. }),
  83. includes = [
  84. "googlemock",
  85. "googlemock/include",
  86. "googletest",
  87. "googletest/include",
  88. ],
  89. linkopts = select({
  90. ":windows": [],
  91. "//conditions:default": ["-pthread"],
  92. }),
  93. deps = select({
  94. ":has_absl": [
  95. "@com_google_absl//absl/debugging:failure_signal_handler",
  96. "@com_google_absl//absl/debugging:stacktrace",
  97. "@com_google_absl//absl/debugging:symbolize",
  98. "@com_google_absl//absl/strings",
  99. "@com_google_absl//absl/types:optional",
  100. "@com_google_absl//absl/types:variant",
  101. ],
  102. "//conditions:default": [],
  103. }),
  104. )
  105. cc_library(
  106. name = "gtest_main",
  107. srcs = ["googlemock/src/gmock_main.cc"],
  108. features = select({
  109. ":windows": ["windows_export_all_symbols"],
  110. "//conditions:default": [],
  111. }),
  112. deps = [":gtest"],
  113. )
  114. # The following rules build samples of how to use gTest.
  115. cc_library(
  116. name = "gtest_sample_lib",
  117. srcs = [
  118. "googletest/samples/sample1.cc",
  119. "googletest/samples/sample2.cc",
  120. "googletest/samples/sample4.cc",
  121. ],
  122. hdrs = [
  123. "googletest/samples/prime_tables.h",
  124. "googletest/samples/sample1.h",
  125. "googletest/samples/sample2.h",
  126. "googletest/samples/sample3-inl.h",
  127. "googletest/samples/sample4.h",
  128. ],
  129. features = select({
  130. ":windows": ["windows_export_all_symbols"],
  131. "//conditions:default": [],
  132. }),
  133. )
  134. cc_test(
  135. name = "gtest_samples",
  136. size = "small",
  137. # All Samples except:
  138. # sample9 (main)
  139. # sample10 (main and takes a command line option and needs to be separate)
  140. srcs = [
  141. "googletest/samples/sample1_unittest.cc",
  142. "googletest/samples/sample2_unittest.cc",
  143. "googletest/samples/sample3_unittest.cc",
  144. "googletest/samples/sample4_unittest.cc",
  145. "googletest/samples/sample5_unittest.cc",
  146. "googletest/samples/sample6_unittest.cc",
  147. "googletest/samples/sample7_unittest.cc",
  148. "googletest/samples/sample8_unittest.cc",
  149. ],
  150. linkstatic = 0,
  151. deps = [
  152. "gtest_sample_lib",
  153. ":gtest_main",
  154. ],
  155. )
  156. cc_test(
  157. name = "sample9_unittest",
  158. size = "small",
  159. srcs = ["googletest/samples/sample9_unittest.cc"],
  160. deps = [":gtest"],
  161. )
  162. cc_test(
  163. name = "sample10_unittest",
  164. size = "small",
  165. srcs = ["googletest/samples/sample10_unittest.cc"],
  166. deps = [":gtest"],
  167. )