[patch] clang-cl 5.0.0 + VS2017.3 fix incorrect arguments
Hi,
I'm testing the latest clang in clang-cl mode with MSVC (15.3 or 2017.3 = cl.exe 19.11). VS (clang-cl) reports several command line warnings - some flags are not accepted anymore.
Attaching my patch for cmake 3.9.1. Probably in addition to patch it's necessary to check clang-cl version (>= 5.0.0), so previous versions are unaffected. Sorry, I can't create a MR, please apply if patch is ok.
EDIT: This was also discussed on the developer mailing list:
EDIT 2: For reference, the above-attached patch is:
diff --git a/Modules/Platform/Windows-MSVC.cmake b/Modules/Platform/Windows-MSVC.cmake
index cfe6e1c21..12f47ca4d 100644
--- a/Modules/Platform/Windows-MSVC.cmake
+++ b/Modules/Platform/Windows-MSVC.cmake
@@ -189,7 +189,7 @@ else()
if(CMAKE_VS_PLATFORM_TOOLSET MATCHES "(v[0-9]+_clang_.*|LLVM-vs[0-9]+.*)")
# Clang/C2 in MSVC14 Update 1 seems to not support -fsantinize (yet?)
# set(_RTC1 "-fsantinize=memory,safe-stack")
- set(_FLAGS_CXX " -frtti -fexceptions")
+ set(_FLAGS_CXX " /GR /EHsc")
else()
set(_RTC1 "/RTC1")
set(_FLAGS_CXX " /GR /EHsc")
@@ -289,9 +289,9 @@ macro(__windows_compiler_msvc lang)
# note: MSVC 14 2015 Update 1 sets -fno-ms-compatibility by default, but this does not allow one to compile many projects
# that include MS's own headers. CMake itself is affected project too.
string(APPEND CMAKE_${lang}_FLAGS_INIT " ${_PLATFORM_DEFINES}${_PLATFORM_DEFINES_${lang}} -fms-extensions -fms-compatibility -D_WINDOWS -Wall${_FLAGS_${lang}}")
- string(APPEND CMAKE_${lang}_FLAGS_DEBUG_INIT " /MDd -gline-tables-only -fno-inline -O0 ${_RTC1}")
+ string(APPEND CMAKE_${lang}_FLAGS_DEBUG_INIT " /MDd -gline-tables-only -Xclang -fno-inline -O0 ${_RTC1}")
string(APPEND CMAKE_${lang}_FLAGS_RELEASE_INIT " /MD -O2 -DNDEBUG")
- string(APPEND CMAKE_${lang}_FLAGS_RELWITHDEBINFO_INIT " /MD -gline-tables-only -O2 -fno-inline -DNDEBUG")
+ string(APPEND CMAKE_${lang}_FLAGS_RELWITHDEBINFO_INIT " /MD -gline-tables-only -O2 -Xclang -fno-inline -DNDEBUG")
string(APPEND CMAKE_${lang}_FLAGS_MINSIZEREL_INIT " /MD -DNDEBUG") # TODO: Add '-Os' once VS generator maps it properly for Clang
else()
string(APPEND CMAKE_${lang}_FLAGS_INIT " ${_PLATFORM_DEFINES}${_PLATFORM_DEFINES_${lang}} /D_WINDOWS /W3${_FLAGS_${lang}}")