[libc-commits] [libc] df838db - [NFC][libc] Disable benchmarks when the LLVM benchmark target is not available

Guillaume Chatelet via libc-commits libc-commits at lists.llvm.org
Tue Mar 29 01:46:27 PDT 2022


Author: Guillaume Chatelet
Date: 2022-03-29T08:45:53Z
New Revision: df838dbcfa9da0c15d5115fe3e643ee032d39a79

URL: https://github.com/llvm/llvm-project/commit/df838dbcfa9da0c15d5115fe3e643ee032d39a79
DIFF: https://github.com/llvm/llvm-project/commit/df838dbcfa9da0c15d5115fe3e643ee032d39a79.diff

LOG: [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

Added: 
    

Modified: 
    libc/CMakeLists.txt
    libc/benchmarks/CMakeLists.txt

Removed: 
    


################################################################################
diff  --git a/libc/CMakeLists.txt b/libc/CMakeLists.txt
index 6ce6c149113ef..ca9a81991fa98 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 0e9ec5a1f790c..c67dadf0f1f8b 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=<INSTALL_DIR>
+        )
+
 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


        


More information about the libc-commits mailing list