You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

190 lines
5.6 KiB

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