mirror of
https://github.com/apple/foundationdb.git
synced 2026-01-25 04:18:18 +00:00
Use Findbenchmark instead of hardcoding the google-benchmark path in … (#12612)
* Use Findbenchmark instead of hardcoding the google-benchmark path in flowbench * fixup! Add missing include directories * fixup! Remove extra PRIVATE token * target_link_libraries -> target_include_directories * Support downloading google-benchmark if not found locally This may need to be reconsidered, as it seems more reasonable that the developer prepares the library rather than letting CMake takes the responsibility of monitoring the availability of an external project. * Remove extra creation of flowbench target
This commit is contained in:
82
cmake/Findbenchmark.cmake
Normal file
82
cmake/Findbenchmark.cmake
Normal file
@@ -0,0 +1,82 @@
|
||||
# Distributed under the OSI-approved Apache 2.0. See the LICENSE file in
|
||||
# FoundationDB source code
|
||||
|
||||
#[=======================================================================[.rst:
|
||||
Findbenchmark
|
||||
-------
|
||||
|
||||
Find Google Benchmark
|
||||
|
||||
benchmark_ROOT variable can be used for HINTS for different version of Google benchmark.
|
||||
|
||||
Result variables
|
||||
^^^^^^^^^^^^^^^^
|
||||
|
||||
This module will set the following variables in your project:
|
||||
|
||||
``benchmark_FOUND``
|
||||
If false, do not try to use Google Benchmark.
|
||||
``benchmark_INCLUDE_DIR``
|
||||
path to benchmark include directory
|
||||
``benchmark_LIBRARY``
|
||||
path to benchmark library
|
||||
``benchmark_main_LIBRARY``
|
||||
path to benchmark main library
|
||||
|
||||
This module will also define the following imported target:
|
||||
|
||||
``benchmark::benchmark``
|
||||
An imported target for Google Benchmark
|
||||
#]=======================================================================]
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
include(FindPackageMessage)
|
||||
|
||||
macro(_finalize_find_package_benchmark)
|
||||
find_package_handle_standard_args(
|
||||
benchmark
|
||||
FOUND_VAR benchmark_FOUND
|
||||
REQUIRED_VARS benchmark_INCLUDE_DIR benchmark_LIBRARY benchmark_main_LIBRARY)
|
||||
|
||||
if(benchmark_FOUND)
|
||||
add_library(benchmark::benchmark UNKNOWN IMPORTED)
|
||||
set_target_properties(
|
||||
benchmark::benchmark PROPERTIES
|
||||
INTERFACE_INCLUDE_DIRECTORIES "${benchmark_INCLUDE_DIR}"
|
||||
IMPORTED_LOCATION "${benchmark_LIBRARY}")
|
||||
add_library(benchmark::benchmark_main UNKNOWN IMPORTED)
|
||||
set_target_properties(
|
||||
benchmark::benchmark_main PROPERTIES
|
||||
IMPORTED_LOCATION "${benchmark_main_LIBRARY}")
|
||||
endif()
|
||||
|
||||
mark_as_advanced(benchmark_FOUND benchmark_INCLUDE_DIR benchmark_LIBRARY benchmark_main_LIBRARY)
|
||||
endmacro()
|
||||
|
||||
if(NOT benchmark_ROOT)
|
||||
set(benchmark_ROOT $ENV{benchmark_ROOT})
|
||||
endif()
|
||||
|
||||
find_path(benchmark_INCLUDE_DIR
|
||||
NAMES benchmark/benchmark.h
|
||||
HINTS ${benchmark_ROOT}
|
||||
DOC "Google Benchmark include directory")
|
||||
if(NOT benchmark_INCLUDE_DIR)
|
||||
_finalize_find_package_benchmark()
|
||||
return()
|
||||
endif()
|
||||
|
||||
find_library(benchmark_LIBRARY
|
||||
NAMES libbenchmark.a
|
||||
HINTS ${benchmark_ROOT}
|
||||
DOC "Google Benchmark library")
|
||||
find_library(benchmark_main_LIBRARY
|
||||
NAMES libbenchmark_main.a
|
||||
HINTS ${benchmark_ROOT}
|
||||
DOC "Google Benchmark main library")
|
||||
if(NOT benchmark_LIBRARY OR NOT benchmark_main_LIBRARY)
|
||||
_finalize_find_package_benchmark()
|
||||
return()
|
||||
endif()
|
||||
|
||||
_finalize_find_package_benchmark()
|
||||
@@ -1,18 +1,24 @@
|
||||
project (flowbench)
|
||||
project(flowbench)
|
||||
|
||||
fdb_find_sources(FLOWBENCH_SRCS)
|
||||
add_flow_target(EXECUTABLE NAME flowbench SRCS ${FLOWBENCH_SRCS})
|
||||
|
||||
# There is no good way to incorporate the recommended googlebenchmark download + build
|
||||
# process with one that checks to see if googlebenchmark has already been downloaded
|
||||
# and built.
|
||||
if(EXISTS /opt/googlebenchmark-f91b6b AND CLANG AND USE_LIBCXX)
|
||||
add_flow_target(EXECUTABLE NAME flowbench SRCS ${FLOWBENCH_SRCS})
|
||||
target_include_directories(flowbench PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/include" "${CMAKE_CURRENT_BINARY_DIR}/include" /opt/googlebenchmark-f91b6b/include)
|
||||
target_link_directories(flowbench PRIVATE /opt/googlebenchmark-f91b6b/lib64)
|
||||
elseif(EXISTS /opt/googlebenchmark-f91b6b-g++ AND NOT USE_LIBCXX)
|
||||
add_flow_target(EXECUTABLE NAME flowbench SRCS ${FLOWBENCH_SRCS})
|
||||
target_include_directories(flowbench PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/include" "${CMAKE_CURRENT_BINARY_DIR}/include" /opt/googlebenchmark-f91b6b-g++/include)
|
||||
target_link_directories(flowbench PRIVATE /opt/googlebenchmark-f91b6b-g++/lib64)
|
||||
# This stub is kept to maintain the backward compatibility with the existing build
|
||||
# environment. It should be removed when a reasonable environment is established.
|
||||
if(NOT benchmark_ROOT)
|
||||
if(EXISTS /opt/googlebenchmark-f91b6b AND CLANG AND USE_LIBCXX)
|
||||
set(benchmark_ROOT /opt/googlebenchmark-f91b6b)
|
||||
elseif(EXISTS /opt/googlebenchmark-f91b6b-g++ AND NOT USE_LIBCXX)
|
||||
set(benchmark_ROOT /opt/googlebenchmark-f91b6b-g++)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
find_package(benchmark)
|
||||
|
||||
if(benchmark_FOUND)
|
||||
target_include_directories(flowbench PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/include" "${CMAKE_CURRENT_BINARY_DIR}/include")
|
||||
target_include_directories(flowbench INTERFACE $<TARGET_PROPERTY:benchmark::benchmark, INTERFACE_INCLUDE_DIRECTORIES>)
|
||||
target_link_libraries(flowbench benchmark::benchmark)
|
||||
else()
|
||||
## This seems to be copy-pasted from the the google benchmark documentation.
|
||||
## It breaks if you attempt to re-use a build of googlebenchmark across FDB
|
||||
@@ -40,16 +46,19 @@ else()
|
||||
if(results)
|
||||
message(FATAL_ERROR "Build step for Benchmark has Failed. ${results}")
|
||||
endif()
|
||||
|
||||
set(BENCHMARK_ENABLE_TESTING OFF)
|
||||
add_subdirectory(
|
||||
${CMAKE_CURRENT_BINARY_DIR}/googlebenchmark-src
|
||||
${CMAKE_CURRENT_BINARY_DIR}/googlebenchmark-build
|
||||
EXCLUDE_FROM_ALL
|
||||
)
|
||||
add_flow_target(EXECUTABLE NAME flowbench SRCS ${FLOWBENCH_SRCS})
|
||||
target_include_directories(flowbench PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/include" "${CMAKE_CURRENT_BINARY_DIR}/include" ${CMAKE_CURRENT_BINARY_DIR}/googlebenchmark-src/include)
|
||||
target_link_libraries(flowbench benchmark)
|
||||
endif()
|
||||
|
||||
|
||||
if(FLOW_USE_ZSTD)
|
||||
target_include_directories(flowbench PRIVATE ${ZSTD_LIB_INCLUDE_DIR})
|
||||
target_include_directories(flowbench PRIVATE ${ZSTD_LIB_INCLUDE_DIR})
|
||||
endif()
|
||||
target_link_libraries(flowbench benchmark pthread flow fdbclient)
|
||||
target_link_libraries(flowbench pthread flow fdbclient)
|
||||
|
||||
Reference in New Issue
Block a user