Use own benchmark and not any system pre-built ones:

Summary:
(1) use the cmake files of the corresponding libs
(2) allow static linkage of gtest and gbenchmark.
(3) Helps removing the temp solution in #1112

We are yet to disable the installation of the benchmark library, and I have an open pull request at https://github.com/google/benchmark/pull/463 - once it is merged I will do submodule update.

cc lukeyeager pietern who had this issue before - hopefully this makes the solution cleaner.
Closes https://github.com/caffe2/caffe2/pull/1358

Differential Revision: D6111404

Pulled By: Yangqing

fbshipit-source-id: 17468d32cef27f96e9445d119eb869c9c7913118
This commit is contained in:
Yangqing Jia
2017-10-20 10:33:22 -07:00
committed by Facebook Github Bot
parent 25bfffeafe
commit 02f4303749
5 changed files with 27 additions and 16 deletions

View File

@ -9,12 +9,6 @@ set(CAFFE2_VERSION_PATCH 1)
set(CAFFE2_VERSION
"${CAFFE2_VERSION_MAJOR}.${CAFFE2_VERSION_MINOR}.${CAFFE2_VERSION_PATCH}")
# ---[ Do not search cmake install prefix. See the following link for details:
# https://github.com/caffe2/caffe2/commit/251d2d0c521c781276eea3748d92fc92e5dbceab
message(STATUS "Setting CMAKE_FIND_NO_INSTALL_PREFIX")
set(CMAKE_FIND_NO_INSTALL_PREFIX TRUE)
# ---[ Options.
# Note to developers: if you add an option below, make sure you also add it to
# cmake/Summary.cmake so that the summary prints out the option values.

View File

@ -13,6 +13,12 @@ if (USE_CUDA)
caffe2_binary_target("inspect_gpus.cc")
target_link_libraries(inspect_gpus ${CUDA_LIBRARIES})
caffe2_binary_target("print_core_object_sizes.cc")
if (BUILD_TEST)
# Core overhead benchmark
caffe2_binary_target("core_overhead_benchmark.cc")
target_link_libraries(core_overhead_benchmark benchmark)
endif()
endif()
if (USE_ZMQ)

View File

@ -114,17 +114,28 @@ endif()
# ---[ Googletest and benchmark
if(BUILD_TEST)
set(TEMP_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS})
# We will build gtest as static libs and embed it directly into the binary.
set(BUILD_SHARED_LIBS OFF)
# For gtest, we will simply embed it into our test binaries, so we won't
# need to install it.
set(BUILD_GTEST ON)
set(INSTALL_GTEST OFF)
# We currently don't need gmock right now.
set(BUILD_GMOCK OFF)
add_subdirectory(${PROJECT_SOURCE_DIR}/third_party/googletest)
caffe2_include_directories(${PROJECT_SOURCE_DIR}/third_party/googletest/googletest/include)
find_package(Benchmark)
if(Benchmark_FOUND)
list(APPEND Caffe2_DEPENDENCY_LIBS ${Benchmark_LIBRARIES})
caffe2_include_directories(${Benchmark_INCLUDE_DIRS})
else()
add_subdirectory(${PROJECT_SOURCE_DIR}/third_party/benchmark)
caffe2_include_directories(${PROJECT_SOURCE_DIR}/third_party/benchmark/include)
endif()
# We will not need to test benchmark lib itself.
set(BENCHMARK_ENABLE_TESTING OFF)
# We will not need to install benchmark. This is pending
# https://github.com/google/benchmark/pull/463
set(INSTALL_BENCHMARK OFF)
add_subdirectory(${PROJECT_SOURCE_DIR}/third_party/benchmark)
caffe2_include_directories(${PROJECT_SOURCE_DIR}/third_party/benchmark/include)
# Recover the build shared libs option.
set(BUILD_SHARED_LIBS ${TEMP_BUILD_SHARED_LIBS})
endif()
# ---[ LMDB