From 2c2ec4883bd9829b3589ce0aebe466bae9e8b0e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mariusz=20Pluci=C5=84ski?= Date: Thu, 18 Feb 2016 01:06:52 +0100 Subject: VS: in Clang/C2 toolset, setup correct compiler settings --- Modules/Platform/Windows-MSVC.cmake | 30 +++++++++++++++++++++++------- Source/cmVS14CLFlagTable.h | 2 ++ Source/cmVisualStudio10TargetGenerator.cxx | 13 ++++++++++++- 3 files changed, 37 insertions(+), 8 deletions(-) diff --git a/Modules/Platform/Windows-MSVC.cmake b/Modules/Platform/Windows-MSVC.cmake index a61413a..528cde3 100644 --- a/Modules/Platform/Windows-MSVC.cmake +++ b/Modules/Platform/Windows-MSVC.cmake @@ -194,8 +194,14 @@ else() if(_MSVC_C_ARCHITECTURE_FAMILY STREQUAL "ARM" OR _MSVC_CXX_ARCHITECTURE_FAMILY STREQUAL "ARM") set(CMAKE_C_STANDARD_LIBRARIES_INIT "kernel32.lib user32.lib") elseif(MSVC_VERSION GREATER 1310) - set(_RTC1 "/RTC1") - set(_FLAGS_CXX " /GR /EHsc") + if(CMAKE_VS_PLATFORM_TOOLSET MATCHES "v[0-9]+_clang_.*") + # Clang/C2 in MSVC14 Update 1 seems to not support -fsantinize (yet?) + # set(_RTC1 "-fsantinize=memory,safe-stack") + set(_FLAGS_CXX " -frtti -fexceptions") + else() + set(_RTC1 "/RTC1") + set(_FLAGS_CXX " /GR /EHsc") + endif() set(CMAKE_C_STANDARD_LIBRARIES_INIT "kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib") else() set(_RTC1 "/GZ") @@ -296,11 +302,21 @@ macro(__windows_compiler_msvc lang) set(CMAKE_${lang}_LINK_EXECUTABLE "${_CMAKE_VS_LINK_EXE} ${CMAKE_CL_NOLOGO} ${CMAKE_START_TEMP_FILE} /out: /implib: /pdb: /version:.${_PLATFORM_LINK_FLAGS} ${CMAKE_END_TEMP_FILE}") - set(CMAKE_${lang}_FLAGS_INIT "${_PLATFORM_DEFINES}${_PLATFORM_DEFINES_${lang}} /D_WINDOWS /W3${_FLAGS_${lang}}") - set(CMAKE_${lang}_FLAGS_DEBUG_INIT "/D_DEBUG /MDd /Zi /Ob0 /Od ${_RTC1}") - set(CMAKE_${lang}_FLAGS_RELEASE_INIT "/MD /O2 /Ob2 /D NDEBUG") - set(CMAKE_${lang}_FLAGS_RELWITHDEBINFO_INIT "/MD /Zi /O2 /Ob1 /D NDEBUG") - set(CMAKE_${lang}_FLAGS_MINSIZEREL_INIT "/MD /O1 /Ob1 /D NDEBUG") + 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 to compile many projects + # that include MS's own headers. CMake itself is affected project too. + set(CMAKE_${lang}_FLAGS_INIT "${_PLATFORM_DEFINES}${_PLATFORM_DEFINES_${lang}} -fms-extensions -fms-compatibility -D_WINDOWS -Wall${_FLAGS_${lang}}") + set(CMAKE_${lang}_FLAGS_DEBUG_INIT "-D_DEBUG /MDd -gline-tables-only -fno-inline -O0 ${_RTC1}") + set(CMAKE_${lang}_FLAGS_RELEASE_INIT "/MD -O2 -D NDEBUG") + set(CMAKE_${lang}_FLAGS_RELWITHDEBINFO_INIT "/MD -gline-tables-only -O2 -fno-inline -D NDEBUG") + set(CMAKE_${lang}_FLAGS_MINSIZEREL_INIT "/MD -Os -D NDEBUG") + else() + set(CMAKE_${lang}_FLAGS_INIT "${_PLATFORM_DEFINES}${_PLATFORM_DEFINES_${lang}} /D_WINDOWS /W3${_FLAGS_${lang}}") + set(CMAKE_${lang}_FLAGS_DEBUG_INIT "/D_DEBUG /MDd /Zi /Ob0 /Od ${_RTC1}") + set(CMAKE_${lang}_FLAGS_RELEASE_INIT "/MD /O2 /Ob2 /D NDEBUG") + set(CMAKE_${lang}_FLAGS_RELWITHDEBINFO_INIT "/MD /Zi /O2 /Ob1 /D NDEBUG") + set(CMAKE_${lang}_FLAGS_MINSIZEREL_INIT "/MD /O1 /Ob1 /D NDEBUG") + endif() set(CMAKE_${lang}_LINKER_SUPPORTS_PDB ON) set(CMAKE_NINJA_DEPTYPE_${lang} msvc) diff --git a/Source/cmVS14CLFlagTable.h b/Source/cmVS14CLFlagTable.h index 422f47b..1c9cf7c 100644 --- a/Source/cmVS14CLFlagTable.h +++ b/Source/cmVS14CLFlagTable.h @@ -28,6 +28,8 @@ static cmVS7FlagTable cmVS14CLFlagTable[] = "Custom", "Custom", 0}, {"Optimization", "Od", "Disabled", "Disabled", 0}, + {"Optimization", "Os", + "Minimize Size", "MinSize", 0}, {"Optimization", "O1", "Minimize Size", "MinSpace", 0}, {"Optimization", "O2", diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index 27a01a3..31873b5 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -2078,7 +2078,18 @@ void cmVisualStudio10TargetGenerator::WriteClOptions( if(this->MSTools) { - this->WriteString("$(IntDir)\n", 3); + cmsys::RegularExpression clangToolset("v[0-9]+_clang_.*"); + const char* toolset = this->GlobalGenerator->GetPlatformToolset(); + if (toolset && clangToolset.find(toolset)) + { + this->WriteString("" + "$(IntDir)%(filename).obj" + "\n", 3); + } + else + { + this->WriteString("$(IntDir)\n", 3); + } // If not in debug mode, write the DebugInformationFormat field // without value so PDBs don't get generated uselessly. -- cgit v0.12