summaryrefslogtreecommitdiffstats
path: root/Modules/Platform/Windows-MSVC.cmake
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2019-04-19 15:11:53 (GMT)
committerBrad King <brad.king@kitware.com>2019-04-19 16:56:49 (GMT)
commit1baf122cd41d6500139649661052236b8e684565 (patch)
treeec95252e332aa7098c5aca65f478b0e445481538 /Modules/Platform/Windows-MSVC.cmake
parent8542152626590db6a13b20aa3d36214186c6b40d (diff)
downloadCMake-1baf122cd41d6500139649661052236b8e684565.zip
CMake-1baf122cd41d6500139649661052236b8e684565.tar.gz
CMake-1baf122cd41d6500139649661052236b8e684565.tar.bz2
MSVC: Do not add /W3 to CMAKE_<LANG>_FLAGS by default
We do not add default warning flags on other compilers, and having a warning flag in the default flags makes it hard for projects to customize the warning level. They need to use string processing to remove `/W3` from `CMAKE_{C,CXX}_FLAGS`. Therefore we should drop it. However, projects may be using string processing to replace `/W3` with another flag, so we cannot simply drop it. Add a policy to drop it in a compatible way. Fixes: #18317
Diffstat (limited to 'Modules/Platform/Windows-MSVC.cmake')
-rw-r--r--Modules/Platform/Windows-MSVC.cmake17
1 files changed, 15 insertions, 2 deletions
diff --git a/Modules/Platform/Windows-MSVC.cmake b/Modules/Platform/Windows-MSVC.cmake
index 4279a74..ed0e7fb 100644
--- a/Modules/Platform/Windows-MSVC.cmake
+++ b/Modules/Platform/Windows-MSVC.cmake
@@ -366,21 +366,34 @@ macro(__windows_compiler_msvc lang)
set(_MDd " /MDd")
set(_MD " /MD")
endif()
+
+ cmake_policy(GET CMP0092 _cmp0092)
+ if(_cmp0092 STREQUAL "NEW")
+ set(_W3 "")
+ set(_Wall "")
+ else()
+ set(_W3 " /W3")
+ set(_Wall " -Wall")
+ endif()
+ unset(_cmp0092)
+
if(CMAKE_VS_PLATFORM_TOOLSET MATCHES "v[0-9]+_clang_.*")
# 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_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_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_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}}")
+ string(APPEND CMAKE_${lang}_FLAGS_INIT " ${_PLATFORM_DEFINES}${_PLATFORM_DEFINES_${lang}} /D_WINDOWS${_W3}${_FLAGS_${lang}}")
string(APPEND CMAKE_${lang}_FLAGS_DEBUG_INIT "${_MDd} /Zi /Ob0 /Od ${_RTC1}")
string(APPEND CMAKE_${lang}_FLAGS_RELEASE_INIT "${_MD} /O2 /Ob2 /DNDEBUG")
string(APPEND CMAKE_${lang}_FLAGS_RELWITHDEBINFO_INIT "${_MD} /Zi /O2 /Ob1 /DNDEBUG")
string(APPEND CMAKE_${lang}_FLAGS_MINSIZEREL_INIT "${_MD} /O1 /Ob1 /DNDEBUG")
endif()
+ unset(_Wall)
+ unset(_W3)
unset(_MDd)
unset(_MD)