Zachary Turner | c7ce968 | 2018-08-27 21:35:58 +0000 | [diff] [blame] | 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. -->
|
Zachary Turner | f550b4a | 2018-08-27 21:53:36 +0000 | [diff] [blame] | 10 | <CLToolExe Condition="$(UseClangCl)">$(ClangClExecutable)</CLToolExe>
|
| 11 | <LinkToolExe Condition="$(UseLldLink)">$(LldLinkExecutable)</LinkToolExe>
|
Zachary Turner | c7ce968 | 2018-08-27 21:35:58 +0000 | [diff] [blame] | 12 | </PropertyGroup>
|
| 13 |
|
| 14 | <ItemGroup>
|
| 15 | <PropertyPageSchema Include="$(VCTargetsPath)$(LangID)\llvm-general.xml">
|
| 16 | <Context>Project</Context>
|
| 17 | </PropertyPageSchema>
|
| 18 | </ItemGroup>
|
| 19 |
|
Zachary Turner | f550b4a | 2018-08-27 21:53:36 +0000 | [diff] [blame] | 20 | <!-- Take any clang-specific options that the user wants to pass and stick them onto the
|
| 21 | general purpose list of command line flags. -->
|
| 22 | <ItemDefinitionGroup Condition="$(UseClangCl)">
|
| 23 | <ClCompile>
|
| 24 | <AdditionalOptions>-m$(PlatformArchitecture) $(ClangClAdditionalOptions) %(AdditionalOptions)</AdditionalOptions>
|
| 25 | </ClCompile>
|
| 26 | </ItemDefinitionGroup>
|
| 27 |
|
| 28 | <ItemDefinitionGroup Condition="$(UseLldLink)">
|
| 29 | <Link>
|
| 30 | <AdditionalOptions>$(LldLinkAdditionalOptions) %(AdditionalOptions)</AdditionalOptions>
|
| 31 | </Link>
|
| 32 | </ItemDefinitionGroup>
|
| 33 |
|
Zachary Turner | c7ce968 | 2018-08-27 21:35:58 +0000 | [diff] [blame] | 34 | <!-- We hook up a target to run every time ClCompile is about to run, the
|
| 35 | purpose of which is to sanitize the command line before it gets passed to
|
| 36 | the compiler. Some options we silently discard, other options we warn on
|
| 37 | and then discard, and other options we generate a hard error.
|
| 38 |
|
| 39 | We try to keep hard errors to a minimum and reserve it for cases where
|
| 40 | the option implies fundamentally different assumptions about the way code
|
| 41 | should be compiled. This code would probably generate an error anyway,
|
| 42 | but at least this way we give the user a more useful message about what
|
| 43 | the actual problem is, rather than relying on some obscure compilation
|
| 44 | error.
|
| 45 |
|
| 46 | For any options that clang-cl discards, we would prefer to not even pass
|
| 47 | them in on the command line. So if a user starts with a cl projects and
|
| 48 | changes the toolset to clang, they could have set options such as /Gm
|
| 49 | (minimal rebuild), /sdl (Security Checks), etc. The ClCompile task would
|
| 50 | then notice this and pass these through to clang-cl.exe. Clang would of
|
| 51 | course ignore them, but in some cases (such as /Gm), they would generate
|
| 52 | -Wunused-command-line-argument warnings, so it's better if we can just
|
| 53 | strip them from the command line entirely. This also has the side
|
| 54 | benefit of making command lines shorter which is always nice when trying
|
| 55 | to look at the tool output.
|
| 56 | -->
|
Zachary Turner | f550b4a | 2018-08-27 21:53:36 +0000 | [diff] [blame] | 57 | <Target Name="BeforeClCompile" BeforeTargets="ClCompile" Condition="$(UseClangCl)">
|
Zachary Turner | c7ce968 | 2018-08-27 21:35:58 +0000 | [diff] [blame] | 58 | <!-- Error if they're trying to compile this file as managed code. -->
|
| 59 | <Error Condition="('%(ClCompile.CompileAsManaged)' != 'false') AND ('%(ClCompile.CompileAsManaged)' != '')"
|
| 60 | File="@(ClCompile)(0,0)"
|
| 61 | Text="clang-cl does not support compiling managed code (/clr). This file cannot be compiled."/>
|
| 62 |
|
| 63 | <!-- Error if WinRT is being used. -->
|
| 64 | <Error Condition="('%(ClCompile.CompileAsWinRT)' == 'true') OR ('%(ClCompile.WinRTNoStdLib)' == 'true')"
|
| 65 | File="@(ClCompile)(0,0)"
|
| 66 | Text="clang-cl does not support Windows Runtime Language Extensions (/ZW, /ZW:nostdlib). This file cannot be compiled."/>
|
| 67 |
|
| 68 | <!-- Error if OpenMP language extensions are enabled. -->
|
| 69 | <Error Condition="'%(ClCompile.OpenMPSupport)' == 'true'"
|
| 70 | File="@(ClCompile)(0,0)"
|
| 71 | Text="clang-cl does not support OpenMP (/openmp). This file cannot be compiled."/>
|
| 72 |
|
| 73 | <!-- Error if C++ Modules are enabled. Clang has its own notion of modules that are not compatible. -->
|
| 74 | <Error Condition="'%(ClCompile.EnableModules)' == 'true'"
|
| 75 | File="@(ClCompile)(0,0)"
|
| 76 | Text="clang-cl does not support MSVC Modules (/experimental:module). This file cannot be compiled."/>
|
| 77 |
|
| 78 | <ItemGroup>
|
| 79 | <ClCompile>
|
| 80 | <!-- Map /ZI and /Zi to /Z7. Clang internally does this, so if we were
|
| 81 | to just pass the option through, clang would work. The problem is
|
| 82 | that MSBuild would not. MSBuild detects /ZI and /Zi and then
|
| 83 | assumes (rightly) that there will be a compiler-generated PDB (e.g.
|
| 84 | vc141.pdb). Since clang-cl will not emit this, MSBuild will always
|
| 85 | think that the compiler-generated PDB needs to be re-generated from
|
| 86 | scratch and trigger a full build. The way to avoid this is to
|
| 87 | always give MSBuild accurate information about how we plan to
|
| 88 | generate debug info (which is to always using /Z7 semantics).
|
| 89 | -->
|
| 90 | <DebugInformationFormat Condition="'%(ClCompile.DebugInformationFormat)' == 'ProgramDatabase'">OldStyle</DebugInformationFormat>
|
| 91 | <DebugInformationFormat Condition="'%(ClCompile.DebugInformationFormat)' == 'EditAndContinue'">OldStyle</DebugInformationFormat>
|
| 92 |
|
| 93 | <!-- Unset any options that we either silently ignore or warn about due to compatibility.
|
| 94 | Generally when an option is set to no value, that means "Don't pass an option to the
|
| 95 | compiler at all."
|
| 96 | -->
|
| 97 | <WholeProgramOptimization/>
|
| 98 | <EnableFiberSafeOptimizations/>
|
| 99 | <IgnoreStandardIncludePath/>
|
| 100 | <EnableParallelCodeGeneration/>
|
| 101 | <ForceConformanceInForLoopScope/>
|
| 102 | <TreatWChar_tAsBuiltInType/>
|
| 103 | <SDLCheck/>
|
| 104 | <GenerateXMLDocumentationFiles/>
|
| 105 | <BrowseInformation/>
|
| 106 | <EnablePREfast/>
|
| 107 | <MinimalRebuild/>
|
| 108 | <StringPooling/>
|
| 109 | <ExpandAttributedSource/>
|
| 110 | <EnforceTypeConversionRules/>
|
| 111 | <ErrorReporting/>
|
| 112 | <DisableLanguageExtensions/>
|
| 113 | <ProgramDataBaseFileName/>
|
| 114 | <DisableSpecificWarnings/>
|
| 115 | <TreatSpecificWarningsAsErrors/>
|
| 116 | <ForcedUsingFiles/>
|
| 117 | <PREfastLog/>
|
| 118 | <PREfastAdditionalOptions/>
|
| 119 | <PREfastAdditionalPlugins/>
|
| 120 | <MultiProcessorCompilation/>
|
| 121 | <UseFullPaths/>
|
| 122 | <RemoveUnreferencedCodeData/>
|
| 123 |
|
| 124 | <!-- We can't just unset BasicRuntimeChecks, as that will pass /RTCu to the compiler.
|
| 125 | We have to explicitly set it to 'Default' to avoid passing anything. -->
|
| 126 | <BasicRuntimeChecks>Default</BasicRuntimeChecks>
|
| 127 | </ClCompile>
|
| 128 | </ItemGroup>
|
| 129 | </Target>
|
| 130 |
|
| 131 | </Project>
|