benchmark.cmake 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. # Copyright 2017 gRPC authors.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. if(gRPC_BENCHMARK_PROVIDER STREQUAL "module")
  15. set(BENCHMARK_ENABLE_GTEST_TESTS OFF CACHE BOOL "Turn off gTest in gBenchmark")
  16. if(NOT BENCHMARK_ROOT_DIR)
  17. set(BENCHMARK_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/benchmark)
  18. endif()
  19. if(EXISTS "${BENCHMARK_ROOT_DIR}/CMakeLists.txt")
  20. add_subdirectory(${BENCHMARK_ROOT_DIR} third_party/benchmark)
  21. if(TARGET benchmark)
  22. set(_gRPC_BENCHMARK_LIBRARIES benchmark)
  23. endif()
  24. else()
  25. message(WARNING "gRPC_BENCHMARK_PROVIDER is \"module\" but BENCHMARK_ROOT_DIR is wrong")
  26. endif()
  27. elseif(gRPC_BENCHMARK_PROVIDER STREQUAL "package")
  28. # Use "CONFIG" as there is no built-in cmake module for benchmark.
  29. find_package(benchmark REQUIRED CONFIG)
  30. if(TARGET benchmark::benchmark)
  31. set(_gRPC_BENCHMARK_LIBRARIES benchmark::benchmark)
  32. endif()
  33. set(_gRPC_FIND_BENCHMARK "if(NOT benchmark_FOUND)\n find_package(benchmark CONFIG)\nendif()")
  34. elseif(gRPC_BENCHMARK_PROVIDER STREQUAL "none")
  35. # Benchmark is a test-only dependency and can be avoided if we're not building tests.
  36. endif()