[compiler-rt] r264901 - [cmake] Get the MSVC version by running cl rather than relying on MSVC_VERSION

Reid Kleckner via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 30 11:31:14 PDT 2016


Author: rnk
Date: Wed Mar 30 13:31:14 2016
New Revision: 264901

URL: http://llvm.org/viewvc/llvm-project?rev=264901&view=rev
Log:
[cmake] Get the MSVC version by running cl rather than relying on MSVC_VERSION

MSVC_VERSION comes from the _MSC_VER macro, which won't correspond to
the STL version if the host compiler is clang-cl.

Modified:
    compiler-rt/trunk/cmake/config-ix.cmake

Modified: compiler-rt/trunk/cmake/config-ix.cmake
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/cmake/config-ix.cmake?rev=264901&r1=264900&r2=264901&view=diff
==============================================================================
--- compiler-rt/trunk/cmake/config-ix.cmake (original)
+++ compiler-rt/trunk/cmake/config-ix.cmake Wed Mar 30 13:31:14 2016
@@ -139,6 +139,27 @@ if (NOT CMAKE_SIZEOF_VOID_P EQUAL 4 AND
   message(FATAL_ERROR "Please use architecture with 4 or 8 byte pointers.")
 endif()
 
+# Find and run MSVC (not clang-cl) and get its version. This will tell clang-cl
+# what version of MSVC to pretend to be so that the STL works.
+set(MSVC_VERSION_FLAG "")
+if (MSVC)
+  # Find and run MSVC (not clang-cl) and get its version. This will tell
+  # clang-cl what version of MSVC to pretend to be so that the STL works.
+  execute_process(COMMAND "$ENV{VSINSTALLDIR}/VC/bin/cl.exe"
+    OUTPUT_QUIET
+    ERROR_VARIABLE MSVC_COMPAT_VERSION
+    )
+  string(REGEX REPLACE "^.*Compiler Version ([0-9.]+) for .*$" "\\1"
+    MSVC_COMPAT_VERSION "${MSVC_COMPAT_VERSION}")
+  if (MSVC_COMPAT_VERSION MATCHES "^[0-9].+$")
+    set(MSVC_VERSION_FLAG "-fms-compatibility-version=${MSVC_COMPAT_VERSION}")
+    # Add this flag into the host build if this is clang-cl.
+    if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
+      append("${MSVC_VERSION_FLAG}" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
+    endif()
+  endif()
+endif()
+
 # Generate the COMPILER_RT_SUPPORTED_ARCH list.
 if(ANDROID)
   # Examine compiler output to determine target architecture.
@@ -154,15 +175,10 @@ elseif(NOT APPLE) # Supported archs for
       test_target_arch(i686 __i686__ "-m32")
       test_target_arch(i386 __i386__ "-m32")
     else()
-      # Extract the major version from CMake's MSVC_VERSION variable and pass
-      # it to -fms-compatibility-version. The major version controls the most
-      # important parts of clang's compatibility.
-      string(SUBSTRING "${MSVC_VERSION}" 0 2 MSVC_MAJOR_VERSION)
-      set(flags "-fms-compatibility-version=${MSVC_MAJOR_VERSION}")
       if (CMAKE_SIZEOF_VOID_P EQUAL 4)
-        test_target_arch(i386 "" "${flags}")
+        test_target_arch(i386 "" "${MSVC_VERSION_FLAG}")
       else()
-        test_target_arch(x86_64 "" "${flags}")
+        test_target_arch(x86_64 "" "${MSVC_VERSION_FLAG}")
       endif()
     endif()
   elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "powerpc")




More information about the llvm-commits mailing list