Use new task in relative-ObjectFileName target

This commit is contained in:
Niels Martin Hansen 2015-01-19 04:11:42 +01:00
parent 59ab4cd09b
commit 5e446264a2
1 changed files with 23 additions and 27 deletions

View File

@ -27,22 +27,11 @@
</Lib> </Lib>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<!-- Magic pseudo-target that makes object filenames relative to a given directory <!-- Add ObjectFileName for ClCompile items that need to be placed in subdirs
for linking to work, for projects with same-named files in separate dirs.
First define its relation to the system build targets: It must run as part of the
"compile inputs" section, but before all the system things. The system things here To use this feature, add a InputRelativeSourceDir metadata to ClCompile for
include testing whether multiple inputs might have identical outputs, which will a project.
produce a warning which we don't want.
Then define the target, make it depend on all ClCompile items, and have a fake
output that can never be a valid filename (due to pipe character). Instead have
the output name depend on the two variables involved in how the ObjectFileName
is determined: The specified InputRelativeSourceDir, and the actual RelativeDir
for the items.
This will cause MSBuild to batch the items as appropriate.
To use this feature, add a InputRelativeSourceDir metadata to ClCompile for
a project.
--> -->
<PropertyGroup> <PropertyGroup>
<ComputeCompileInputsTargets> <ComputeCompileInputsTargets>
@ -55,18 +44,25 @@
Inputs="@(ClCompile)" Inputs="@(ClCompile)"
Outputs="%(InputRelativeSourceDir)|%(RelativeDir)" Outputs="%(InputRelativeSourceDir)|%(RelativeDir)"
> >
<PropertyGroup> <!-- Transform paths on items -->
<InputRelativeDir>%(ClCompile.RelativeDir)</InputRelativeDir> <CalculateOutputDir
<InputRelativeDir Condition="!HasTrailingSlash('$(InputRelativeDir)')">$(InputRelativeDir)\</InputRelativeDir> Items="@(ClCompile)"
<InputRelativeSourceDir>%(ClCompile.InputRelativeSourceDir)</InputRelativeSourceDir> SourceDir="%(InputRelativeSourceDir)"
<InputRelativeSourceDir Condition="!HasTrailingSlash('$(InputRelativeSourceDir)')">$(InputRelativeSourceDir)\</InputRelativeSourceDir> DestinationDir="."
<InputRelativeDir>$(InputRelativeDir.Replace("$(InputRelativeSourceDir)",""))</InputRelativeDir> Condition="'%(ClCompile.InputRelativeSourceDir)' != ''"
</PropertyGroup> >
<!-- <Exec Command="echo ClCompile output for @(ClCompile -> '%(Filename)%(Extension)') to $(IntDir)$(InputRelativeDir)" /> --> <Output ItemName="_RelativeClCompile" TaskParameter="Outputs" />
</CalculateOutputDir>
<ItemGroup> <ItemGroup>
<ClCompile Condition="'%(ClCompile.InputRelativeSourceDir)' != ''"> <!-- Add the ObjectFileName -->
<ObjectFileName>$(IntDir)$(InputRelativeDir)</ObjectFileName> <_RelativeClCompile Condition="'%(_RelativeClCompile.OutputDir)' != ''">
</ClCompile> <ObjectFileName>$(IntDir)%(_RelativeClCompile.OutputDir)</ObjectFileName>
</_RelativeClCompile>
<!-- Remove old items and replace them with new -->
<ClCompile Remove="@(_RelativeClCompile->'%(Identity)')" />
<ClCompile Include="@(_RelativeClCompile)" />
<!-- Forget about the temporary ones -->
<_RelativeClCompile Remove="@(_RelativeClCompile)" />
</ItemGroup> </ItemGroup>
</Target> </Target>
</Project> </Project>