Revert "[libc++] Use CMake interface targets to setup benchmark flags"

This reverts commit da0592e4c8.

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.
This commit is contained in:
Leonard Chan 2020-08-17 18:11:56 -07:00
parent de0c7a044b
commit 1454018dc1
1 changed files with 64 additions and 28 deletions

View File

@ -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()