[cmake] Make gtest macro definitions a part the library interface

These definitions are needed by any file which uses gtest. Previously we
were adding them in the add_unittest function, but over time we've
accumulated libraries (which don't go through add_unittest) building on
gtest and this has resulted in proliferation of the definitions.

Making this a part of the library interface enables them to be managed
centrally. This follows a patch for -Wno-suggest-override (D84554) which
took a similar approach.

Differential Revision: https://reviews.llvm.org/D84748

GitOrigin-RevId: bb91c9fe7b62939fdb11ae42a31a5d5a61575ae7
diff --git a/cmake/modules/AddLLVM.cmake b/cmake/modules/AddLLVM.cmake
index ac3d5c8..7b8077e 100644
--- a/cmake/modules/AddLLVM.cmake
+++ b/cmake/modules/AddLLVM.cmake
@@ -1400,15 +1400,8 @@
     set(EXCLUDE_FROM_ALL ON)
   endif()
 
-  # Our current version of gtest uses tr1/tuple which is deprecated on MSVC.
-  # Since LLVM itself requires C++14, we can safely force it off.
-  add_definitions(-DGTEST_HAS_TR1_TUPLE=0)
-
   include_directories(${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest/include)
   include_directories(${LLVM_MAIN_SRC_DIR}/utils/unittest/googlemock/include)
-  if (NOT LLVM_ENABLE_THREADS)
-    list(APPEND LLVM_COMPILE_DEFINITIONS GTEST_HAS_PTHREAD=0)
-  endif ()
 
   if (SUPPORTS_VARIADIC_MACROS_FLAG)
     list(APPEND LLVM_COMPILE_FLAGS "-Wno-variadic-macros")
diff --git a/lib/Testing/Support/CMakeLists.txt b/lib/Testing/Support/CMakeLists.txt
index fe460ae..4f5345c 100644
--- a/lib/Testing/Support/CMakeLists.txt
+++ b/lib/Testing/Support/CMakeLists.txt
@@ -1,6 +1,3 @@
-add_definitions(-DGTEST_LANG_CXX11=1)
-add_definitions(-DGTEST_HAS_TR1_TUPLE=0)
-
 add_llvm_library(LLVMTestingSupport
   Annotations.cpp
   Error.cpp
diff --git a/utils/unittest/CMakeLists.txt b/utils/unittest/CMakeLists.txt
index e7caf37..14c7803 100644
--- a/utils/unittest/CMakeLists.txt
+++ b/utils/unittest/CMakeLists.txt
@@ -19,9 +19,6 @@
   googlemock
   )
 
-# Gtest 1.8.0 uses tr1/tuple which is deprecated on MSVC, so we force it off.
-add_definitions(-DGTEST_HAS_TR1_TUPLE=0)
-
 if(WIN32)
   add_definitions(-DGTEST_OS_WINDOWS=1)
 endif()
@@ -45,10 +42,6 @@
 set(LLVM_REQUIRES_RTTI 1)
 add_definitions( -DGTEST_HAS_RTTI=0 )
 
-if (NOT LLVM_ENABLE_THREADS)
-  add_definitions( -DGTEST_HAS_PTHREAD=0 )
-endif()
-
 find_library(LLVM_PTHREAD_LIBRARY_PATH pthread)
 if (LLVM_PTHREAD_LIBRARY_PATH)
   list(APPEND LIBS pthread)
@@ -76,6 +69,13 @@
   set_target_properties(gtest PROPERTIES INTERFACE_COMPILE_OPTIONS "-Wno-suggest-override")
 endif()
 
+# Gtest 1.8.0 uses tr1/tuple which is deprecated on MSVC, so we force it off.
+target_compile_definitions(gtest PUBLIC GTEST_HAS_TR1_TUPLE=0)
+
+if (NOT LLVM_ENABLE_THREADS)
+  target_compile_definitions(gtest PUBLIC GTEST_HAS_PTHREAD=0)
+endif ()
+
 add_subdirectory(UnitTestMain)
 
 # When LLVM_LINK_LLVM_DYLIB is enabled, libLLVM.so is added to the interface