BUILD.bazel 5.1 KB

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