Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always linking gbench statically #1874

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions cpp/bench/ann/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ endif()
# ##################################################################################################
# * Configure tests function-------------------------------------------------------------

# Build and link static version of the GBench to keep ANN_BENCH self-contained.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't work when google benchmark is pre-built and coming from the environment. The sources in that case will be empty and you will fail to have any gtest/gbench in your final executable.

get_target_property(TMP_PROP benchmark::benchmark SOURCES)
add_library(benchmark_static STATIC ${TMP_PROP})
get_target_property(TMP_PROP benchmark::benchmark INCLUDE_DIRECTORIES)
target_include_directories(benchmark_static PUBLIC ${TMP_PROP})
get_target_property(TMP_PROP benchmark::benchmark LINK_LIBRARIES)
target_link_libraries(benchmark_static PUBLIC ${TMP_PROP})

function(ConfigureAnnBench)

set(oneValueArgs NAME)
Expand All @@ -106,10 +114,11 @@ function(ConfigureAnnBench)
string(TOLOWER ${BENCH_NAME} BENCH_LIB_NAME)
set_target_properties(${BENCH_NAME} PROPERTIES OUTPUT_NAME ${BENCH_LIB_NAME})
add_dependencies(${BENCH_NAME} ANN_BENCH)
target_link_libraries(ANN_BENCH PRIVATE benchmark_static)
else()
add_executable(${BENCH_NAME} ${ConfigureAnnBench_PATH})
target_compile_definitions(${BENCH_NAME} PRIVATE ANN_BENCH_BUILD_MAIN)
target_link_libraries(${BENCH_NAME} PRIVATE benchmark::benchmark)
target_link_libraries(${BENCH_NAME} PRIVATE benchmark_static)
endif()

target_link_libraries(
Expand Down Expand Up @@ -242,14 +251,6 @@ endif()
if(RAFT_ANN_BENCH_SINGLE_EXE)
add_executable(ANN_BENCH bench/ann/src/common/benchmark.cpp)

# Build and link static version of the GBench to keep ANN_BENCH self-contained.
get_target_property(TMP_PROP benchmark::benchmark SOURCES)
add_library(benchmark_static STATIC ${TMP_PROP})
get_target_property(TMP_PROP benchmark::benchmark INCLUDE_DIRECTORIES)
target_include_directories(benchmark_static PUBLIC ${TMP_PROP})
get_target_property(TMP_PROP benchmark::benchmark LINK_LIBRARIES)
target_link_libraries(benchmark_static PUBLIC ${TMP_PROP})

target_include_directories(ANN_BENCH PRIVATE ${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES})

target_link_libraries(
Expand Down