[libcxx-commits] [libcxx] da0592e - [libc++] Use CMake interface targets to setup benchmark flags
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Aug 13 05:38:27 PDT 2020
Author: Louis Dionne
Date: 2020-08-13T08:38:02-04:00
New Revision: da0592e4c8df95efad4e42d63646f8a5336a7edc
URL: https://github.com/llvm/llvm-project/commit/da0592e4c8df95efad4e42d63646f8a5336a7edc
DIFF: https://github.com/llvm/llvm-project/commit/da0592e4c8df95efad4e42d63646f8a5336a7edc.diff
LOG: [libc++] Use CMake interface targets to setup benchmark flags
This also fixes an issue where the benchmarks were being built with C++14
instead of C++17, as they should be.
Added:
Modified:
libcxx/benchmarks/CMakeLists.txt
Removed:
################################################################################
diff --git a/libcxx/benchmarks/CMakeLists.txt b/libcxx/benchmarks/CMakeLists.txt
index 8480ede23a49..b35506dcf04a 100644
--- a/libcxx/benchmarks/CMakeLists.txt
+++ b/libcxx/benchmarks/CMakeLists.txt
@@ -70,64 +70,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)
-check_flag_supported("-std=c++17")
-mangle_name("LIBCXX_SUPPORTS_STD_EQ_c++17_FLAG" BENCHMARK_SUPPORTS_STD_CXX17_FLAG)
-if (${BENCHMARK_SUPPORTS_STD_CXX17_FLAG})
- set(BENCHMARK_DIALECT_FLAG "-std=c++17")
-else()
- # If the compiler doesn't support -std=c++17, attempt to fall back to -std=c++1z while still
- # requiring C++17 language features.
- set(BENCHMARK_DIALECT_FLAG "-std=c++1z")
-endif()
-
-set(BENCHMARK_TEST_COMPILE_FLAGS
- ${BENCHMARK_DIALECT_FLAG} -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
-)
-
-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 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)
+
+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()
+ PATHS ${LIBCXX_BENCHMARK_NATIVE_GCC_TOOLCHAIN}
+ PATH_SUFFIXES lib lib64
+ DOC "The libstdc++ filesystem library used by the benchmarks"
+ )
+ 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)
+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)
@@ -145,25 +122,15 @@ function(add_benchmark_test name source_file)
set_target_properties(${libcxx_target}
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}")
+ RUNTIME_OUTPUT_DIRECTORY "${BENCHMARK_OUTPUT_DIR}")
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()
@@ -171,10 +138,7 @@ function(add_benchmark_test name source_file)
set_target_properties(${native_target}
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}")
+ RUNTIME_OUTPUT_DIRECTORY "${BENCHMARK_OUTPUT_DIR}")
endif()
endfunction()
More information about the libcxx-commits
mailing list