Author: Stella Laurenzo Date: 2022-03-02T10:53:32-08:00 New Revision: 9f37775472b45986b0ecce5243bd6ce119e5bd69
URL: https://github.com/llvm/llvm-project/commit/9f37775472b45986b0ecce5243bd6ce119e5bd69 DIFF: https://github.com/llvm/llvm-project/commit/9f37775472b45986b0ecce5243bd6ce119e5bd69.diff LOG: [cmake] Prefix gtest and gtest_main with "llvm_". 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 Added: Modified: 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 Removed: ################################################################################ diff --git a/compiler-rt/lib/asan/tests/CMakeLists.txt b/compiler-rt/lib/asan/tests/CMakeLists.txt index 047a3fa282c40..b2e27f66b7312 100644 --- a/compiler-rt/lib/asan/tests/CMakeLists.txt +++ b/compiler-rt/lib/asan/tests/CMakeLists.txt @@ -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} ) diff --git a/compiler-rt/lib/fuzzer/tests/CMakeLists.txt b/compiler-rt/lib/fuzzer/tests/CMakeLists.txt index 85369990889ec..10fcfbaa083e5 100644 --- a/compiler-rt/lib/fuzzer/tests/CMakeLists.txt +++ b/compiler-rt/lib/fuzzer/tests/CMakeLists.txt @@ -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 diff --git a/compiler-rt/lib/gwp_asan/tests/CMakeLists.txt b/compiler-rt/lib/gwp_asan/tests/CMakeLists.txt index abc02a49637cc..8b4ee7d553b82 100644 --- a/compiler-rt/lib/gwp_asan/tests/CMakeLists.txt +++ b/compiler-rt/lib/gwp_asan/tests/CMakeLists.txt @@ -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 diff --git a/compiler-rt/lib/interception/tests/CMakeLists.txt b/compiler-rt/lib/interception/tests/CMakeLists.txt index 06184ee77447f..8d5c4abb7af0c 100644 --- a/compiler-rt/lib/interception/tests/CMakeLists.txt +++ b/compiler-rt/lib/interception/tests/CMakeLists.txt @@ -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() diff --git a/compiler-rt/lib/msan/tests/CMakeLists.txt b/compiler-rt/lib/msan/tests/CMakeLists.txt index dc8408042bd0b..3ed888b81c6e5 100644 --- a/compiler-rt/lib/msan/tests/CMakeLists.txt +++ b/compiler-rt/lib/msan/tests/CMakeLists.txt @@ -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} ) diff --git a/compiler-rt/lib/orc/unittests/CMakeLists.txt b/compiler-rt/lib/orc/unittests/CMakeLists.txt index 3b492196dd620..32038dbecf19a 100644 --- a/compiler-rt/lib/orc/unittests/CMakeLists.txt +++ b/compiler-rt/lib/orc/unittests/CMakeLists.txt @@ -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) diff --git a/compiler-rt/lib/sanitizer_common/tests/CMakeLists.txt b/compiler-rt/lib/sanitizer_common/tests/CMakeLists.txt index f536df885abcf..826bdc3d7c8a2 100644 --- a/compiler-rt/lib/sanitizer_common/tests/CMakeLists.txt +++ b/compiler-rt/lib/sanitizer_common/tests/CMakeLists.txt @@ -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}) diff --git a/compiler-rt/lib/scudo/standalone/tests/CMakeLists.txt b/compiler-rt/lib/scudo/standalone/tests/CMakeLists.txt index 6d0936cbb5c1e..7be58f424dd68 100644 --- a/compiler-rt/lib/scudo/standalone/tests/CMakeLists.txt +++ b/compiler-rt/lib/scudo/standalone/tests/CMakeLists.txt @@ -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}) diff --git a/compiler-rt/lib/tsan/tests/CMakeLists.txt b/compiler-rt/lib/tsan/tests/CMakeLists.txt index 0a49c238403f4..91702c913592b 100644 --- a/compiler-rt/lib/tsan/tests/CMakeLists.txt +++ b/compiler-rt/lib/tsan/tests/CMakeLists.txt @@ -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) diff --git a/compiler-rt/lib/xray/tests/CMakeLists.txt b/compiler-rt/lib/xray/tests/CMakeLists.txt index 99884b05d77e4..1d698391fe025 100644 --- a/compiler-rt/lib/xray/tests/CMakeLists.txt +++ b/compiler-rt/lib/xray/tests/CMakeLists.txt @@ -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} ) diff --git a/flang/CMakeLists.txt b/flang/CMakeLists.txt index 5caa79e8da477..e6ebd26203a10 100644 --- a/flang/CMakeLists.txt +++ b/flang/CMakeLists.txt @@ -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 diff --git a/libc/benchmarks/CMakeLists.txt b/libc/benchmarks/CMakeLists.txt index 54f70c4b033e9..0e9ec5a1f790c 100644 --- a/libc/benchmarks/CMakeLists.txt +++ b/libc/benchmarks/CMakeLists.txt @@ -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}) diff --git a/libc/test/utils/tools/CMakeLists.txt b/libc/test/utils/tools/CMakeLists.txt index 0e343f154eac5..d685f27754cd4 100644 --- a/libc/test/utils/tools/CMakeLists.txt +++ b/libc/test/utils/tools/CMakeLists.txt @@ -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}) diff --git a/lldb/unittests/CMakeLists.txt b/lldb/unittests/CMakeLists.txt index e7b0f1c17d6d1..79afbbf1f8f54 100644 --- a/lldb/unittests/CMakeLists.txt +++ b/lldb/unittests/CMakeLists.txt @@ -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. diff --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake index 37bc98f9e021e..6827970254201 100644 --- a/llvm/cmake/modules/AddLLVM.cmake +++ b/llvm/cmake/modules/AddLLVM.cmake @@ -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) diff --git a/llvm/lib/Testing/Support/CMakeLists.txt b/llvm/lib/Testing/Support/CMakeLists.txt index 1830ea88bb3fa..81774eb171caa 100644 --- a/llvm/lib/Testing/Support/CMakeLists.txt +++ b/llvm/lib/Testing/Support/CMakeLists.txt @@ -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 diff --git a/llvm/runtimes/CMakeLists.txt b/llvm/runtimes/CMakeLists.txt index 11391fa7ed89a..b99cb377e75a7 100644 --- a/llvm/runtimes/CMakeLists.txt +++ b/llvm/runtimes/CMakeLists.txt @@ -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}) diff --git a/llvm/unittests/Support/CommandLineInit/CMakeLists.txt b/llvm/unittests/Support/CommandLineInit/CMakeLists.txt index a69182f646980..1889c8fba9a7a 100644 --- a/llvm/unittests/Support/CommandLineInit/CMakeLists.txt +++ b/llvm/unittests/Support/CommandLineInit/CMakeLists.txt @@ -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}) diff --git a/llvm/utils/unittest/CMakeLists.txt b/llvm/utils/unittest/CMakeLists.txt index 90037ae2e44bf..9dd7b5379f308 100644 --- a/llvm/utils/unittest/CMakeLists.txt +++ b/llvm/utils/unittest/CMakeLists.txt @@ -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) diff --git a/llvm/utils/unittest/UnitTestMain/CMakeLists.txt b/llvm/utils/unittest/UnitTestMain/CMakeLists.txt index 32f0f25a60ffc..7a3ac8a0f43e6 100644 --- a/llvm/utils/unittest/UnitTestMain/CMakeLists.txt +++ b/llvm/utils/unittest/UnitTestMain/CMakeLists.txt @@ -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 _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits