|
| 1 | +<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
| 2 | + <Import Project="$(MSBuildThisFileDirectory)ImportBefore\*.targets" Condition="Exists('$(MSBuildThisFileDirectory)ImportBefore')" /> |
| 3 | + <PropertyGroup> |
| 4 | + <!-- Set the path to clang-cl executable based on the value of the project- |
| 5 | + level setting. This has to be done in the .targets file since values |
| 6 | + selected via the settings UI appear in the vcxproj (which is imported |
| 7 | + before the targets file but after the props file) and we need the path |
| 8 | + that the user may have overridden in the UI. --> |
| 9 | + <CLToolExe Condition="$(UseClangCl)">$(ClangClExecutable)</CLToolExe> |
| 10 | + <LinkToolExe Condition="'$(Platform)' == 'Win32'">$(LldLinkExecutable)</LinkToolExe> |
| 11 | + <LinkToolExe Condition="'$(Platform)' == 'x64'">$(LldLinkExecutable)</LinkToolExe> |
| 12 | + |
| 13 | + </PropertyGroup> |
| 14 | + |
| 15 | + <!-- Take any clang-specific options that the user wants to pass and stick them onto the |
| 16 | + general purpose list of command line flags. --> |
| 17 | + <ItemDefinitionGroup Condition="$(UseClangCl)"> |
| 18 | + <ClCompile> |
| 19 | + <!-- Set this to "Default" (which means not passing any /RTC option) so that any other value will |
| 20 | + be treated as having been overridden by the user. This Serves as a hint to the user that |
| 21 | + Default is the value we support, and other values will generate a warning. It also means |
| 22 | + that if the user simply creates a new project in MSVC (which uses /RTCu by default), then |
| 23 | + switches the toolset to Clang, we will still treat the value as default (which for us is to |
| 24 | + not pass the option). Only if the user explicitly overrode this setting in a project to use |
| 25 | + /RTCu would we see the warning. --> |
| 26 | + <!-- Force define PSAPI_VERSION=1--> |
| 27 | + <PreprocessorDefinitions>PSAPI_VERSION=1;%(PreprocessorDefinitions)</PreprocessorDefinitions> |
| 28 | + <BasicRuntimeChecks>Default</BasicRuntimeChecks> |
| 29 | + <AdditionalOptions Condition="'$(Platform)' == 'Win32'">--target=i686-pc-windows-msvc $(ClangClAdditionalOptions) %(AdditionalOptions)</AdditionalOptions> |
| 30 | + <AdditionalOptions Condition="'$(Platform)' == 'x64'">--target=x86_64-pc-windows-msvc $(ClangClAdditionalOptions) %(AdditionalOptions)</AdditionalOptions> |
| 31 | + <AdditionalOptions Condition="'$(Platform)' == 'ARM64'">--target=aarch64-pc-windows-msvc $(ClangClAdditionalOptions) %(AdditionalOptions)</AdditionalOptions> |
| 32 | + <AdditionalOptions Condition="'$(Platform)' == 'ARM'">--target=arm-pc-windows-msvc $(ClangClAdditionalOptions) %(AdditionalOptions)</AdditionalOptions> |
| 33 | + </ClCompile> |
| 34 | + </ItemDefinitionGroup> |
| 35 | + |
| 36 | + <ItemDefinitionGroup Condition="$(UseLldLink)"> |
| 37 | + <Link> |
| 38 | + <!-- Map /DEBUG and /DEBUG:FASTLINK to /DEBUG:FULL. |
| 39 | + <GenerateDebugInformation Condition="'%(Link.GenerateDebugInformation)' == 'true'">DebugFull</GenerateDebugInformation> |
| 40 | + <GenerateDebugInformation Condition="'%(Link.GenerateDebugInformation)' == 'DebugFastLink'">DebugFull</GenerateDebugInformation> --> |
| 41 | + <AdditionalOptions>$(LldLinkAdditionalOptions) %(AdditionalOptions)</AdditionalOptions> |
| 42 | + </Link> |
| 43 | + </ItemDefinitionGroup> |
| 44 | + |
| 45 | + |
| 46 | + <!-- We hook up a target to run every time ClCompile is about to run, the |
| 47 | + purpose of which is to sanitize the command line before it gets passed to |
| 48 | + the compiler. Some options we silently discard, other options we warn on |
| 49 | + and then discard, and other options we generate a hard error. |
| 50 | +
|
| 51 | + We try to keep hard errors to a minimum and reserve it for cases where |
| 52 | + the option implies fundamentally different assumptions about the way code |
| 53 | + should be compiled. This code would probably generate an error anyway, |
| 54 | + but at least this way we give the user a more useful message about what |
| 55 | + the actual problem is, rather than relying on some obscure compilation |
| 56 | + error. |
| 57 | +
|
| 58 | + For any options that clang-cl discards, we would prefer to not even pass |
| 59 | + them in on the command line. So if a user starts with a cl projects and |
| 60 | + changes the toolset to clang, they could have set options such as /Gm |
| 61 | + (minimal rebuild), /sdl (Security Checks), etc. The ClCompile task would |
| 62 | + then notice this and pass these through to clang-cl.exe. Clang would of |
| 63 | + course ignore them, but in some cases (such as /Gm), they would generate |
| 64 | + -Wunused-command-line-argument warnings, so it's better if we can just |
| 65 | + strip them from the command line entirely. This also has the side |
| 66 | + benefit of making command lines shorter which is always nice when trying |
| 67 | + to look at the tool output. |
| 68 | + --> |
| 69 | + <Target Name="BeforeClCompile" BeforeTargets="ClCompile" Condition="$(UseClangCl)"> |
| 70 | + <!-- Error if they're trying to compile this file as managed code. --> |
| 71 | + <Error Condition="('%(ClCompile.CompileAsManaged)' != 'false') and ('%(ClCompile.CompileAsManaged)' != '')" |
| 72 | + File="@(ClCompile)(0,0)" |
| 73 | + Text="clang-cl does not support compiling managed code (/clr). This file cannot be compiled."/> |
| 74 | + |
| 75 | + <!-- Error if WinRT is being used. --> |
| 76 | + <Error Condition="('%(ClCompile.CompileAsWinRT)' == 'true') or ('%(ClCompile.WinRTNoStdLib)' == 'true')" |
| 77 | + File="@(ClCompile)(0,0)" |
| 78 | + Text="clang-cl does not support Windows Runtime Language Extensions (/ZW, /ZW:nostdlib). This file cannot be compiled."/> |
| 79 | + |
| 80 | + <!-- Error if OpenMP language extensions are enabled. --> |
| 81 | + <Error Condition="'%(ClCompile.OpenMPSupport)' == 'true'" |
| 82 | + File="@(ClCompile)(0,0)" |
| 83 | + Text="clang-cl does not support OpenMP (/openmp). This file cannot be compiled."/> |
| 84 | + |
| 85 | + <!-- Error if C++ Modules are enabled. Clang has its own notion of modules that are not compatible. --> |
| 86 | + <Error Condition="'%(ClCompile.EnableModules)' == 'true'" |
| 87 | + File="@(ClCompile)(0,0)" |
| 88 | + Text="clang-cl does not support MSVC Modules (/experimental:module). This file cannot be compiled."/> |
| 89 | + |
| 90 | + <ItemGroup> |
| 91 | + <ClCompile> |
| 92 | + <!-- Map /ZI and /Zi to /Z7. Clang internally does this, so if we were |
| 93 | + to just pass the option through, clang would work. The problem is |
| 94 | + that MSBuild would not. MSBuild detects /ZI and /Zi and then |
| 95 | + assumes (rightly) that there will be a compiler-generated PDB (e.g. |
| 96 | + vc141.pdb). Since clang-cl will not emit this, MSBuild will always |
| 97 | + think that the compiler-generated PDB needs to be re-generated from |
| 98 | + scratch and trigger a full build. The way to avoid this is to |
| 99 | + always give MSBuild accurate information about how we plan to |
| 100 | + generate debug info (which is to always using /Z7 semantics). |
| 101 | + --> |
| 102 | + <DebugInformationFormat Condition="'%(ClCompile.DebugInformationFormat)' == 'ProgramDatabase'">OldStyle</DebugInformationFormat> |
| 103 | + <DebugInformationFormat Condition="'%(ClCompile.DebugInformationFormat)' == 'EditAndContinue'">OldStyle</DebugInformationFormat> |
| 104 | + |
| 105 | + <!-- Unset any options that we either silently ignore or warn about due to compatibility. |
| 106 | + Generally when an option is set to no value, that means "Don't pass an option to the |
| 107 | + compiler at all." |
| 108 | + --> |
| 109 | + <WholeProgramOptimization/> |
| 110 | + <EnableFiberSafeOptimizations/> |
| 111 | + <IgnoreStandardIncludePath/> |
| 112 | + <EnableParallelCodeGeneration/> |
| 113 | + <ForceConformanceInForLoopScope/> |
| 114 | + <TreatWChar_tAsBuiltInType/> |
| 115 | + <SDLCheck/> |
| 116 | + <GenerateXMLDocumentationFiles/> |
| 117 | + <BrowseInformation/> |
| 118 | + <EnablePREfast/> |
| 119 | + <MinimalRebuild/> |
| 120 | + <StringPooling/> |
| 121 | + <ExpandAttributedSource/> |
| 122 | + <EnforceTypeConversionRules/> |
| 123 | + <ErrorReporting/> |
| 124 | + <DisableLanguageExtensions/> |
| 125 | + <ProgramDataBaseFileName/> |
| 126 | + <DisableSpecificWarnings/> |
| 127 | + <TreatSpecificWarningsAsErrors/> |
| 128 | + <ForcedUsingFiles/> |
| 129 | + <PREfastLog/> |
| 130 | + <PREfastAdditionalOptions/> |
| 131 | + <PREfastAdditionalPlugins/> |
| 132 | + <MultiProcessorCompilation/> |
| 133 | + <UseFullPaths/> |
| 134 | + <RemoveUnreferencedCodeData/> |
| 135 | + <SupportJustMyCode/> |
| 136 | + <!-- Ignore C++ Language Standard for C --> |
| 137 | + <LanguageStandard Condition="('%(ClCompile.CompileAs)' == 'CompileAsC') or ('%(ClCompile.CompileAs)' == 'Default' and '%(ClCompile.Extension)' == '.c')"/> |
| 138 | + |
| 139 | + <!-- We can't just unset BasicRuntimeChecks, as that will pass /RTCu to the compiler. |
| 140 | + We have to explicitly set it to 'Default' to avoid passing anything. --> |
| 141 | + <BasicRuntimeChecks>Default</BasicRuntimeChecks> |
| 142 | + </ClCompile> |
| 143 | + </ItemGroup> |
| 144 | + </Target> |
| 145 | +<Import Project="$(MSBuildThisFileDirectory)ImportAfter\*.targets" Condition="Exists('$(MSBuildThisFileDirectory)ImportAfter')" /> |
| 146 | +</Project> |
0 commit comments