Enable sapi_test target in CMake, add Benchmark dependency

PiperOrigin-RevId: 281719298
Change-Id: Idd2570fff4907c81cdab1070bd1f3e41e29c76f6
This commit is contained in:
Christian Blichmann 2019-11-21 04:03:47 -08:00 committed by Copybara-Service
parent 6dd97f5073
commit d47c066112
5 changed files with 91 additions and 2 deletions

View File

@ -34,6 +34,11 @@ if(SAPI_ENABLE_TESTS)
check_target(gtest)
check_target(gtest_main)
check_target(gmock)
if(SAPI_USE_BENCHMARK)
include(cmake/benchmark/Download.cmake)
endif()
check_target(benchmark)
endif()
if(SAPI_USE_ABSL)

View File

@ -21,6 +21,7 @@
# depend on some of these libraries (e.g. Abseil).
option(SAPI_USE_ABSL "Download Abseil at config time" ON)
option(SAPI_USE_GOOGLETEST "Download googletest at config time" ON)
option(SAPI_USE_BENCHMARK "Download benchmark at config time" ON)
option(SAPI_USE_GFLAGS "Download gflags at config time" ON)
option(SAPI_USE_GLOG "Download glog at config time" ON)
option(SAPI_USE_PROTOBUF "Download protobuf at config time" ON)

View File

@ -0,0 +1,28 @@
# Copyright 2019 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
cmake_minimum_required(VERSION 3.10)
project(benchmark-download NONE)
include(ExternalProject)
ExternalProject_Add(benchmark
GIT_REPOSITORY https://github.com/google/benchmark.git
GIT_TAG 090faecb454fbd6e6e17a75ef8146acb037118d4 # 2019-05-13
SOURCE_DIR "${CMAKE_BINARY_DIR}/benchmark-src"
BINARY_DIR "${CMAKE_BINARY_DIR}/benchmark-build"
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
)

View File

@ -0,0 +1,40 @@
# Copyright 2019 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Downloads and unpacks Benchmark at configure time
set(workdir "${CMAKE_BINARY_DIR}/benchmark-download")
configure_file("${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt.in"
"${workdir}/CMakeLists.txt")
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
RESULT_VARIABLE error
WORKING_DIRECTORY "${workdir}")
if(error)
message(FATAL_ERROR "CMake step for ${PROJECT_NAME} failed: ${error}")
endif()
execute_process(COMMAND ${CMAKE_COMMAND} --build .
RESULT_VARIABLE error
WORKING_DIRECTORY "${workdir}")
if(error)
message(FATAL_ERROR "Build step for ${PROJECT_NAME} failed: ${error}")
endif()
set(BENCHMARK_ENABLE_TESTING OFF)
set(BENCHMARK_ENABLE_EXCEPTIONS OFF)
set(BENCHMARK_ENABLE_GTEST_TESTS OFF)
add_subdirectory("${CMAKE_BINARY_DIR}/benchmark-src"
"${CMAKE_BINARY_DIR}/benchmark-build" EXCLUDE_FROM_ALL)

View File

@ -168,5 +168,20 @@ target_link_libraries(sapi_client PRIVATE
sapi::vars
)
if(SAPI_ENABLE_TESTS)
# sandboxed_api:sapi_test
# TODO(cblichmann): Add sapi_test once generator can be invoked via CMake
add_executable(sapi_test
sapi_test.cc
)
target_link_libraries(sapi_test PRIVATE
absl::memory
benchmark
sapi::sapi
sapi::status
sapi::status_matchers
sapi::stringop_sapi
sapi::sum_sapi
sapi::test_main
)
gtest_discover_tests(sapi_test)
endif()