[Lldb-commits] [lldb] bb91c9f - [cmake] Make gtest macro definitions a part the library interface

Pavel Labath via lldb-commits lldb-commits at lists.llvm.org
Tue Aug 11 06:22:59 PDT 2020


Author: Pavel Labath
Date: 2020-08-11T15:22:44+02:00
New Revision: bb91c9fe7b62939fdb11ae42a31a5d5a61575ae7

URL: https://github.com/llvm/llvm-project/commit/bb91c9fe7b62939fdb11ae42a31a5d5a61575ae7
DIFF: https://github.com/llvm/llvm-project/commit/bb91c9fe7b62939fdb11ae42a31a5d5a61575ae7.diff

LOG: [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

Added: 
    

Modified: 
    lldb/unittests/TestingSupport/Symbol/CMakeLists.txt
    llvm/cmake/modules/AddLLVM.cmake
    llvm/lib/Testing/Support/CMakeLists.txt
    llvm/utils/unittest/CMakeLists.txt

Removed: 
    


################################################################################
diff  --git a/lldb/unittests/TestingSupport/Symbol/CMakeLists.txt b/lldb/unittests/TestingSupport/Symbol/CMakeLists.txt
index c9891f2b0777..3faec7c8030b 100644
--- a/lldb/unittests/TestingSupport/Symbol/CMakeLists.txt
+++ b/lldb/unittests/TestingSupport/Symbol/CMakeLists.txt
@@ -3,13 +3,6 @@ add_lldb_library(lldbSymbolHelpers
   YAMLModuleTester.cpp
   )
 
-# Our current version of gtest does not properly recognize C++11 support
-# with MSVC, so it falls back to tr1 / experimental classes.  Since LLVM
-# itself requires C++11, we can safely force it on unconditionally so that
-# we don't have to fight with the buggy gtest check.
-target_compile_definitions(lldbSymbolHelpers PUBLIC
-  -DGTEST_LANG_CXX11=1
-  -DGTEST_HAS_TR1_TUPLE=0)
 target_include_directories(lldbSymbolHelpers PUBLIC
   ${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest/include
   ${LLVM_MAIN_SRC_DIR}/utils/unittest/googlemock/include)

diff  --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake
index ac3d5c8e3c7d..7b8077efab51 100644
--- a/llvm/cmake/modules/AddLLVM.cmake
+++ b/llvm/cmake/modules/AddLLVM.cmake
@@ -1400,15 +1400,8 @@ function(add_unittest test_suite test_name)
     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/llvm/lib/Testing/Support/CMakeLists.txt b/llvm/lib/Testing/Support/CMakeLists.txt
index fe460aeefc91..4f5345c1dc57 100644
--- a/llvm/lib/Testing/Support/CMakeLists.txt
+++ b/llvm/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/llvm/utils/unittest/CMakeLists.txt b/llvm/utils/unittest/CMakeLists.txt
index e7caf37727fc..14c780342b60 100644
--- a/llvm/utils/unittest/CMakeLists.txt
+++ b/llvm/utils/unittest/CMakeLists.txt
@@ -19,9 +19,6 @@ include_directories(
   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 @@ endif()
 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 @@ if(CXX_SUPPORTS_SUGGEST_OVERRIDE_FLAG)
   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


        


More information about the lldb-commits mailing list