[cmake] Prefix gtest and gtest_main with "llvm_".
authorStella Laurenzo <stellaraccident@gmail.com>
Wed, 2 Mar 2022 18:17:05 +0000 (10:17 -0800)
committerStella Laurenzo <laurenzo@google.com>
Wed, 2 Mar 2022 18:53:32 +0000 (10:53 -0800)
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

20 files changed:
compiler-rt/lib/asan/tests/CMakeLists.txt
compiler-rt/lib/fuzzer/tests/CMakeLists.txt
compiler-rt/lib/gwp_asan/tests/CMakeLists.txt
compiler-rt/lib/interception/tests/CMakeLists.txt
compiler-rt/lib/msan/tests/CMakeLists.txt
compiler-rt/lib/orc/unittests/CMakeLists.txt
compiler-rt/lib/sanitizer_common/tests/CMakeLists.txt
compiler-rt/lib/scudo/standalone/tests/CMakeLists.txt
compiler-rt/lib/tsan/tests/CMakeLists.txt
compiler-rt/lib/xray/tests/CMakeLists.txt
flang/CMakeLists.txt
libc/benchmarks/CMakeLists.txt
libc/test/utils/tools/CMakeLists.txt
lldb/unittests/CMakeLists.txt
llvm/cmake/modules/AddLLVM.cmake
llvm/lib/Testing/Support/CMakeLists.txt
llvm/runtimes/CMakeLists.txt
llvm/unittests/Support/CommandLineInit/CMakeLists.txt
llvm/utils/unittest/CMakeLists.txt
llvm/utils/unittest/UnitTestMain/CMakeLists.txt

index 047a3fa..b2e27f6 100644 (file)
@@ -172,7 +172,7 @@ function(add_asan_tests arch test_runtime)
   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}
       )
index 8536999..10fcfba 100644 (file)
@@ -74,7 +74,7 @@ if(COMPILER_RT_DEFAULT_TARGET_ARCH IN_LIST FUZZER_SUPPORTED_ARCH)
     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
@@ -84,7 +84,7 @@ if(COMPILER_RT_DEFAULT_TARGET_ARCH IN_LIST FUZZER_SUPPORTED_ARCH)
   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
index abc02a4..8b4ee7d 100644 (file)
@@ -66,7 +66,7 @@ if(COMPILER_RT_DEFAULT_TARGET_ARCH IN_LIST GWP_ASAN_SUPPORTED_ARCH)
     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
index 06184ee..8d5c4ab 100644 (file)
@@ -95,7 +95,7 @@ macro(add_interception_tests_for_arch arch)
     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()
index dc84080..3ed888b 100644 (file)
@@ -66,7 +66,7 @@ macro(msan_compile obj_list source arch kind cflags)
     ${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}
   )
index 3b49219..32038db 100644 (file)
@@ -52,7 +52,7 @@ else()
   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)
index f536df8..826bdc3 100644 (file)
@@ -163,7 +163,7 @@ macro(add_sanitizer_tests_for_arch arch)
     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})
 
index 6d0936c..7be58f4 100644 (file)
@@ -73,7 +73,7 @@ macro(add_scudo_unittest testname)
         "${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})
index 0a49c23..91702c9 100644 (file)
@@ -62,7 +62,7 @@ foreach (header ${TSAN_HEADERS})
   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)
index 99884b0..1d69839 100644 (file)
@@ -102,7 +102,7 @@ macro(add_xray_unittest testname)
         ${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}
         )
index 5caa79e..e6ebd26 100644 (file)
@@ -148,12 +148,12 @@ if (FLANG_STANDALONE_BUILD)
   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"
@@ -163,9 +163,9 @@ if (FLANG_STANDALONE_BUILD)
           "${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()
@@ -467,7 +467,7 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
     PATTERN "config.h" EXCLUDE
     PATTERN ".git"     EXCLUDE
     PATTERN "CMakeFiles" EXCLUDE)
-    
+
   install(DIRECTORY ${FLANG_INCLUDE_DIR}/flang
     DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
     COMPONENT flang-headers
index 54f70c4..0e9ec5a 100644 (file)
@@ -25,8 +25,8 @@ function(add_libc_benchmark_unittest target_name)
   )
   target_link_libraries(${target_name}
     PRIVATE
-    gtest_main
-    gtest
+    llvm_gtest_main
+    llvm_gtest
     ${LIBC_BENCHMARKS_UNITTEST_DEPENDS}
   )
   llvm_update_compile_flags(${target_name})
index 0e343f1..d685f27 100644 (file)
@@ -16,15 +16,15 @@ function(add_libc_tool_unittest 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})
index e7b0f1c..79afbbf 100644 (file)
@@ -20,7 +20,7 @@ endif ()
 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.
index 37bc98f..6827970 100644 (file)
@@ -1502,7 +1502,7 @@ function(add_unittest test_suite test_name)
   # 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)
index 1830ea8..81774eb 100644 (file)
@@ -12,7 +12,7 @@ add_llvm_library(LLVMTestingSupport
   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
index 11391fa..b99cb37 100644 (file)
@@ -480,8 +480,8 @@ if(runtimes)
         obj2yaml
         sancov
         sanstats
-        gtest_main
-        gtest
+        llvm_gtest_main
+        llvm_gtest
       )
     foreach(target ${test_targets} ${SUB_CHECK_TARGETS})
       add_dependencies(${target} ${RUNTIMES_TEST_DEPENDS})
index a69182f..1889c8f 100644 (file)
@@ -26,7 +26,7 @@ add_llvm_executable(${test_name}
   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})
 
index 90037ae..9dd7b53 100644 (file)
@@ -39,7 +39,7 @@ if (LLVM_PTHREAD_LIBRARY_PATH)
   list(APPEND LIBS pthread)
 endif()
 
-add_llvm_library(gtest
+add_llvm_library(llvm_gtest
   googletest/src/gtest-all.cc
   googlemock/src/gmock-all.cc
 
@@ -58,14 +58,14 @@ add_llvm_library(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(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
   )
@@ -89,5 +89,5 @@ function (gtest_remove_dylib_from_link_interface target)
   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)
index 32f0f25..7a3ac8a 100644 (file)
@@ -1,8 +1,8 @@
-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