The upstream project ships CMake rules for building vanilla gtest/gmock which conflict with the names chosen by LLVM. Since LLVM's build rules here are quite specific to LLVM, prefixing them to avoid collision is the right thing (i.e. there does not appear to be a path to letting someone *replace* LLVM's googletest with one they bring, so co-existence should be the goal).
This allows LLVM to be included with testing enabled within projects that themselves have a dependency on an official gtest release.
Reviewed By: mehdi_amini
Differential Revision: https://reviews.llvm.org/D120789
function(generate_asan_tests test_objects test_suite testname)
generate_compiler_rt_tests(${test_objects} ${test_suite} ${testname} ${arch}
COMPILE_DEPS ${ASAN_UNITTEST_HEADERS} ${ASAN_IGNORELIST_FILE}
- DEPS gtest asan
+ DEPS llvm_gtest asan
KIND ${TEST_KIND}
${ARGN}
)
FuzzerUnitTests "Fuzzer-${arch}-Test" ${arch}
SOURCES FuzzerUnittest.cpp ${COMPILER_RT_GTEST_SOURCE}
RUNTIME ${LIBFUZZER_TEST_RUNTIME}
- DEPS gtest ${LIBFUZZER_TEST_RUNTIME_DEPS}
+ DEPS llvm_gtest ${LIBFUZZER_TEST_RUNTIME_DEPS}
CFLAGS ${LIBFUZZER_UNITTEST_CFLAGS} ${LIBFUZZER_TEST_RUNTIME_CFLAGS}
LINK_FLAGS ${LIBFUZZER_UNITTEST_LINK_FLAGS} ${LIBFUZZER_TEST_RUNTIME_LINK_FLAGS})
set_target_properties(FuzzerUnitTests PROPERTIES
generate_compiler_rt_tests(FuzzedDataProviderTestObjects
FuzzedDataProviderUnitTests "FuzzerUtils-${arch}-Test" ${arch}
SOURCES FuzzedDataProviderUnittest.cpp ${COMPILER_RT_GTEST_SOURCE}
- DEPS gtest ${LIBFUZZER_TEST_RUNTIME_DEPS} ${COMPILER_RT_SOURCE_DIR}/include/fuzzer/FuzzedDataProvider.h
+ DEPS llvm_gtest ${LIBFUZZER_TEST_RUNTIME_DEPS} ${COMPILER_RT_SOURCE_DIR}/include/fuzzer/FuzzedDataProvider.h
CFLAGS ${LIBFUZZER_UNITTEST_CFLAGS} ${LIBFUZZER_TEST_RUNTIME_CFLAGS}
LINK_FLAGS ${LIBFUZZER_UNITTEST_LINK_FLAGS} ${LIBFUZZER_TEST_RUNTIME_LINK_FLAGS})
set_target_properties(FuzzedDataProviderUnitTests PROPERTIES
GwpAsanUnitTests "GwpAsan-${arch}-Test" ${arch}
SOURCES ${GWP_ASAN_UNITTESTS} ${COMPILER_RT_GTEST_SOURCE}
RUNTIME ${GWP_ASAN_TEST_RUNTIME}
- DEPS gtest ${GWP_ASAN_UNIT_TEST_HEADERS}
+ DEPS llvm_gtest ${GWP_ASAN_UNIT_TEST_HEADERS}
CFLAGS ${GWP_ASAN_UNITTEST_CFLAGS}
LINK_FLAGS ${GWP_ASAN_UNITTEST_LINK_FLAGS})
set_target_properties(GwpAsanUnitTests PROPERTIES
RUNTIME ${INTERCEPTION_COMMON_LIB}
SOURCES ${INTERCEPTION_UNITTESTS} ${COMPILER_RT_GTEST_SOURCE}
COMPILE_DEPS ${INTERCEPTION_TEST_HEADERS}
- DEPS gtest
+ DEPS llvm_gtest
CFLAGS ${INTERCEPTION_TEST_CFLAGS_COMMON}
LINK_FLAGS ${INTERCEPTION_TEST_LINK_FLAGS_COMMON})
endmacro()
${obj_list} ${source} ${arch}
KIND ${kind}
COMPILE_DEPS ${MSAN_UNITTEST_HEADERS}
- DEPS gtest msan
+ DEPS llvm_gtest msan
CFLAGS -isystem ${CMAKE_CURRENT_BINARY_DIR}/../libcxx_msan_${arch}/include/c++/v1
${MSAN_UNITTEST_INSTRUMENTED_CFLAGS} ${cflags}
)
append_list_if(COMPILER_RT_HAS_LIBEXECINFO -lexecinfo ORC_UNITTEST_LINK_FLAGS)
endif()
-set(ORC_DEPS gtest orc)
+set(ORC_DEPS llvm_gtest orc)
# ORC uses C++ standard library headers.
if (TARGET cxx-headers OR HAVE_LIBCXX)
set(ORC_DEPS cxx-headers)
RUNTIME "${SANITIZER_COMMON_LIB}"
SOURCES ${SANITIZER_UNITTESTS} ${COMPILER_RT_GTEST_SOURCE} ${COMPILER_RT_GMOCK_SOURCE}
COMPILE_DEPS ${SANITIZER_TEST_HEADERS}
- DEPS gtest
+ DEPS llvm_gtest
CFLAGS ${SANITIZER_TEST_CFLAGS_COMMON} ${extra_flags}
LINK_FLAGS ${SANITIZER_TEST_LINK_FLAGS_COMMON} ${TARGET_LINK_FLAGS} ${extra_flags})
"${testname}-${arch}-Test" ${arch}
SOURCES ${TEST_SOURCES} ${COMPILER_RT_GTEST_SOURCE}
COMPILE_DEPS ${SCUDO_TEST_HEADERS}
- DEPS gtest scudo_standalone
+ DEPS llvm_gtest scudo_standalone
RUNTIME ${RUNTIME}
CFLAGS ${SCUDO_UNITTEST_CFLAGS}
LINK_FLAGS ${LINK_FLAGS})
list(APPEND TSAN_RTL_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/../${header})
endforeach()
-set(TSAN_DEPS gtest tsan)
+set(TSAN_DEPS llvm_gtest tsan)
# TSan uses C++ standard library headers.
if (TARGET cxx-headers OR HAVE_LIBCXX)
set(TSAN_DEPS cxx-headers)
${XRAY_HEADERS} ${XRAY_ALL_SOURCE_FILES_ABS_PATHS}
"test_helpers.h"
RUNTIME "${XRAY_RUNTIME_LIBS}"
- DEPS gtest xray llvm-xray LLVMXRay LLVMTestingSupport
+ DEPS llvm_gtest xray llvm-xray LLVMXRay LLVMTestingSupport
CFLAGS ${XRAY_UNITTEST_CFLAGS}
LINK_FLAGS ${TARGET_LINK_FLAGS} ${XRAY_UNITTEST_LINK_FLAGS}
)
if (FLANG_INCLUDE_TESTS)
set(UNITTEST_DIR ${LLVM_BUILD_MAIN_SRC_DIR}/utils/unittest)
if(EXISTS ${UNITTEST_DIR}/googletest/include/gtest/gtest.h)
- if (NOT TARGET gtest)
- add_library(gtest
+ if (NOT TARGET llvm_gtest)
+ add_library(llvm_gtest
${UNITTEST_DIR}/googletest/src/gtest-all.cc
${UNITTEST_DIR}/googlemock/src/gmock-all.cc
)
- target_include_directories(gtest
+ target_include_directories(llvm_gtest
PUBLIC
"${UNITTEST_DIR}/googletest/include"
"${UNITTEST_DIR}/googlemock/include"
"${UNITTEST_DIR}/googlemock"
)
find_package(Threads)
- target_link_libraries(gtest PUBLIC Threads::Threads)
- add_library(gtest_main ${UNITTEST_DIR}/UnitTestMain/TestMain.cpp)
- target_link_libraries(gtest_main PUBLIC gtest)
+ target_link_libraries(llvm_gtest PUBLIC Threads::Threads)
+ add_library(llvm_gtest_main ${UNITTEST_DIR}/UnitTestMain/TestMain.cpp)
+ target_link_libraries(gtest_main PUBLIC llvm_gtest)
endif()
set(FLANG_GTEST_AVAIL 1)
else()
PATTERN "config.h" EXCLUDE
PATTERN ".git" EXCLUDE
PATTERN "CMakeFiles" EXCLUDE)
-
+
install(DIRECTORY ${FLANG_INCLUDE_DIR}/flang
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
COMPONENT flang-headers
)
target_link_libraries(${target_name}
PRIVATE
- gtest_main
- gtest
+ llvm_gtest_main
+ llvm_gtest
${LIBC_BENCHMARKS_UNITTEST_DEPENDS}
)
llvm_update_compile_flags(${target_name})
)
target_link_libraries(${target_name}
PRIVATE
- gtest_main
- gtest
+ llvm_gtest_main
+ llvm_gtest
${LIBC_TOOL_UNITTEST_DEPENDS}
)
add_custom_command(
TARGET ${target_name}
POST_BUILD
- COMMAND $<TARGET_FILE:${target_name}>
+ COMMAND $<TARGET_FILE:${target_name}>
${LIBC_TOOL_UNITTEST_ARGS}
)
add_dependencies(libc-tool-unittests ${target_name})
if (LLDB_BUILT_STANDALONE)
# Build the gtest library needed for unittests, if we have LLVM sources
# handy.
- if (EXISTS ${LLVM_MAIN_SRC_DIR}/utils/unittest AND NOT TARGET gtest)
+ if (EXISTS ${LLVM_MAIN_SRC_DIR}/utils/unittest AND NOT TARGET llvm_gtest)
add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/unittest utils/unittest)
endif()
# LLVMTestingSupport library is needed for Process/gdb-remote.
# libpthreads overrides some standard library symbols, so main
# executable must be linked with it in order to provide consistent
# API for all shared libaries loaded by this executable.
- target_link_libraries(${test_name} PRIVATE gtest_main gtest ${LLVM_PTHREAD_LIB})
+ target_link_libraries(${test_name} PRIVATE llvm_gtest_main llvm_gtest ${LLVM_PTHREAD_LIB})
add_dependencies(${test_suite} ${test_name})
get_target_property(test_suite_folder ${test_suite} FOLDER)
Support
)
-target_link_libraries(LLVMTestingSupport PRIVATE gtest)
+target_link_libraries(LLVMTestingSupport PRIVATE llvm_gtest)
# This is to avoid the error in gtest-death-test-internal.h
# (150,16): error: 'Create' overrides a member function but
obj2yaml
sancov
sanstats
- gtest_main
- gtest
+ llvm_gtest_main
+ llvm_gtest
)
foreach(target ${test_targets} ${SUB_CHECK_TARGETS})
add_dependencies(${target} ${RUNTIMES_TEST_DEPENDS})
IGNORE_EXTERNALIZE_DEBUGINFO NO_INSTALL_RPATH
CommandLineInitTest.cpp)
-target_link_libraries(${test_name} PRIVATE gtest)
+target_link_libraries(${test_name} PRIVATE llvm_gtest)
add_dependencies(${test_suite} ${test_name})
list(APPEND LIBS pthread)
endif()
-add_llvm_library(gtest
+add_llvm_library(llvm_gtest
googletest/src/gtest-all.cc
googlemock/src/gmock-all.cc
# that warning here for any targets that link to gtest.
if(CXX_SUPPORTS_SUGGEST_OVERRIDE_FLAG)
add_definitions("-Wno-suggest-override")
- set_target_properties(gtest PROPERTIES INTERFACE_COMPILE_OPTIONS "-Wno-suggest-override")
+ set_target_properties(llvm_gtest PROPERTIES INTERFACE_COMPILE_OPTIONS "-Wno-suggest-override")
endif()
if (NOT LLVM_ENABLE_THREADS)
- target_compile_definitions(gtest PUBLIC GTEST_HAS_PTHREAD=0)
+ target_compile_definitions(llvm_gtest PUBLIC GTEST_HAS_PTHREAD=0)
endif ()
-target_include_directories(gtest
+target_include_directories(llvm_gtest
PUBLIC googletest/include googlemock/include
PRIVATE googletest googlemock
)
endif()
endfunction()
-gtest_remove_dylib_from_link_interface(gtest)
-gtest_remove_dylib_from_link_interface(gtest_main)
+gtest_remove_dylib_from_link_interface(llvm_gtest)
+gtest_remove_dylib_from_link_interface(llvm_gtest_main)
-add_llvm_library(gtest_main
+add_llvm_library(llvm_gtest_main
TestMain.cpp
LINK_LIBS
- gtest
+ llvm_gtest
LINK_COMPONENTS
Support # Depends on llvm::cl