[llvm] c3339e3 - [cmake] Make MSVC generate appropriate __cplusplus macro definition

Tatyana Krasnukha via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 3 02:53:22 PDT 2020


Author: Tatyana Krasnukha
Date: 2020-08-03T12:52:43+03:00
New Revision: c3339e3e921c2e064936c30f5eacba4e41c432da

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

LOG: [cmake] Make MSVC generate appropriate __cplusplus macro definition

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

Added: 
    

Modified: 
    llvm/cmake/modules/AddLLVM.cmake
    llvm/cmake/modules/HandleLLVMOptions.cmake
    llvm/utils/unittest/CMakeLists.txt

Removed: 
    


################################################################################
diff  --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake
index a25f3e87af61..5b5be953767b 100644
--- a/llvm/cmake/modules/AddLLVM.cmake
+++ b/llvm/cmake/modules/AddLLVM.cmake
@@ -1405,13 +1405,6 @@ function(add_unittest test_suite test_name)
     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)

diff  --git a/llvm/cmake/modules/HandleLLVMOptions.cmake b/llvm/cmake/modules/HandleLLVMOptions.cmake
index 0df9334363b4..4feb4b7a7f30 100644
--- a/llvm/cmake/modules/HandleLLVMOptions.cmake
+++ b/llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -421,6 +421,12 @@ if( MSVC )
 
   append("/Zc:inline" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
 
+  # Some projects use the __cplusplus preprocessor macro to check support for
+  # a particular version of the C++ standard. When this option is not specified
+  # explicitly, macro's value is "199711L" that implies C++98 Standard.
+  # https://devblogs.microsoft.com/cppblog/msvc-now-correctly-reports-__cplusplus/
+  append("/Zc:__cplusplus" CMAKE_CXX_FLAGS)
+
   # Allow users to request PDBs in release mode. CMake offeres the
   # RelWithDebInfo configuration, but it uses 
diff erent optimization settings
   # (/Ob1 vs /Ob2 or -O2 vs -O3). LLVM provides this flag so that users can get

diff  --git a/llvm/utils/unittest/CMakeLists.txt b/llvm/utils/unittest/CMakeLists.txt
index bcae36fa150d..9127ebce7b4c 100644
--- a/llvm/utils/unittest/CMakeLists.txt
+++ b/llvm/utils/unittest/CMakeLists.txt
@@ -19,11 +19,6 @@ include_directories(
   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()


        


More information about the llvm-commits mailing list