1<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> 2 <Import Project="$(VCTargetsPath)\Microsoft.CppCommon.targets" /> 3 4 <PropertyGroup> 5 <!-- Set the path to clang-cl executable based on the value of the project- 6 level setting. This has to be done in the .targets file since values 7 selected via the settings UI appear in the vcxproj (which is imported 8 before the targets file but after the props file) and we need the path 9 that the user may have overridden in the UI. --> 10 <CLToolExe>$(ClangClExecutable)</CLToolExe> 11 </PropertyGroup> 12 13 <ItemGroup> 14 <PropertyPageSchema Include="$(VCTargetsPath)$(LangID)\llvm-general.xml"> 15 <Context>Project</Context> 16 </PropertyPageSchema> 17 </ItemGroup> 18 19 <!-- We hook up a target to run every time ClCompile is about to run, the 20 purpose of which is to sanitize the command line before it gets passed to 21 the compiler. Some options we silently discard, other options we warn on 22 and then discard, and other options we generate a hard error. 23 24 We try to keep hard errors to a minimum and reserve it for cases where 25 the option implies fundamentally different assumptions about the way code 26 should be compiled. This code would probably generate an error anyway, 27 but at least this way we give the user a more useful message about what 28 the actual problem is, rather than relying on some obscure compilation 29 error. 30 31 For any options that clang-cl discards, we would prefer to not even pass 32 them in on the command line. So if a user starts with a cl projects and 33 changes the toolset to clang, they could have set options such as /Gm 34 (minimal rebuild), /sdl (Security Checks), etc. The ClCompile task would 35 then notice this and pass these through to clang-cl.exe. Clang would of 36 course ignore them, but in some cases (such as /Gm), they would generate 37 -Wunused-command-line-argument warnings, so it's better if we can just 38 strip them from the command line entirely. This also has the side 39 benefit of making command lines shorter which is always nice when trying 40 to look at the tool output. 41 --> 42 <Target Name="BeforeClCompile" BeforeTargets="ClCompile"> 43 <!-- Warn on /Zi and /ZI, then map them both to /Z7. --> 44 <Warning Condition="'%(ClCompile.DebugInformationFormat)' == 'ProgramDatabase'" 45 File="@(ClCompile)(0,0)" 46 Text="clang-cl does not support /Zi (Program Database). The file will be compiled as if /Z7 (C7 Compatible Debug Info) had been passed. Update the Debug Information Format in project settings to silence this warning."/> 47 <Warning Condition="'%(ClCompile.DebugInformationFormat)' == 'EditAndContinue'" 48 File="@(ClCompile)(0,0)" 49 Text="clang-cl does not support /ZI (Program Database for Edit and Continue). The file will be compiled as if /Z7 (C7 Compatible Debug Info) had been passed. Update the Debug Information Format in project settings to silence this warning."/> 50 51 <!-- Warn if Fiber Safe Optimizations are enabled, and then ignore them. --> 52 <Warning Condition="'%(ClCompile.EnableFiberSafeOptimizations)' == 'true'" 53 File="@(ClCompile)(0,0)" 54 Text="clang-cl does not support fiber safe optimizations (/GT). Disable this option in compatibility settings to silence this warning."/> 55 56 <!-- Warn if Whole Program Optimization is enabled, and then ignore it. --> 57 <Warning Condition="'%(ClCompile.WholeProgramOptimization)' == 'true'" 58 File="@(ClCompile)(0,0)" 59 Text="clang-cl does not support MSVC Link Time Optimization. Disable this option in compatibility settings to silence this warning."/> 60 61 <!-- Warn if Ignore Standard Include Paths is non-empty, then ignore it. --> 62 <Warning Condition="'%(ClCompile.IgnoreStandardIncludePath)' == 'true'" 63 File="@(ClCompile)(0,0)" 64 Text="clang-cl does not support Ignore Standard Include Path (/X). Disable this option in compatibility settings to silence this warning."/> 65 66 <!-- Warn if Smaller Type Check is enabled, then ignore it.--> 67 <Warning Condition="'%(ClCompile.SmallerTypeCheck)' == 'true'" 68 File="@(ClCompile)(0,0)" 69 Text="clang-cl does not support Smaller Type Check (/RTCc). Disable this option in compatibility settings to silence this warning."/> 70 71 <!-- Warn if Runtime Checks are enabled, then ignore them.--> 72 <Warning Condition="'%(ClCompile.BasicRuntimeChecks)' != 'Default'" 73 File="@(ClCompile)(0,0)" 74 Text="clang-cl does not support Basic Runtime Checks (/RTCu, /RTC1, /RTCs). Disable this option in compatibility settings to silence this warning."/> 75 76 <!-- Warn if parallel code generation on #pragma loop is enabled, then ignore. --> 77 <Warning Condition="'(ClCompile.EnableParallelCodeGeneration)' == 'true'" 78 File="@(ClCompile)(0,0)" 79 Text="clang-cl does not support parallel code generation with #pragma loop(hint) (/Qpar). Disable this option in compatibility settings to silence this warning."/> 80 81 <!-- Warn if hotpatchable images are turned on --> 82 <Warning Condition="'%(ClCompile.CreateHotpatchableImage)' == 'true'" 83 File="@(ClCompile)(0,0)" 84 Text="clang-cl does not support creating hotpatchable images (/hotpatch). Disable this option in compatibility settings to silence this warning."/> 85 86 <!-- Warn if /Zc:forScope- is specified, and then ignore it. --> 87 <Warning Condition="'%(ClCompile.ForceConformanceInForLoopScope)' == 'false'" 88 File="@(ClCompile)(0,0)" 89 Text="clang-cl does not support disabling for loop scope conformance (/Zc:forScope-). Disable this option in compatibility settings to silence this warning."/> 90 91 <!-- Warn if /Zc:wchar_t- is specified, and then ignore it. --> 92 <Warning Condition="'%(ClCompile.TreatWChar_tAsBuiltInType)' == 'false'" 93 File="@(ClCompile)(0,0)" 94 Text="clang-cl does not support treating wchar_t as a non builtin type (/Zc:wchar_t-). Disable this option in compatibility settings to silence this warning."/> 95 96 <!-- Warn if XML Documentation is generated, and then ignore it. --> 97 <Warning Condition="'%(ClCompile.GenerateXMLDocumentationFiles)' == 'true'" 98 File="@(ClCompile)(0,0)" 99 Text="clang-cl does not support generating xml documentation comment files (/doc). Disable this option in compatibility settings to silence this warning."/> 100 101 <!-- Warn if Browse Information is generated, and then ignore it. --> 102 <Warning Condition="'%(ClCompile.BrowseInformation)' == 'true'" 103 File="@(ClCompile)(0,0)" 104 Text="clang-cl does not support generating browse information (/FR). Disable this option in compatibility settings to silence this warning."/> 105 106 <!-- Warn if /analyze is passed, then ignore it. --> 107 <Warning Condition="'%(ClCompile.EnablePREfast)' == 'true'" 108 File="@(ClCompile)(0,0)" 109 Text="clang-cl does not support MSVC code analysis functionality (/analyze). Disable this option in compatibility settings to silence this warning."/> 110 111 <!-- Error if they're trying to compile this file as managed code. --> 112 <Error Condition="('%(ClCompile.CompileAsManaged)' != 'false') AND ('%(ClCompile.CompileAsManaged)' != '')" 113 File="@(ClCompile)(0,0)" 114 Text="clang-cl does not support compiling managed code (/clr). This file cannot be compiled."/> 115 116 <!-- Error if WinRT is being used. --> 117 <Error Condition="('%(ClCompile.CompileAsWinRT)' == 'true') OR ('%(ClCompile.WinRTNoStdLib)' == 'true')" 118 File="@(ClCompile)(0,0)" 119 Text="clang-cl does not support Windows Runtime Language Extensions (/ZW, /ZW:nostdlib). This file cannot be compiled."/> 120 121 <!-- Error if OpenMP language extensions are enabled. --> 122 <Error Condition="'%(ClCompile.OpenMPSupport)' == 'true'" 123 File="@(ClCompile)(0,0)" 124 Text="clang-cl does not support OpenMP (/openmp). This file cannot be compiled."/> 125 126 <!-- Error if C++ Modules are enabled. Clang has its own notion of modules that are not compatible. --> 127 <Error Condition="'%(ClCompile.EnableModules)' == 'true'" 128 File="@(ClCompile)(0,0)" 129 Text="clang-cl does not support MSVC Modules (/experimental:module). This file cannot be compiled."/> 130 131 <ItemGroup> 132 <ClCompile> 133 <!-- Map /ZI and /Zi to /Z7. Clang internally does this, so if we were 134 to just pass the option through, clang would work. The problem is 135 that MSBuild would not. MSBuild detects /ZI and /Zi and then 136 assumes (rightly) that there will be a compiler-generated PDB (e.g. 137 vc141.pdb). Since clang-cl will not emit this, MSBuild will always 138 think that the compiler-generated PDB needs to be re-generated from 139 scratch and trigger a full build. The way to avoid this is to 140 always give MSBuild accurate information about how we plan to 141 generate debug info (which is to always using /Z7 semantics). 142 --> 143 <DebugInformationFormat Condition="'%(ClCompile.DebugInformationFormat)' == 'ProgramDatabase'">OldStyle</DebugInformationFormat> 144 <DebugInformationFormat Condition="'%(ClCompile.DebugInformationFormat)' == 'EditAndContinue'">OldStyle</DebugInformationFormat> 145 146 <!-- Unset any options that we either silently ignore or warn about due to compatibility. 147 Generally when an option is set to no value, that means "Don't pass an option to the 148 compiler at all." 149 --> 150 <WholeProgramOptimization/> 151 <EnableFiberSafeOptimizations/> 152 <IgnoreStandardIncludePath/> 153 <EnableParallelCodeGeneration/> 154 <ForceConformanceInForLoopScope/> 155 <TreatWChar_tAsBuiltInType/> 156 <SDLCheck/> 157 <GenerateXMLDocumentationFiles/> 158 <BrowseInformation/> 159 <EnablePREfast/> 160 <MinimalRebuild/> 161 <StringPooling/> 162 <ExpandAttributedSource/> 163 <EnforceTypeConversionRules/> 164 <ErrorReporting/> 165 <DisableLanguageExtensions/> 166 <ProgramDataBaseFileName/> 167 <DisableSpecificWarnings/> 168 <TreatSpecificWarningsAsErrors/> 169 <ForcedUsingFiles/> 170 <PREfastLog/> 171 <PREfastAdditionalOptions/> 172 <PREfastAdditionalPlugins/> 173 <MultiProcessorCompilation/> 174 <UseFullPaths/> 175 <RemoveUnreferencedCodeData/> 176 177 <!-- We can't just unset BasicRuntimeChecks, as that will pass /RTCu to the compiler. 178 We have to explicitly set it to 'Default' to avoid passing anything. --> 179 <BasicRuntimeChecks>Default</BasicRuntimeChecks> 180 </ClCompile> 181 </ItemGroup> 182 </Target> 183 184</Project> 185