aboutsummaryrefslogtreecommitdiff
path: root/third-party
diff options
context:
space:
mode:
Diffstat (limited to 'third-party')
-rw-r--r--third-party/benchmark/bindings/python/build_defs.bzl4
-rw-r--r--third-party/benchmark/include/benchmark/benchmark.h10
-rw-r--r--third-party/unittest/CMakeLists.txt95
-rw-r--r--third-party/unittest/UnitTestMain/CMakeLists.txt16
4 files changed, 84 insertions, 41 deletions
diff --git a/third-party/benchmark/bindings/python/build_defs.bzl b/third-party/benchmark/bindings/python/build_defs.bzl
index b0c1b0f..d520eda6 100644
--- a/third-party/benchmark/bindings/python/build_defs.bzl
+++ b/third-party/benchmark/bindings/python/build_defs.bzl
@@ -2,6 +2,8 @@
This file contains some build definitions for C++ extensions used in the Google Benchmark Python bindings.
"""
+load("//third_party/bazel_rules/rules_cc/cc:cc_binary.bzl", "cc_binary")
+
_SHARED_LIB_SUFFIX = {
"//conditions:default": ".so",
"//:windows": ".dll",
@@ -10,7 +12,7 @@ _SHARED_LIB_SUFFIX = {
def py_extension(name, srcs, hdrs = [], copts = [], features = [], deps = []):
for shared_lib_suffix in _SHARED_LIB_SUFFIX.values():
shared_lib_name = name + shared_lib_suffix
- native.cc_binary(
+ cc_binary(
name = shared_lib_name,
linkshared = True,
linkstatic = True,
diff --git a/third-party/benchmark/include/benchmark/benchmark.h b/third-party/benchmark/include/benchmark/benchmark.h
index 08cfe29..c2debb2 100644
--- a/third-party/benchmark/include/benchmark/benchmark.h
+++ b/third-party/benchmark/include/benchmark/benchmark.h
@@ -250,6 +250,10 @@ BENCHMARK(BM_test)->Unit(benchmark::kMillisecond);
_Pragma("GCC diagnostic push") \
_Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
#define BENCHMARK_RESTORE_DEPRECATED_WARNING _Pragma("GCC diagnostic pop")
+#define BENCHMARK_DISABLE_PEDANTIC_WARNING \
+ _Pragma("GCC diagnostic push") \
+ _Pragma("GCC diagnostic ignored \"-Wpedantic\"")
+#define BENCHMARK_RESTORE_PEDANTIC_WARNING _Pragma("GCC diagnostic pop")
#elif defined(__NVCOMPILER)
#define BENCHMARK_BUILTIN_EXPECT(x, y) __builtin_expect(x, y)
#define BENCHMARK_DEPRECATED_MSG(msg) __attribute__((deprecated(msg)))
@@ -257,6 +261,8 @@ BENCHMARK(BM_test)->Unit(benchmark::kMillisecond);
_Pragma("diagnostic push") \
_Pragma("diag_suppress deprecated_entity_with_custom_message")
#define BENCHMARK_RESTORE_DEPRECATED_WARNING _Pragma("diagnostic pop")
+#define BENCHMARK_DISABLE_PEDANTIC_WARNING
+#define BENCHMARK_RESTORE_PEDANTIC_WARNING
#else
#define BENCHMARK_BUILTIN_EXPECT(x, y) x
#define BENCHMARK_DEPRECATED_MSG(msg)
@@ -265,6 +271,8 @@ BENCHMARK(BM_test)->Unit(benchmark::kMillisecond);
__LINE__) ") : warning note: " msg))
#define BENCHMARK_DISABLE_DEPRECATED_WARNING
#define BENCHMARK_RESTORE_DEPRECATED_WARNING
+#define BENCHMARK_DISABLE_PEDANTIC_WARNING
+#define BENCHMARK_RESTORE_PEDANTIC_WARNING
#endif
// clang-format on
@@ -1462,11 +1470,13 @@ class Fixture : public internal::Benchmark {
// Check that __COUNTER__ is defined and that __COUNTER__ increases by 1
// every time it is expanded. X + 1 == X + 0 is used in case X is defined to be
// empty. If X is empty the expression becomes (+1 == +0).
+BENCHMARK_DISABLE_PEDANTIC_WARNING
#if defined(__COUNTER__) && (__COUNTER__ + 1 == __COUNTER__ + 0)
#define BENCHMARK_PRIVATE_UNIQUE_ID __COUNTER__
#else
#define BENCHMARK_PRIVATE_UNIQUE_ID __LINE__
#endif
+BENCHMARK_RESTORE_PEDANTIC_WARNING
// Helpers for generating unique variable names
#ifdef BENCHMARK_HAS_CXX11
diff --git a/third-party/unittest/CMakeLists.txt b/third-party/unittest/CMakeLists.txt
index 3fa885a..79535a1 100644
--- a/third-party/unittest/CMakeLists.txt
+++ b/third-party/unittest/CMakeLists.txt
@@ -11,6 +11,34 @@
#
# Project-wide settings
+set(LLVM_SUBPROJECT_TITLE "Third-Party/Google Test")
+
+if(LLVM_RUNTIMES_BUILD)
+ # This instance of GTest is use for unittests for the runtime libraries. It
+ # must not link to LLVMSupport (used for llvm::raw_ostream and llvm::cl
+ # support) of the host build: It may be a different architecture and/or
+ # using a different C++ ABI such as libcxx/libstdc++.
+ set(GTEST_LLVM_COMPONENTS "")
+
+ # We cannot use llvm_gtest for the target; it would clash with
+ # find_package(LLVM) with LLVM_EXPORT_GTEST=ON. Instead, we define an alias
+ # default_gtest that points to llvm_gtest in the LLVM build and
+ # runtimes_gtest in an runtimes build.
+ set(gtest_name "runtimes_gtest")
+
+ # Override locally; never install the runtimes-GTest.
+ set(LLVM_INSTALL_GTEST OFF)
+
+ # Build the library containing main() so unittests need less boilerplate.
+ # UnitTestMain/TestMain.cpp always needs LLVMSupport, use GTest's original
+ # main when unavailable.
+ set(gtest_main_src googletest/src/gtest_main.cc)
+else()
+ set(GTEST_LLVM_COMPONENTS "Support")
+ set(gtest_name "llvm_gtest")
+ set(gtest_main_src UnitTestMain/TestMain.cpp)
+endif()
+
if(WIN32)
add_definitions(-DGTEST_OS_WINDOWS=1)
endif()
@@ -38,17 +66,13 @@ if (HAVE_LIBPTHREAD)
list(APPEND LIBS pthread)
endif()
-# Make available for runtimes using the LLVM buildtree
-# (required for unittests in bootstrapping builds)
-set(EXCLUDE_FROM_ALL OFF)
-
# Install GTest only if requested.
set(BUILDTREE_ONLY BUILDTREE_ONLY)
if (LLVM_INSTALL_GTEST)
set(BUILDTREE_ONLY "")
endif ()
-add_llvm_library(llvm_gtest
+add_llvm_library("${gtest_name}"
googletest/src/gtest-all.cc
googlemock/src/gmock-all.cc
@@ -56,7 +80,7 @@ add_llvm_library(llvm_gtest
${LIBS}
LINK_COMPONENTS
- Support # Depends on llvm::raw_ostream
+ ${GTEST_LLVM_COMPONENTS}
# This is a library meant only for the build tree.
${BUILDTREE_ONLY}
@@ -67,15 +91,14 @@ add_llvm_library(llvm_gtest
# that warning here for any targets that link to gtest.
if(CXX_SUPPORTS_SUGGEST_OVERRIDE_FLAG)
add_definitions("-Wno-suggest-override")
- set_target_properties(llvm_gtest PROPERTIES INTERFACE_COMPILE_OPTIONS "-Wno-suggest-override")
+ set_target_properties("${gtest_name}" PROPERTIES INTERFACE_COMPILE_OPTIONS "-Wno-suggest-override")
endif()
if (NOT LLVM_ENABLE_THREADS)
- target_compile_definitions(llvm_gtest PUBLIC GTEST_HAS_PTHREAD=0)
+ target_compile_definitions("${gtest_name}" PUBLIC GTEST_HAS_PTHREAD=0)
endif ()
-# Top-level include directory required for "llvm/Support/raw_os_ostream.h"
-target_include_directories(llvm_gtest
+target_include_directories("${gtest_name}"
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/googletest/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/googlemock/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/>
@@ -84,21 +107,36 @@ target_include_directories(llvm_gtest
PRIVATE googletest googlemock
)
-# When used from the buildtree, also force use of buildtree LLVM headers,
-# (instead locally installed version)
-# FIXME: Shouldn't this be done for all LLVM libraries? Currently, LLVM uses a
-# big giant `include_directories( ${LLVM_INCLUDE_DIR} ${LLVM_MAIN_INCLUDE_DIR})`
-# which CMake does not add to the import library.
-target_include_directories(llvm_gtest BEFORE
- PUBLIC $<BUILD_INTERFACE:${LLVM_SOURCE_DIR}/include>
- $<BUILD_INTERFACE:${LLVM_BINARY_DIR}/include>
- )
+if(LLVM_RUNTIMES_BUILD)
+ target_compile_definitions("${gtest_name}" PUBLIC GTEST_NO_LLVM_SUPPORT=1)
+else()
+ # When used from the buildtree, also force use of buildtree LLVM headers,
+ # (instead locally installed version)
+ # FIXME: Shouldn't this be done for all LLVM libraries? Currently, LLVM uses a
+ # big giant `include_directories( ${LLVM_INCLUDE_DIR} ${LLVM_MAIN_INCLUDE_DIR})`
+ # which CMake does not add to the import library.
+ target_include_directories("${gtest_name}" BEFORE
+ PUBLIC $<BUILD_INTERFACE:${LLVM_SOURCE_DIR}/include>
+ $<BUILD_INTERFACE:${LLVM_BINARY_DIR}/include>
+ )
+endif()
+
-add_subdirectory(UnitTestMain)
+add_llvm_library("${gtest_name}_main"
+ ${gtest_main_src}
+
+ LINK_LIBS
+ "${gtest_name}"
+
+ LINK_COMPONENTS
+ ${GTEST_LLVM_COMPONENTS}
+
+ ${BUILDTREE_ONLY}
+)
if (LLVM_INSTALL_GTEST)
- install(DIRECTORY googletest/include/gtest/ DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/llvm-gtest/gtest/" COMPONENT llvm_gtest)
- install(DIRECTORY googlemock/include/gmock/ DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/llvm-gmock/gmock/" COMPONENT llvm_gtest)
+ install(DIRECTORY googletest/include/gtest/ DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/llvm-gtest/gtest/" COMPONENT "${gtest_name}")
+ install(DIRECTORY googlemock/include/gmock/ DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/llvm-gmock/gmock/" COMPONENT "${gtest_name}")
endif()
# When LLVM_LINK_LLVM_DYLIB is enabled, libLLVM.so is added to the interface
@@ -118,5 +156,14 @@ function (gtest_remove_dylib_from_link_interface target)
endif()
endfunction()
-gtest_remove_dylib_from_link_interface(llvm_gtest)
-gtest_remove_dylib_from_link_interface(llvm_gtest_main)
+if (NOT LLVM_RUNTIMES_BUILD)
+ gtest_remove_dylib_from_link_interface("${gtest_name}")
+ gtest_remove_dylib_from_link_interface("${gtest_name}_main")
+endif ()
+
+# The build processing this file always uses this GTest for unittests.
+# Projects that do not use the LLVM_ENABLE_PROJECTS mechanism, but are
+# standalone-builds using find_package(LLVM) can define these aliases
+# explicitly.
+add_library(default_gtest ALIAS "${gtest_name}")
+add_library(default_gtest_main ALIAS "${gtest_name}_main")
diff --git a/third-party/unittest/UnitTestMain/CMakeLists.txt b/third-party/unittest/UnitTestMain/CMakeLists.txt
deleted file mode 100644
index 729ea7e..0000000
--- a/third-party/unittest/UnitTestMain/CMakeLists.txt
+++ /dev/null
@@ -1,16 +0,0 @@
-set(BUILDTREE_ONLY BUILDTREE_ONLY)
-if (LLVM_INSTALL_GTEST)
- set(BUILDTREE_ONLY "")
-endif ()
-
-add_llvm_library(llvm_gtest_main
- TestMain.cpp
-
- LINK_LIBS
- llvm_gtest
-
- LINK_COMPONENTS
- Support # Depends on llvm::cl
-
- ${BUILDTREE_ONLY}
- )