[PATCH] D120789: [cmake] Prefix gtest and gtest_main with "llvm_".

Stella Laurenzo via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 1 20:40:51 PST 2022


stellaraccident created this revision.
Herald added a subscriber: mgorny.
Herald added a project: All.
stellaraccident requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120789

Files:
  llvm/cmake/modules/AddLLVM.cmake
  llvm/utils/unittest/CMakeLists.txt
  llvm/utils/unittest/UnitTestMain/CMakeLists.txt


Index: llvm/utils/unittest/UnitTestMain/CMakeLists.txt
===================================================================
--- llvm/utils/unittest/UnitTestMain/CMakeLists.txt
+++ 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
Index: llvm/utils/unittest/CMakeLists.txt
===================================================================
--- llvm/utils/unittest/CMakeLists.txt
+++ llvm/utils/unittest/CMakeLists.txt
@@ -39,7 +39,7 @@
   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 @@
 # 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 @@
   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: llvm/cmake/modules/AddLLVM.cmake
===================================================================
--- llvm/cmake/modules/AddLLVM.cmake
+++ llvm/cmake/modules/AddLLVM.cmake
@@ -1502,7 +1502,7 @@
   # 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)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D120789.412314.patch
Type: text/x-patch
Size: 2419 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220302/b6d1a0cf/attachment.bin>


More information about the llvm-commits mailing list