From df838dbcfa9da0c15d5115fe3e643ee032d39a79 Mon Sep 17 00:00:00 2001 From: Guillaume Chatelet Date: Fri, 25 Mar 2022 13:21:20 +0000 Subject: [PATCH] [NFC][libc] Disable benchmarks when the LLVM benchmark target is not available Fixes https://github.com/llvm/llvm-project/issues/53686 Differential Revision: https://reviews.llvm.org/D122481 --- libc/CMakeLists.txt | 4 +++- libc/benchmarks/CMakeLists.txt | 26 ++++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/libc/CMakeLists.txt b/libc/CMakeLists.txt index 6ce6c149113e..ca9a81991fa9 100644 --- a/libc/CMakeLists.txt +++ b/libc/CMakeLists.txt @@ -161,7 +161,9 @@ if(LLVM_INCLUDE_TESTS) add_subdirectory(fuzzing) endif() -add_subdirectory(benchmarks) +if(LIBC_INCLUDE_BENCHMARKS) + add_subdirectory(benchmarks) +endif() if (LIBC_INCLUDE_DOCS) add_subdirectory(docs) diff --git a/libc/benchmarks/CMakeLists.txt b/libc/benchmarks/CMakeLists.txt index 0e9ec5a1f790..c67dadf0f1f8 100644 --- a/libc/benchmarks/CMakeLists.txt +++ b/libc/benchmarks/CMakeLists.txt @@ -43,6 +43,27 @@ endfunction() # Build Google Benchmark for libc #============================================================================== +include(ExternalProject) +ExternalProject_Add(google-benchmark-libc + EXCLUDE_FROM_ALL ON + PREFIX google-benchmark-libc + SOURCE_DIR ${LLVM_THIRD_PARTY_DIR}/benchmark + INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR}/google-benchmark-libc + CMAKE_CACHE_ARGS + -DBENCHMARK_ENABLE_EXCEPTIONS:BOOL=OFF + -DBENCHMARK_ENABLE_LTO:BOOL=OFF + -DBENCHMARK_ENABLE_TESTING:BOOL=OFF + -DBENCHMARK_ENABLE_WERROR:BOOL=${LLVM_ENABLE_WERROR} + -DBENCHMARK_FORCE_WERROR:BOOL=OFF + -DBENCHMARK_USE_LIBCXX:BOOL=OFF + -DCMAKE_BUILD_TYPE:STRING=RELEASE + -DCMAKE_C_COMPILER:STRING=${CMAKE_C_COMPILER} + -DCMAKE_CXX_COMPILER:STRING=${CMAKE_CXX_COMPILER} + -DCMAKE_CXX_FLAGS:STRING=${BENCHMARK_LIBC_COMPILE_FLAGS} + -DCMAKE_CXX_STANDARD:STRING=14 + -DCMAKE_INSTALL_PREFIX:PATH= + ) + add_custom_target(libc-benchmark-util-tests) # libc-benchmark @@ -52,13 +73,14 @@ add_library(libc-benchmark LibcBenchmark.cpp LibcBenchmark.h ) -add_dependencies(libc-benchmark benchmark) + target_link_libraries(libc-benchmark PUBLIC - benchmark + benchmark::benchmark LLVMSupport Threads::Threads ) +add_dependencies(libc-benchmark google-benchmark-libc) llvm_update_compile_flags(libc-benchmark) add_libc_benchmark_unittest(libc-benchmark-test