From 1454018dc1d980940765e2121b26de9bd980ac7f Mon Sep 17 00:00:00 2001 From: Leonard Chan Date: Mon, 17 Aug 2020 18:11:56 -0700 Subject: [PATCH] Revert "[libc++] Use CMake interface targets to setup benchmark flags" This reverts commit da0592e4c8df95efad4e42d63646f8a5336a7edc. Reverting because this is incompatible with cmake 3.13.5, with the minimum supported version being 3.13.4. See https://luci-milo.appspot.com/p/fuchsia/builders/ci/clang-linux-x64/b8871967816877544224. --- libcxx/benchmarks/CMakeLists.txt | 92 ++++++++++++++++++++++---------- 1 file changed, 64 insertions(+), 28 deletions(-) diff --git a/libcxx/benchmarks/CMakeLists.txt b/libcxx/benchmarks/CMakeLists.txt index b35506dcf04a..8480ede23a49 100644 --- a/libcxx/benchmarks/CMakeLists.txt +++ b/libcxx/benchmarks/CMakeLists.txt @@ -70,33 +70,57 @@ 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) - -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 (LIBSTDCXX_FILESYSTEM_TEST) - target_link_libraries(cxx-benchmarks-flags-native INTERFACE "-lstdc++fs") - endif() +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() - target_link_libraries(cxx-benchmarks-flags-native INTERFACE -lc++fs -lc++experimental) + # 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() -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(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) + +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() +endif() set(libcxx_benchmark_targets) @@ -104,7 +128,6 @@ 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) @@ -122,15 +145,25 @@ function(add_benchmark_test name source_file) set_target_properties(${libcxx_target} PROPERTIES OUTPUT_NAME "${name}.libcxx.out" - RUNTIME_OUTPUT_DIRECTORY "${BENCHMARK_OUTPUT_DIR}") + RUNTIME_OUTPUT_DIRECTORY "${BENCHMARK_OUTPUT_DIR}" + COMPILE_FLAGS "${BENCHMARK_TEST_LIBCXX_COMPILE_FLAGS}" + LINK_FLAGS "${BENCHMARK_TEST_LIBCXX_LINK_FLAGS}") 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() @@ -138,7 +171,10 @@ function(add_benchmark_test name source_file) set_target_properties(${native_target} PROPERTIES OUTPUT_NAME "${name}.native.out" - RUNTIME_OUTPUT_DIRECTORY "${BENCHMARK_OUTPUT_DIR}") + RUNTIME_OUTPUT_DIRECTORY "${BENCHMARK_OUTPUT_DIR}" + INCLUDE_DIRECTORIES "" + COMPILE_FLAGS "${BENCHMARK_TEST_NATIVE_COMPILE_FLAGS}" + LINK_FLAGS "${BENCHMARK_TEST_NATIVE_LINK_FLAGS}") endif() endfunction()