Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit 564787f

Browse files
committed
[cmake] Instead of testing char16_t for MSVC compat, directly ask cl.exe its version
Credit to Aaron Ballman for thinking of this. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@264886 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 2dec5fc commit 564787f

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

cmake/modules/HandleLLVMOptions.cmake

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -348,14 +348,16 @@ if( MSVC )
348348
append("/Zc:rvalueCast" CMAKE_CXX_FLAGS)
349349

350350
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
351-
# In VS 2015, char16_t became a builtin type. Clang still defaults to VS
352-
# 2013 compatibility, where it cannot be a builtin type. If we're using an
353-
# STL newer than 2015, this compilation will fail. Rasing the MSVC
354-
# compatibility version of the compiler will provide char16/32.
355-
check_cxx_source_compiles("#include <cstdint>\nchar16_t v1;\n" STL_PROVIDES_CHAR16_T)
356-
if (NOT STL_PROVIDES_CHAR16_T)
357-
append("-fms-compatibility-version=19" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
358-
endif()
351+
# Find and run MSVC (not clang-cl) and get its version. This will tell
352+
# clang-cl what version of MSVC to pretend to be so that the STL works.
353+
execute_process(COMMAND "$ENV{VSINSTALLDIR}/VC/bin/cl.exe"
354+
OUTPUT_QUIET
355+
ERROR_VARIABLE MSVC_COMPAT_VERSION
356+
)
357+
string(REGEX REPLACE "^.*Compiler Version ([0-9.]+) for .*$" "\\1"
358+
MSVC_COMPAT_VERSION "${MSVC_COMPAT_VERSION}")
359+
append("-fms-compatibility-version=${MSVC_COMPAT_VERSION}"
360+
CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
359361
endif()
360362

361363
if (NOT LLVM_ENABLE_TIMESTAMPS AND CMAKE_CXX_COMPILER_ID MATCHES "Clang")

0 commit comments

Comments
 (0)