labath created this revision. labath added reviewers: ldionne, logan-5, beanz. Herald added subscribers: lldb-commits, dexonsmith, hiraditya, mgorny. Herald added projects: LLDB, LLVM. labath requested review of this revision.
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 <https://reviews.llvm.org/D84554>) which took a similar approach. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D84748 Files: lldb/unittests/TestingSupport/Symbol/CMakeLists.txt llvm/cmake/modules/AddLLVM.cmake llvm/lib/Testing/Support/CMakeLists.txt llvm/utils/unittest/CMakeLists.txt Index: llvm/utils/unittest/CMakeLists.txt =================================================================== --- llvm/utils/unittest/CMakeLists.txt +++ llvm/utils/unittest/CMakeLists.txt @@ -19,11 +19,6 @@ googlemock ) -# LLVM requires C++11 but gtest doesn't correctly detect the availability -# of C++11 on MSVC, so we force it on. -add_definitions(-DGTEST_LANG_CXX11=1) -add_definitions(-DGTEST_HAS_TR1_TUPLE=0) - if(WIN32) add_definitions(-DGTEST_OS_WINDOWS=1) endif() @@ -47,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) @@ -78,6 +69,14 @@ set_target_properties(gtest PROPERTIES INTERFACE_COMPILE_OPTIONS "-Wno-suggest-override") endif() +# LLVM requires C++11 but gtest doesn't correctly detect the availability +# of C++11 on MSVC, so we force it on. +target_compile_definitions(gtest PUBLIC GTEST_LANG_CXX11=1 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 Index: llvm/lib/Testing/Support/CMakeLists.txt =================================================================== --- llvm/lib/Testing/Support/CMakeLists.txt +++ 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 Index: llvm/cmake/modules/AddLLVM.cmake =================================================================== --- llvm/cmake/modules/AddLLVM.cmake +++ llvm/cmake/modules/AddLLVM.cmake @@ -1400,18 +1400,8 @@ set(EXCLUDE_FROM_ALL ON) endif() - # 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. - add_definitions(-DGTEST_LANG_CXX11=1) - 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") Index: lldb/unittests/TestingSupport/Symbol/CMakeLists.txt =================================================================== --- lldb/unittests/TestingSupport/Symbol/CMakeLists.txt +++ lldb/unittests/TestingSupport/Symbol/CMakeLists.txt @@ -3,11 +3,5 @@ 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. -add_definitions(-DGTEST_LANG_CXX11=1) -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)
Index: llvm/utils/unittest/CMakeLists.txt =================================================================== --- llvm/utils/unittest/CMakeLists.txt +++ llvm/utils/unittest/CMakeLists.txt @@ -19,11 +19,6 @@ googlemock ) -# LLVM requires C++11 but gtest doesn't correctly detect the availability -# of C++11 on MSVC, so we force it on. -add_definitions(-DGTEST_LANG_CXX11=1) -add_definitions(-DGTEST_HAS_TR1_TUPLE=0) - if(WIN32) add_definitions(-DGTEST_OS_WINDOWS=1) endif() @@ -47,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) @@ -78,6 +69,14 @@ set_target_properties(gtest PROPERTIES INTERFACE_COMPILE_OPTIONS "-Wno-suggest-override") endif() +# LLVM requires C++11 but gtest doesn't correctly detect the availability +# of C++11 on MSVC, so we force it on. +target_compile_definitions(gtest PUBLIC GTEST_LANG_CXX11=1 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 Index: llvm/lib/Testing/Support/CMakeLists.txt =================================================================== --- llvm/lib/Testing/Support/CMakeLists.txt +++ 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 Index: llvm/cmake/modules/AddLLVM.cmake =================================================================== --- llvm/cmake/modules/AddLLVM.cmake +++ llvm/cmake/modules/AddLLVM.cmake @@ -1400,18 +1400,8 @@ set(EXCLUDE_FROM_ALL ON) endif() - # 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. - add_definitions(-DGTEST_LANG_CXX11=1) - 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") Index: lldb/unittests/TestingSupport/Symbol/CMakeLists.txt =================================================================== --- lldb/unittests/TestingSupport/Symbol/CMakeLists.txt +++ lldb/unittests/TestingSupport/Symbol/CMakeLists.txt @@ -3,11 +3,5 @@ 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. -add_definitions(-DGTEST_LANG_CXX11=1) -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)
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits