1 <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
\r
2 <Import Project="$(VCTargetsPath)\Microsoft.CppCommon.targets" />
\r
5 <!-- Set the path to clang-cl executable based on the value of the project-
\r
6 level setting. This has to be done in the .targets file since values
\r
7 selected via the settings UI appear in the vcxproj (which is imported
\r
8 before the targets file but after the props file) and we need the path
\r
9 that the user may have overridden in the UI. -->
\r
10 <CLToolExe Condition="$(UseClangCl)">$(ClangClExecutable)</CLToolExe>
\r
11 <LinkToolExe Condition="$(UseLldLink)">$(LldLinkExecutable)</LinkToolExe>
\r
12 <LIBToolExe Condition="$(UseLlvmLib)">$(LlvmLibExecutable)</LIBToolExe>
\r
16 <PropertyPageSchema Include="$(VCTargetsPath)$(LangID)\llvm-general.xml">
\r
17 <Context>Project</Context>
\r
18 </PropertyPageSchema>
\r
21 <!-- Take any clang-specific options that the user wants to pass and stick them onto the
\r
22 general purpose list of command line flags. -->
\r
23 <ItemDefinitionGroup Condition="$(UseClangCl)">
\r
25 <AdditionalOptions>-m$(PlatformArchitecture) $(ClangClAdditionalOptions) %(AdditionalOptions)</AdditionalOptions>
\r
27 </ItemDefinitionGroup>
\r
29 <ItemDefinitionGroup Condition="$(UseLldLink)">
\r
31 <AdditionalOptions>$(LldLinkAdditionalOptions) %(AdditionalOptions)</AdditionalOptions>
\r
33 </ItemDefinitionGroup>
\r
35 <!-- We hook up a target to run every time ClCompile is about to run, the
\r
36 purpose of which is to sanitize the command line before it gets passed to
\r
37 the compiler. Some options we silently discard, other options we warn on
\r
38 and then discard, and other options we generate a hard error.
\r
40 We try to keep hard errors to a minimum and reserve it for cases where
\r
41 the option implies fundamentally different assumptions about the way code
\r
42 should be compiled. This code would probably generate an error anyway,
\r
43 but at least this way we give the user a more useful message about what
\r
44 the actual problem is, rather than relying on some obscure compilation
\r
47 For any options that clang-cl discards, we would prefer to not even pass
\r
48 them in on the command line. So if a user starts with a cl projects and
\r
49 changes the toolset to clang, they could have set options such as /Gm
\r
50 (minimal rebuild), /sdl (Security Checks), etc. The ClCompile task would
\r
51 then notice this and pass these through to clang-cl.exe. Clang would of
\r
52 course ignore them, but in some cases (such as /Gm), they would generate
\r
53 -Wunused-command-line-argument warnings, so it's better if we can just
\r
54 strip them from the command line entirely. This also has the side
\r
55 benefit of making command lines shorter which is always nice when trying
\r
56 to look at the tool output.
\r
58 <Target Name="BeforeClCompile" BeforeTargets="ClCompile" Condition="$(UseClangCl)">
\r
59 <!-- Error if they're trying to compile this file as managed code. -->
\r
60 <Error Condition="('%(ClCompile.CompileAsManaged)' != 'false') AND ('%(ClCompile.CompileAsManaged)' != '')"
\r
61 File="@(ClCompile)(0,0)"
\r
62 Text="clang-cl does not support compiling managed code (/clr). This file cannot be compiled."/>
\r
64 <!-- Error if WinRT is being used. -->
\r
65 <Error Condition="('%(ClCompile.CompileAsWinRT)' == 'true') OR ('%(ClCompile.WinRTNoStdLib)' == 'true')"
\r
66 File="@(ClCompile)(0,0)"
\r
67 Text="clang-cl does not support Windows Runtime Language Extensions (/ZW, /ZW:nostdlib). This file cannot be compiled."/>
\r
69 <!-- Error if OpenMP language extensions are enabled. -->
\r
70 <Error Condition="'%(ClCompile.OpenMPSupport)' == 'true'"
\r
71 File="@(ClCompile)(0,0)"
\r
72 Text="clang-cl does not support OpenMP (/openmp). This file cannot be compiled."/>
\r
74 <!-- Error if C++ Modules are enabled. Clang has its own notion of modules that are not compatible. -->
\r
75 <Error Condition="'%(ClCompile.EnableModules)' == 'true'"
\r
76 File="@(ClCompile)(0,0)"
\r
77 Text="clang-cl does not support MSVC Modules (/experimental:module). This file cannot be compiled."/>
\r
81 <!-- Map /ZI and /Zi to /Z7. Clang internally does this, so if we were
\r
82 to just pass the option through, clang would work. The problem is
\r
83 that MSBuild would not. MSBuild detects /ZI and /Zi and then
\r
84 assumes (rightly) that there will be a compiler-generated PDB (e.g.
\r
85 vc141.pdb). Since clang-cl will not emit this, MSBuild will always
\r
86 think that the compiler-generated PDB needs to be re-generated from
\r
87 scratch and trigger a full build. The way to avoid this is to
\r
88 always give MSBuild accurate information about how we plan to
\r
89 generate debug info (which is to always using /Z7 semantics).
\r
91 <DebugInformationFormat Condition="'%(ClCompile.DebugInformationFormat)' == 'ProgramDatabase'">OldStyle</DebugInformationFormat>
\r
92 <DebugInformationFormat Condition="'%(ClCompile.DebugInformationFormat)' == 'EditAndContinue'">OldStyle</DebugInformationFormat>
\r
94 <!-- Unset any options that we either silently ignore or warn about due to compatibility.
\r
95 Generally when an option is set to no value, that means "Don't pass an option to the
\r
98 <WholeProgramOptimization/>
\r
99 <EnableFiberSafeOptimizations/>
\r
100 <IgnoreStandardIncludePath/>
\r
101 <EnableParallelCodeGeneration/>
\r
102 <ForceConformanceInForLoopScope/>
\r
103 <TreatWChar_tAsBuiltInType/>
\r
105 <GenerateXMLDocumentationFiles/>
\r
106 <BrowseInformation/>
\r
110 <ExpandAttributedSource/>
\r
111 <EnforceTypeConversionRules/>
\r
113 <DisableLanguageExtensions/>
\r
114 <ProgramDataBaseFileName/>
\r
115 <DisableSpecificWarnings/>
\r
116 <TreatSpecificWarningsAsErrors/>
\r
117 <ForcedUsingFiles/>
\r
119 <PREfastAdditionalOptions/>
\r
120 <PREfastAdditionalPlugins/>
\r
121 <MultiProcessorCompilation/>
\r
123 <RemoveUnreferencedCodeData/>
\r
125 <!-- We can't just unset BasicRuntimeChecks, as that will pass /RTCu to the compiler.
\r
126 We have to explicitly set it to 'Default' to avoid passing anything. -->
\r
127 <BasicRuntimeChecks>Default</BasicRuntimeChecks>
\r