summaryrefslogtreecommitdiff
path: root/libcxx/benchmarks
diff options
context:
space:
mode:
authorLouis Dionne <ldionne@apple.com>2020-08-12 17:56:16 -0400
committerLouis Dionne <ldionne.2@gmail.com>2021-09-23 12:14:01 -0400
commitfd04fd9ac92d705f7d144b77109b8bcec950c04f (patch)
tree390443f3d1a84404ce895fb2c809118eb9433eef /libcxx/benchmarks
parentf9912fe4eac91f27965c22d015b3109c5158d050 (diff)
downloadllvm-fd04fd9ac92d705f7d144b77109b8bcec950c04f.tar.gz
[libc++] Use CMake interface targets to setup benchmark flags
This is a re-application of da0592e4c8df which was reverted in 1454018dc1d9 because it was incompatible with older CMakes. Instead, disable the benchmarks when CMake is too old to support those idioms. Differential Revision: https://reviews.llvm.org/D110285
Diffstat (limited to 'libcxx/benchmarks')
-rw-r--r--libcxx/benchmarks/CMakeLists.txt79
1 files changed, 26 insertions, 53 deletions
diff --git a/libcxx/benchmarks/CMakeLists.txt b/libcxx/benchmarks/CMakeLists.txt
index 8e33f8ebcf0c..8d83ecdfc9b9 100644
--- a/libcxx/benchmarks/CMakeLists.txt
+++ b/libcxx/benchmarks/CMakeLists.txt
@@ -1,3 +1,8 @@
+if (CMAKE_VERSION VERSION_LESS 3.17)
+ message(WARNING "The libc++ benchmarks won't be available because the version of CMake is too old to support them.")
+ return()
+endif()
+
include(ExternalProject)
include(CheckCXXCompilerFlag)
@@ -75,56 +80,41 @@ set(BENCHMARK_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR})
set(BENCHMARK_LIBCXX_INSTALL ${CMAKE_CURRENT_BINARY_DIR}/benchmark-libcxx)
set(BENCHMARK_NATIVE_INSTALL ${CMAKE_CURRENT_BINARY_DIR}/benchmark-native)
+add_library( cxx-benchmarks-flags INTERFACE)
+target_compile_features( cxx-benchmarks-flags INTERFACE cxx_std_17)
+target_compile_options( cxx-benchmarks-flags INTERFACE -O2 -fsized-deallocation)
+target_include_directories(cxx-benchmarks-flags INTERFACE "${BENCHMARK_LIBCXX_INSTALL}/include"
+ INTERFACE "${LIBCXX_SOURCE_DIR}/test/support")
-set(BENCHMARK_TEST_COMPILE_FLAGS
- -O2
- -fsized-deallocation
- -I${BENCHMARK_LIBCXX_INSTALL}/include
- -I${LIBCXX_SOURCE_DIR}/test/support
-)
-set(BENCHMARK_TEST_LIBCXX_COMPILE_FLAGS
- ${BENCHMARK_TEST_COMPILE_FLAGS}
- ${SANITIZER_FLAGS}
- -Wno-user-defined-literals
- -Wno-suggest-override
-)
-
-set(BENCHMARK_TEST_LIBCXX_LINK_FLAGS
- -nodefaultlibs
- -L${BENCHMARK_LIBCXX_INSTALL}/lib/
- ${SANITIZER_FLAGS}
-)
-set(BENCHMARK_TEST_NATIVE_COMPILE_FLAGS
- ${BENCHMARK_NATIVE_TARGET_FLAGS}
- ${BENCHMARK_TEST_COMPILE_FLAGS}
-)
-set(BENCHMARK_TEST_NATIVE_LINK_FLAGS
- ${BENCHMARK_NATIVE_TARGET_FLAGS}
- -L${BENCHMARK_NATIVE_INSTALL}/lib
-)
-split_list(BENCHMARK_TEST_COMPILE_FLAGS)
-split_list(BENCHMARK_TEST_LIBCXX_COMPILE_FLAGS)
-split_list(BENCHMARK_TEST_LIBCXX_LINK_FLAGS)
-split_list(BENCHMARK_TEST_NATIVE_COMPILE_FLAGS)
-split_list(BENCHMARK_TEST_NATIVE_LINK_FLAGS)
-
+add_library( cxx-benchmarks-flags-native INTERFACE)
+target_link_libraries( cxx-benchmarks-flags-native INTERFACE cxx-benchmarks-flags)
+target_compile_options(cxx-benchmarks-flags-native INTERFACE ${BENCHMARK_NATIVE_TARGET_FLAGS})
+target_link_options( cxx-benchmarks-flags-native INTERFACE ${BENCHMARK_NATIVE_TARGET_FLAGS} "-L${BENCHMARK_NATIVE_INSTALL}/lib")
if (LIBCXX_BENCHMARK_NATIVE_STDLIB STREQUAL "libstdc++")
find_library(LIBSTDCXX_FILESYSTEM_TEST stdc++fs
PATHS ${LIBCXX_BENCHMARK_NATIVE_GCC_TOOLCHAIN}
PATH_SUFFIXES lib lib64
DOC "The libstdc++ filesystem library used by the benchmarks"
)
- if (NOT "${LIBSTDCXX_FILESYSTEM_TEST}" STREQUAL "LIBSTDCXX_FILESYSTEM_TEST-NOTFOUND")
- set(LIBSTDCXX_FILESYSTEM_LIB "stdc++fs")
- endif()
+ if (LIBSTDCXX_FILESYSTEM_TEST)
+ target_link_libraries(cxx-benchmarks-flags-native INTERFACE -lstdc++fs)
+ endif()
+else()
+ target_link_libraries(cxx-benchmarks-flags-native INTERFACE -lc++fs -lc++experimental)
endif()
+add_library( cxx-benchmarks-flags-libcxx INTERFACE)
+target_link_libraries( cxx-benchmarks-flags-libcxx INTERFACE cxx-benchmarks-flags)
+target_compile_options(cxx-benchmarks-flags-libcxx INTERFACE ${SANITIZER_FLAGS} -Wno-user-defined-literals -Wno-suggest-override)
+target_link_options( cxx-benchmarks-flags-libcxx INTERFACE -nodefaultlibs "-L${BENCHMARK_LIBCXX_INSTALL}/lib" ${SANITIZER_FLAGS})
+
set(libcxx_benchmark_targets)
function(add_benchmark_test name source_file)
set(libcxx_target ${name}_libcxx)
list(APPEND libcxx_benchmark_targets ${libcxx_target})
add_executable(${libcxx_target} EXCLUDE_FROM_ALL ${source_file})
+ target_link_libraries(${libcxx_target} PRIVATE cxx-benchmarks-flags-libcxx)
add_dependencies(${libcxx_target} cxx google-benchmark-libcxx)
add_dependencies(cxx-benchmarks ${libcxx_target})
if (LIBCXX_ENABLE_SHARED)
@@ -143,27 +133,15 @@ function(add_benchmark_test name source_file)
PROPERTIES
OUTPUT_NAME "${name}.libcxx.out"
RUNTIME_OUTPUT_DIRECTORY "${BENCHMARK_OUTPUT_DIR}"
- COMPILE_FLAGS "${BENCHMARK_TEST_LIBCXX_COMPILE_FLAGS}"
- LINK_FLAGS "${BENCHMARK_TEST_LIBCXX_LINK_FLAGS}"
- CXX_STANDARD 17
- CXX_STANDARD_REQUIRED YES
CXX_EXTENSIONS NO)
cxx_link_system_libraries(${libcxx_target})
if (LIBCXX_BENCHMARK_NATIVE_STDLIB)
- if (LIBCXX_BENCHMARK_NATIVE_STDLIB STREQUAL "libstdc++" AND NOT DEFINED LIBSTDCXX_FILESYSTEM_LIB
- AND "${name}" STREQUAL "filesystem")
- return()
- endif()
set(native_target ${name}_native)
add_executable(${native_target} EXCLUDE_FROM_ALL ${source_file})
+ target_link_libraries(${native_target} PRIVATE cxx-benchmarks-flags-native)
add_dependencies(${native_target} google-benchmark-native
google-benchmark-libcxx)
target_link_libraries(${native_target} PRIVATE -lbenchmark)
- if (LIBCXX_BENCHMARK_NATIVE_STDLIB STREQUAL "libstdc++")
- target_link_libraries(${native_target} PRIVATE ${LIBSTDCXX_FILESYSTEM_LIB})
- elseif (LIBCXX_BENCHMARK_NATIVE_STDLIB STREQUAL "libc++")
- target_link_libraries(${native_target} PRIVATE -lc++fs -lc++experimental)
- endif()
if (LIBCXX_HAS_PTHREAD_LIB)
target_link_libraries(${native_target} PRIVATE -pthread)
endif()
@@ -172,11 +150,6 @@ function(add_benchmark_test name source_file)
PROPERTIES
OUTPUT_NAME "${name}.native.out"
RUNTIME_OUTPUT_DIRECTORY "${BENCHMARK_OUTPUT_DIR}"
- INCLUDE_DIRECTORIES ""
- COMPILE_FLAGS "${BENCHMARK_TEST_NATIVE_COMPILE_FLAGS}"
- LINK_FLAGS "${BENCHMARK_TEST_NATIVE_LINK_FLAGS}"
- CXX_STANDARD 17
- CXX_STANDARD_REQUIRED YES
CXX_EXTENSIONS NO)
endif()
endfunction()