@@ -139,6 +139,27 @@ if (NOT CMAKE_SIZEOF_VOID_P EQUAL 4 AND
139
139
message (FATAL_ERROR "Please use architecture with 4 or 8 byte pointers." )
140
140
endif ()
141
141
142
+ # Find and run MSVC (not clang-cl) and get its version. This will tell clang-cl
143
+ # what version of MSVC to pretend to be so that the STL works.
144
+ set (MSVC_VERSION_FLAG "" )
145
+ if (MSVC )
146
+ # Find and run MSVC (not clang-cl) and get its version. This will tell
147
+ # clang-cl what version of MSVC to pretend to be so that the STL works.
148
+ execute_process (COMMAND "$ENV{VSINSTALLDIR} /VC/bin/cl.exe"
149
+ OUTPUT_QUIET
150
+ ERROR_VARIABLE MSVC_COMPAT_VERSION
151
+ )
152
+ string (REGEX REPLACE "^.*Compiler Version ([0-9.]+) for .*$" "\\ 1"
153
+ MSVC_COMPAT_VERSION "${MSVC_COMPAT_VERSION} " )
154
+ if (MSVC_COMPAT_VERSION MATCHES "^[0-9].+$" )
155
+ set (MSVC_VERSION_FLAG "-fms-compatibility-version=${MSVC_COMPAT_VERSION} " )
156
+ # Add this flag into the host build if this is clang-cl.
157
+ if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" )
158
+ append ("${MSVC_VERSION_FLAG} " CMAKE_C_FLAGS CMAKE_CXX_FLAGS )
159
+ endif ()
160
+ endif ()
161
+ endif ()
162
+
142
163
# Generate the COMPILER_RT_SUPPORTED_ARCH list.
143
164
if (ANDROID)
144
165
# Examine compiler output to determine target architecture.
@@ -154,15 +175,10 @@ elseif(NOT APPLE) # Supported archs for Apple platforms are generated later
154
175
test_target_arch(i686 __i686__ "-m32" )
155
176
test_target_arch(i386 __i386__ "-m32" )
156
177
else ()
157
- # Extract the major version from CMake's MSVC_VERSION variable and pass
158
- # it to -fms-compatibility-version. The major version controls the most
159
- # important parts of clang's compatibility.
160
- string (SUBSTRING "${MSVC_VERSION} " 0 2 MSVC_MAJOR_VERSION)
161
- set (flags "-fms-compatibility-version=${MSVC_MAJOR_VERSION} " )
162
178
if (CMAKE_SIZEOF_VOID_P EQUAL 4)
163
- test_target_arch(i386 "" "${flags } " )
179
+ test_target_arch(i386 "" "${MSVC_VERSION_FLAG } " )
164
180
else ()
165
- test_target_arch(x86_64 "" "${flags } " )
181
+ test_target_arch(x86_64 "" "${MSVC_VERSION_FLAG } " )
166
182
endif ()
167
183
endif ()
168
184
elseif ("${COMPILER_RT_DEFAULT_TARGET_ARCH} " MATCHES "powerpc" )
0 commit comments